diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-12-20 11:37:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-20 11:37:41 +0100 |
commit | 6ea05ac99fd2a59ccc326290abd8ba9b7a85bd26 (patch) | |
tree | 0595a7d2ba587acd4390db762bd0bae500128a09 /src/gpt-auto-generator | |
parent | faf9e4426cff8a9ac3f34fec6d3fcbca3f1ca669 (diff) | |
parent | 7d1353ccf21190d82030750df9d1150f9f894d3d (diff) | |
download | systemd-6ea05ac99fd2a59ccc326290abd8ba9b7a85bd26.tar.gz |
Merge pull request #10912 from poettering/gpt-root-rw
make sure to propagate GPT root partition r/w flag into mount r/w flag
Diffstat (limited to 'src/gpt-auto-generator')
-rw-r--r-- | src/gpt-auto-generator/gpt-auto-generator.c | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index e9f3d7dab2..d9e29c47f3 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -39,7 +39,7 @@ static const char *arg_dest = NULL; static bool arg_enabled = true; static bool arg_root_enabled = true; -static bool arg_root_rw = false; +static int arg_root_rw = -1; static int add_cryptsetup(const char *id, const char *what, bool rw, bool require, char **device) { _cleanup_free_ char *e = NULL, *n = NULL, *d = NULL, *id_escaped = NULL, *what_escaped = NULL; @@ -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; } @@ -558,7 +601,8 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat assert(key); - if (STR_IN_SET(key, "systemd.gpt_auto", "rd.systemd.gpt_auto")) { + if (proc_cmdline_key_streq(key, "systemd.gpt_auto") || + proc_cmdline_key_streq(key, "rd.systemd.gpt_auto")) { r = value ? parse_boolean(value) : 1; if (r < 0) @@ -566,7 +610,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat else arg_enabled = r; - } else if (streq(key, "root")) { + } else if (proc_cmdline_key_streq(key, "root")) { if (proc_cmdline_value_missing(key, value)) return 0; @@ -576,7 +620,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat arg_root_enabled = streq(value, "gpt-auto"); - } else if (streq(key, "roothash")) { + } else if (proc_cmdline_key_streq(key, "roothash")) { if (proc_cmdline_value_missing(key, value)) return 0; @@ -585,9 +629,9 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat arg_root_enabled = false; - } else if (streq(key, "rw") && !value) + } else if (proc_cmdline_key_streq(key, "rw") && !value) arg_root_rw = true; - else if (streq(key, "ro") && !value) + else if (proc_cmdline_key_streq(key, "ro") && !value) arg_root_rw = false; return 0; @@ -639,7 +683,7 @@ static int add_root_mount(void) { "/dev/gpt-auto-root", in_initrd() ? "/sysroot" : "/", NULL, - arg_root_rw, + arg_root_rw > 0, NULL, "Root Partition", in_initrd() ? SPECIAL_INITRD_ROOT_FS_TARGET : SPECIAL_LOCAL_FS_TARGET); |