[systemd-devel] [PATCH] gpt-auto-generator: honor read-only attribute for native rootfs, post-initrd.

Dimitri John Ledkov dimitri.j.ledkov at intel.com
Mon Dec 29 06:33:48 PST 2014


Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov at intel.com>
---

 This is not yet really ready for application, as ultimately this is
 only solution for part of the problem.

 With this patch, post-initrd -.mount unit will have correct
 "Options=rw" if READ_ONLY flag is not set and ro/rw was not specified
 on the kernel cmdline. In the initrd the -.mount unit will continue
 to be mounted ro by default (honoring cmdline rw flag, but ignoring
 unset READ_ONLY flag).

 However, remount-fs only considers /etc/fstab and only remounts
 things with options as specified in the /etc/fstab. Thus the fact
 that -.mount unit changed "Options=ro" -> "Options=rw" between
 initramfs and pivoted system does not result in the root filesystem
 getting remounted as rw.

 I believe initramfs generator should not / cannot be parsing
 partition flags of /dev/gpt-auto-root as udev might not yet created
 such symlink at the time generator is running.

 I didn't look into .mount unit handling, but it is peculiar that
 -.mount is considered to be successfully started even though it has
 different mount options. Shouldn't the unit be attempted to be "mount
 -oremount,$options $path" with options as specified in the .mount
 file, if it happens to be pre-mounted in the initramfs instead of
 getting marked as 'started'?

 Regards,

 Dimitri.

 src/gpt-auto-generator/gpt-auto-generator.c | 35 +++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c
index 909fdda..bd2e023 100644
--- a/src/gpt-auto-generator/gpt-auto-generator.c
+++ b/src/gpt-auto-generator/gpt-auto-generator.c
@@ -43,10 +43,13 @@
 #include "blkid-util.h"
 #include "btrfs-util.h"
 
+static int add_root_mount(void);
+
 static const char *arg_dest = "/tmp";
 static bool arg_enabled = true;
 static bool arg_root_enabled = true;
 static bool arg_root_rw = false;
+static bool arg_root_rw_cmdline_set = false;
 
 static int add_swap(const char *path) {
         _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL;
@@ -481,9 +484,6 @@ static int enumerate_partitions(dev_t devnum) {
                 if (major(qn) == 0)
                         continue;
 
-                if (qn == devnum)
-                        continue;
-
                 if (qn == pn)
                         continue;
 
@@ -551,9 +551,22 @@ static int enumerate_partitions(dev_t devnum) {
                         srv = strdup(node);
                         if (!srv)
                                 return log_oom();
+
+                } else if (sd_id128_equal(type_id, GPT_ROOT_NATIVE)) {
+
+                        /* Explicit ro/rw flag already set on the kernel command line */
+                        if (!arg_root_rw_cmdline_set) {
+                                arg_root_rw = !(flags & GPT_FLAG_READ_ONLY);
+                        }
                 }
         }
 
+        if (arg_root_enabled) {
+                k = add_root_mount();
+                if (k < 0)
+                        r = k;
+        }
+
         if (home) {
                 k = probe_and_add_mount("home", home, "/home", home_rw, "Home Partition", SPECIAL_LOCAL_FS_TARGET);
                 if (k < 0)
@@ -613,10 +626,14 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
 
                 arg_root_enabled = streq(value, "gpt-auto");
 
-        } else if (streq(key, "rw") && !value)
+        } else if (streq(key, "rw") && !value) {
                 arg_root_rw = true;
-        else if (streq(key, "ro") && !value)
+                arg_root_rw_cmdline_set = true;
+        }
+        else if (streq(key, "ro") && !value) {
                 arg_root_rw = false;
+                arg_root_rw_cmdline_set = true;
+        }
 
         return 0;
 }
@@ -701,10 +718,10 @@ int main(int argc, char *argv[]) {
                 return EXIT_SUCCESS;
         }
 
-        if (arg_root_enabled)
-                r = add_root_mount();
-
-        if (!in_initrd()) {
+        if (in_initrd()) {
+                if (arg_root_enabled)
+                        r = add_root_mount();
+        } else {
                 int k;
 
                 k = add_mounts();
-- 
2.1.0



More information about the systemd-devel mailing list