From 0a4afa37fb314d24cdb3bc3da11eea01c6474eb5 Mon Sep 17 00:00:00 2001 From: Jakob Meng Date: Tue, 3 Oct 2023 10:04:42 +0200 Subject: [PATCH] overlay.d/05core: Writeable root fs for Live ISOs booted from RAM Previously, karg coreos.liveiso.fromram would cause live-generator to copy rootfs.img to a tmpfs and then mount it to /sysroot. Because rootfs.img contains a squashfs, /sysroot will be mounted read-only, preventing rpm-ostree operations such as install and rebase which are required by OKD/FCOS [0]. Now, with karg coreos.liveiso.fromram (Live ISO) or coreos.live.\ fromram (PXE boot) the rootfs.img will be mounted to /isoroot. The contents of /isoroot will be copied to /run/ephemeral and the latter will be bind-\ mounted to /sysroot. Because /run/ephemeral is a writeable xfs, both sysroot-etc.mount and sysroot-var.mount are not required in this case. For example, to rebase a FCOS/OKD bootimage first boot a Live ISO with Fedora 39 from RAM and then rebase and soft-reboot [1] (requires systemd v254) it with: rpm-ostree rebase fedora:fedora/x86_64/coreos/next rpm-ostree apply-live --allow-replacement systemctl soft-reboot [0] https://github.com/coreos/rpm-ostree/issues/4547 [1] https://www.freedesktop.org/software/systemd/man/systemd-soft-reboot.service.html --- .../modules.d/35coreos-live/live-generator | 126 +++++++++++------- 1 file changed, 78 insertions(+), 48 deletions(-) diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-live/live-generator b/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-live/live-generator index add4e6dcca..c59bd13fc5 100755 --- a/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-live/live-generator +++ b/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-live/live-generator @@ -28,8 +28,6 @@ fi > /run/ostree-live add_requires sysroot.mount initrd-root-fs.target -add_requires sysroot-etc.mount initrd-root-fs.target -add_requires sysroot-var.mount initrd-root-fs.target # make sure we enable network if required for coreos-livepxe-rootfs # https://github.com/coreos/fedora-coreos-tracker/issues/1423 add_requires coreos-enable-network.service initrd-root-fs.target @@ -53,12 +51,22 @@ ExecStartPre=/usr/sbin/ostree-cmdline start ExecStartPost=/usr/sbin/ostree-cmdline stop EOF +# Determine what to mount in sysroot.mount based on if we were asked to run +# completely from RAM via coreos.liveiso.fromram or coreos.live.fromram karg. +if getargbool 0 coreos.liveiso.fromram || getargbool 0 coreos.live.fromram; then + isorootmount=isoroot + isorootwhere=/isoroot +else + isorootmount=sysroot + isorootwhere=/sysroot +fi + isoroot=$(getarg coreos.liveiso= ||:) if [ -z "${isoroot}" ]; then # In this case, the rootfs is already unpacked into the initrd, or we need # to retrieve it - cat >"${UNIT_DIR}/sysroot.mount" <"${UNIT_DIR}/${isorootmount}.mount" <"${UNIT_DIR}/coreos-liveiso-run-media-iso-cp-rootfsimg.service" <"${UNIT_DIR}/sysroot.mount" <"${UNIT_DIR}/${isorootmount}.mount" <"${UNIT_DIR}/sysroot-xfs-ephemeral-setup.service" <"${UNIT_DIR}/sysroot-xfs-ephemeral-setup.service" <>"${UNIT_DIR}/sysroot.mount" <>"${UNIT_DIR}/sysroot-relabel.service" <"${UNIT_DIR}/sysroot-xfs-ephemeral-setup.service" < "${UNIT_DIR}/sysroot-etc.mount" -cat >>"${UNIT_DIR}/sysroot-etc.mount" < "${UNIT_DIR}/sysroot-etc.mount" + cat >>"${UNIT_DIR}/sysroot-etc.mount" <"${UNIT_DIR}/sysroot-var.mount" -cat >>"${UNIT_DIR}/sysroot-var.mount" <"${UNIT_DIR}/sysroot-var.mount" + cat >>"${UNIT_DIR}/sysroot-var.mount" <>"${UNIT_DIR}/sysroot-relabel.service" <>"${UNIT_DIR}/sysroot-relabel.service" <