]> git.ipfire.org Git - thirdparty/systemd.git/commit
switch-root: always use MS_BIND to move api vfs over
authorLennart Poettering <lennart@poettering.net>
Tue, 16 May 2023 12:57:31 +0000 (14:57 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 2 Jun 2023 14:49:39 +0000 (16:49 +0200)
commit7c764d45997721705e43ac66fbb5a56747d00d40
tree258a04a19e4b3eb57e5c8c0853c0207e9a4b3100
parent34f21ff610a3a77bf6e5064f1d0eb567f9a90fb2
switch-root: always use MS_BIND to move api vfs over

We previously would use MS_MOVE to move the old procfs, sysfs, /dev/ and
/run to the new place in some places, and MS_BIND in others.

The logic when to use MS_MOVE and when to use MS_BIND was pretty
arbitrary so far: we'd use MS_MOVE during the initrd → host transition
and MS_BIND when transitioning from host into the exitrd during
shutdown.

Traditionally, using MS_MOVE was preferable, because we didn't bother
with unmounting the old mount hierarchy before the switch root, and thus
using MS_MOVE did some clean-up as side-effect (because the old mounts
went away this way). But since we nowadays properly umount all remaining
mount points (since 268d1244e87a35ff8dff56c92ef375ebf69d462e) when
transitioning it's pointless.

Let's just use MS_BIND always. Let's tweak it though: let's use
MS_BIND|MS_REC for the kernel API VFS, and MS_BIND without MS_REC for
/run/. The latter reflects the fact that the submounts /run/ has usually
are not so much about just accessing kernel APIs but about auxiliary
user resources. Hence let's only move the main mount over for that.

While we are at it, also set up the base filesystem *before* we move the
mounts from the old to the new root, since the base filesystem setup
logic creates various needed inodes for us, which we really should make
use of instead of creating on our own.
src/core/main.c
src/shared/switch-root.c
src/shared/switch-root.h
src/shutdown/shutdown.c