aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-11-23 22:16:57 +0100
committerLennart Poettering <lennart@poettering.net>2018-12-18 14:47:46 +0100
commitfd89051ec3d2555c19d71d5fc6d76809ca3bb79c (patch)
tree3a39651fa4d04ae5cdf9030fe08196e491ddf809
parentgpt-auto: make arg_root_rw a tri-state (diff)
downloadsystemd-fd89051ec3d2555c19d71d5fc6d76809ca3bb79c.tar.gz
systemd-fd89051ec3d2555c19d71d5fc6d76809ca3bb79c.tar.bz2
systemd-fd89051ec3d2555c19d71d5fc6d76809ca3bb79c.zip
gpt-auto: propagate gpt partition ro/rw flag into root mount
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.
-rw-r--r--src/gpt-auto-generator/gpt-auto-generator.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c
index 425f5421c..c6a801389 100644
--- a/src/gpt-auto-generator/gpt-auto-generator.c
+++ b/src/gpt-auto-generator/gpt-auto-generator.c
@@ -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;
}