]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
gpt-auto: propagate gpt partition ro/rw flag into root mount
authorLennart Poettering <lennart@poettering.net>
Fri, 23 Nov 2018 21:16:57 +0000 (22:16 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 18 Dec 2018 13:47:46 +0000 (14:47 +0100)
This ensures that the read/write state of the root mount matches the
read/write flag in the GPT partition table entry.

This is only used as fallback in case no ro/rw flag is specified on the
kernel cmdline, and there's no entry for the root partition in
/etc/fstab.

This is missing functionality of the GPT auto logic, as without this the
root partition was always mounted read-only — when booting with zero
configuration in /etc/fstab and /proc/cmdline —, as we defaulted to
read-only behaviour for all mounts. Moreover we honoured the r/o flag in
the partition table for all other partition types, except for the root
partition.

src/gpt-auto-generator/gpt-auto-generator.c

index 425f5421caa629a58eb9123261992af4da802a7c..c6a801389e897ea6388b7c9cf9e042bc36bf6fd2 100644 (file)
@@ -446,6 +446,43 @@ static int add_esp(DissectedPartition *p) {
 }
 #endif
 
+static int add_root_rw(DissectedPartition *p) {
+        const char *path;
+        int r;
+
+        assert(p);
+
+        if (in_initrd()) {
+                log_debug("In initrd, not generating drop-in for systemd-remount-fs.service.");
+                return 0;
+        }
+
+        if (arg_root_rw >= 0) {
+                log_debug("Parameter ro/rw specified on kernel command line, not generating drop-in for systemd-remount-fs.service.");
+                return 0;
+        }
+
+        if (!p->rw) {
+                log_debug("Root partition marked read-only in GPT partition table, not generating drop-in for systemd-remount-fs.service.");
+                return 0;
+        }
+
+        path = strjoina(arg_dest, "/systemd-remount-fs.service.d/50-remount-rw.conf");
+        (void) mkdir_parents(path, 0755);
+
+        r = write_string_file(path,
+                              "# Automatically generated by systemd-gpt-generator\n\n"
+                              "[Unit]\n"
+                              "ConditionPathExists=\n\n" /* We need to turn off the ConditionPathExist= in the main unit file */
+                              "[Service]\n"
+                              "Environment=SYSTEMD_REMOUNT_ROOT_RW=1\n",
+                              WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_NOFOLLOW);
+        if (r < 0)
+                return log_error_errno(r, "Failed to write drop-in file %s: %m", path);
+
+        return 0;
+}
+
 static int open_parent(dev_t devnum, int *ret) {
         _cleanup_(sd_device_unrefp) sd_device *d = NULL;
         const char *name, *devtype, *node;
@@ -550,6 +587,12 @@ static int enumerate_partitions(dev_t devnum) {
                         r = k;
         }
 
+        if (m->partitions[PARTITION_ROOT].found) {
+                k = add_root_rw(m->partitions + PARTITION_ROOT);
+                if (k < 0)
+                        r = k;
+        }
+
         return r;
 }