Skip to content

Commit

Permalink
overlay.d/05core: add coreos-rootflags back to diskful sysroot.mount
Browse files Browse the repository at this point in the history
In 45396d8 we started creating a static sysroot.mount to appease
systemd 254+ (see [1]), but it missed the `coreos-rootflags` handling
that was present in ignition-ostree-mount-sysroot.sh.

This PR adds back in the dynamic rootflags by using an EnvironmentFile
generated by a coreos-rootflags.service to get the same behavior.

[1] coreos/fedora-coreos-tracker#1527 (comment)
  • Loading branch information
dustymabe committed Aug 9, 2023
1 parent 2f45c5c commit 431e6aa
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ add_requires() {
ln -sf "../${name}" "${requires_dir}/${name}"
}

# Generate a sysroot.mount unit. We can't do this later by dynamically
# doing the mount like we used to because systemd 254+ will drop units that
# require sysroot.mount from the transaction:
# https://github.com/coreos/fedora-coreos-tracker/issues/1527#issuecomment-1656786452
#
# We'll dynamically pick up what mount options to use from the OPTIONS
# environment variable in /run/coreos-rootflags (generated by
# coreos-rootflags.service).
#
# Note that for new machines this is *only* useful on first boot because
# coreos-boot-edit.service will add the root= and rootflags= kargs to the
# kernel command line for subsequent boots. However we haven't migrated
# all old machines so there are still some that could exist that don't
# have root= and rootflags= kargs. For that reason we run this bit of
# code on EVERY diskful boot.
if ! is-live-image; then
mkdir -p ${UNIT_DIR}
# We want to generate sysroot.mount on ostree systems, but we don't want
Expand All @@ -50,9 +65,12 @@ if ! is-live-image; then
cat >${UNIT_DIR}/sysroot.mount << 'EOF'
[Unit]
Before=initrd-root-fs.target
After=coreos-rootflags.service
[Mount]
EnvironmentFile=/run/coreos-rootflags
What=/dev/disk/by-label/root
Where=/sysroot
Options=${OPTIONS}
EOF
add_requires sysroot.mount initrd-root-fs.target
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[Unit]
Description=Determine root FS mount option flags
DefaultDependencies=false
ConditionKernelCommandLine=!root
ConditionPathExists=!/run/ostree-live
# Just in case. We shouldn't run twice.
ConditionPathExists=!/run/coreos-rootflags
# Since the sysroot.mount depends on the options generated by us
# we must run before sysroot.mount
Before=sysroot.mount
# In case the disk was manipulated by Ignition and we need to pick
# up mount options from Ignition config.
After=ignition-disks.service
# The script checks if the rootfs was reprovisioned so let's wait
# until after that has completed if it was requested.
After=ignition-ostree-transposefs-restore.service
# Requires the root device to exist
Requires=dev-disk-by\x2dlabel-root.device
After=dev-disk-by\x2dlabel-root.device

[Service]
Type=oneshot
StandardError=journal
StandardOutput=append:/run/coreos-rootflags
ExecStartPre=echo -n 'OPTIONS='
ExecStart=/usr/sbin/coreos-rootflags
RemainAfterExit=yes
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ install() {
inst_multiple jq blkid
inst_script "$moddir/coreos-rootflags.sh" \
"/usr/sbin/coreos-rootflags"
install_ignition_unit coreos-rootflags.service initrd-root-fs.target
}

0 comments on commit 431e6aa

Please sign in to comment.