From 83260f65f3f02aab620d218860d0d8118e92f257 Mon Sep 17 00:00:00 2001 From: Valentin David Date: Tue, 8 Nov 2022 13:13:04 +0100 Subject: [PATCH] Fix mount propagation To switch root, systemd has to recursively make all mounts private, then after it recursively make all mounts shared. However `/run/mnt/*` and `/writable` are used to be bind mounted in the rest of the file system. For example, there is no reason for mount `/snap/hello/42` to also show up as `/writable/system-data/snap/hello/42` and `/run/mnt/data/system-data/snap/hello/42`. --- static/usr/lib/core/remount-core-fs | 19 +++++++++++++++++++ .../remount-core-fs.service | 1 + .../systemd/system/remount-core-fs.service | 16 ++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100755 static/usr/lib/core/remount-core-fs create mode 120000 static/usr/lib/systemd/system/local-fs.target.wants/remount-core-fs.service create mode 100644 static/usr/lib/systemd/system/remount-core-fs.service diff --git a/static/usr/lib/core/remount-core-fs b/static/usr/lib/core/remount-core-fs new file mode 100755 index 00000000..ac5ac4aa --- /dev/null +++ b/static/usr/lib/core/remount-core-fs @@ -0,0 +1,19 @@ +#!/bin/bash + +FILESYSTEMS=( + /run/mnt/base + /run/mnt/data + /run/mnt/gadget + /run/mnt/kernel + /run/mnt/snapd + /run/mnt/ubuntu-boot + /run/mnt/ubuntu-save + /run/mnt/ubuntu-seed + /writable +) + +for fs in "${FILESYSTEMS[@]}"; do + if mountpoint -q "${fs}"; then + mount --make-private "${fs}" + fi +done diff --git a/static/usr/lib/systemd/system/local-fs.target.wants/remount-core-fs.service b/static/usr/lib/systemd/system/local-fs.target.wants/remount-core-fs.service new file mode 120000 index 00000000..6898efbb --- /dev/null +++ b/static/usr/lib/systemd/system/local-fs.target.wants/remount-core-fs.service @@ -0,0 +1 @@ +../remount-core-fs.service \ No newline at end of file diff --git a/static/usr/lib/systemd/system/remount-core-fs.service b/static/usr/lib/systemd/system/remount-core-fs.service new file mode 100644 index 00000000..ef20cdbf --- /dev/null +++ b/static/usr/lib/systemd/system/remount-core-fs.service @@ -0,0 +1,16 @@ +[Unit] +Description=Reset propagation of initial mount points +DefaultDependencies=no +Before=local-fs-pre.target +Before=local-fs.target +Before=shutdown.target +Wants=local-fs-pre.target +Conflicts=shutdown.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/lib/core/remount-core-fs + +[Install] +WantedBy=local-fs.target