core: copy the host's os-release for /run/host/os-release
Currently for portable services we automatically add a bind mount os-release -> /run/host/os-release. This becomes problematic for the soft-reboot case, as it's likely that portable services will be configured to survive it, and thus would forever keep a reference to the old host's os-release, which would be a problem because it becomes outdated, and also it stops the old rootfs from being garbage collected. Create a copy when the manager starts under /run/systemd/propagate instead, and bind mount that for all services using RootDirectory=/RootImage=, so that on soft-reboot the content gets updated (without creating a new file, so the existing bind mounts will see the new content too). This expands the /run/host/os-release protocol to more services, but I think that's a nice thing to have too. Closes https://github.com/systemd/systemd/issues/28023
This commit is contained in:
@@ -583,4 +583,6 @@ grep -q -F "MARKER_CONFEXT_123" /etc/testfile
|
||||
systemd-confext unmerge
|
||||
rm -rf /run/confexts/ testjob/
|
||||
|
||||
systemd-run -P -p RootImage="${image}.raw" cat /run/host/os-release | cmp "${os_release}"
|
||||
|
||||
touch /testok
|
||||
|
||||
@@ -54,6 +54,8 @@ elif [ -f /run/testsuite82.touch2 ]; then
|
||||
# Test that we really are in the new overlayfs root fs
|
||||
read -r x </lower
|
||||
test "$x" = "miep"
|
||||
cmp /etc/os-release /run/systemd/propagate/os-release
|
||||
grep -q MARKER=1 /etc/os-release
|
||||
|
||||
# Switch back to the original root, away from the overlayfs
|
||||
mount --bind /original-root /run/nextroot
|
||||
@@ -92,7 +94,16 @@ elif [ -f /run/testsuite82.touch ]; then
|
||||
mkdir -p /run/nextroot /tmp/nextroot-lower /original-root
|
||||
mount -t tmpfs tmpfs /tmp/nextroot-lower
|
||||
echo miep >/tmp/nextroot-lower/lower
|
||||
mount -t overlay nextroot /run/nextroot -o lowerdir=/:/tmp/nextroot-lower,ro
|
||||
|
||||
# Copy os-release away, so that we can manipulate it and check that it is updated in the propagate
|
||||
# directory across soft reboots.
|
||||
mkdir -p /tmp/nextroot-lower/usr/lib
|
||||
cp /etc/os-release /tmp/nextroot-lower/usr/lib/os-release
|
||||
echo MARKER=1 >>/tmp/nextroot-lower/usr/lib/os-release
|
||||
cmp /etc/os-release /run/systemd/propagate/os-release
|
||||
(! grep -q MARKER=1 /etc/os-release)
|
||||
|
||||
mount -t overlay nextroot /run/nextroot -o lowerdir=/tmp/nextroot-lower:/,ro
|
||||
|
||||
# Bind our current root into the target so that we later can return to it
|
||||
mount --bind / /run/nextroot/original-root
|
||||
|
||||
Reference in New Issue
Block a user