Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overlay.d/05core: support booting ISO completely from RAM #2544

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[Unit]
Description=Persist Osmet Files (ISO)
DefaultDependencies=false
ConditionPathExists=/run/ostree-live
ConditionKernelCommandLine=coreos.liveiso
cgwalters marked this conversation as resolved.
Show resolved Hide resolved
RequiresMountsFor=/run/media/iso
# on el8, the ISO is mounted by our own systemd unit
After=run-media-iso-mount.service
Before=initrd-switch-root.target
# DefaultDependencies=true so this unit gets stopped on switchroot to
cgwalters marked this conversation as resolved.
Show resolved Hide resolved
# allow for /run/media/iso to get unmounted.
DefaultDependencies=true

[Service]
Type=oneshot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ ExecStartPost=/usr/sbin/ostree-cmdline stop
EOF

isoroot=$(getarg coreos.liveiso= ||:)
is_rhcos8() {
# Unfortunately we can't rely on /etc/os-release since el8 doesn't seem to
# have https://github.com/dracutdevs/dracut/pull/655.
[[ "${isoroot}" == rhcos-* ]] && [[ $(uname -r) == *.el8* ]]
}

if [ -z "${isoroot}" ]; then
# In this case, the rootfs is already unpacked into the initrd, or we need
Expand Down Expand Up @@ -90,32 +85,8 @@ else
After=${isosrc_escaped}
Requires=${isosrc_escaped}
EOF
# Temporary hack for rhel8, where our mount unit can race with udev's
cgwalters marked this conversation as resolved.
Show resolved Hide resolved
# cdrom_id using open(O_EXCL). See:
# https://github.com/coreos/fedora-coreos-config/pull/1986#pullrequestreview-1120840529
# https://issues.redhat.com/browse/OCPBUGS-1505
if is_rhcos8; then
cat >"${UNIT_DIR}/run-media-iso-mount.service" <<EOF
# Automatically generated by live-generator

[Unit]
DefaultDependencies=false
# Note that bootup(7) implies that initrd-root-device is After=basic.target
# but that appears to not be the case. We explicitly order after sysinit.target
After=sysinit.target
After=initrd-root-device.target
Before=initrd-root-fs.target

[Service]
Type=oneshot
RemainAfterExit=yes
# See https://issues.redhat.com/browse/OCPBUGS-1505
# and https://github.com/coreos/fedora-coreos-config/pull/411
ExecStart=/bin/sh -c 'for x in {0..60}; do if mount -o ro -t iso9660 /${isosrc} /run/media/iso; then break; fi; sleep 1; done'
EOF
add_requires run-media-iso-mount.service initrd-root-fs.target
else
cat >"${UNIT_DIR}/run-media-iso.mount" <<EOF
cat >"${UNIT_DIR}/run-media-iso.mount" <<EOF
# Automatically generated by live-generator

[Unit]
Expand All @@ -127,13 +98,42 @@ Wants=systemd-udev-settle.service
After=sysinit.target
After=initrd-root-device.target
Before=initrd-root-fs.target
# This will make /run/media/iso get unmounted when no longer needed,
# which will aid in the coreos.liveiso.fromram case.
StopWhenUnneeded=true
cgwalters marked this conversation as resolved.
Show resolved Hide resolved

[Mount]
What=/${isosrc}
Where=/run/media/iso
Options=ro
Type=iso9660
EOF

# Determine what to mount in sysroot.mount based on if we were asked to run
# completely from RAM via coreos.liveiso.fromram karg.
if getargbool 0 coreos.liveiso.fromram; then
sysrootrequiresmountsfor=""
sysrootfsimg=/rootfs.img
# Add service to copy the rootfs.img from the ISO to memory
cat >"${UNIT_DIR}/coreos-liveiso-run-media-iso-cp-rootfsimg.service" <<EOF
# Automatically generated by live-generator

[Unit]
RequiresMountsFor=/run/media/iso
Before=sysroot.mount
# DefaultDependencies=true so this unit gets stopped on switchroot to
cgwalters marked this conversation as resolved.
Show resolved Hide resolved
# allow for /run/media/iso to get unmounted.
DefaultDependencies=true

[Service]
Type=oneshot
ExecStart=cp -v /run/media/iso/images/pxeboot/rootfs.img /rootfs.img
cgwalters marked this conversation as resolved.
Show resolved Hide resolved
RemainAfterExit=yes
EOF
add_requires coreos-liveiso-run-media-iso-cp-rootfsimg.service default.target
else
sysrootrequiresmountsfor="RequiresMountsFor=/run/media/iso"
sysrootfsimg=/run/media/iso/images/pxeboot/rootfs.img
fi

cat >"${UNIT_DIR}/sysroot.mount" <<EOF
Expand All @@ -142,12 +142,11 @@ EOF
[Unit]
DefaultDependencies=false
Before=initrd-root-fs.target
RequiresMountsFor=/run/media/iso
# on el8, the ISO is mounted by our own systemd unit
After=run-media-iso-mount.service
After=coreos-liveiso-run-media-iso-cp-rootfsimg.service
${sysrootrequiresmountsfor}

[Mount]
What=/run/media/iso/images/pxeboot/rootfs.img
What=${sysrootfsimg}
Where=/sysroot
Type=squashfs
# Offset of the squashfs within the rootfs cpio. Assumes newc format
Expand Down