Skip to content

Commit

Permalink
overlay.d/05core: support booting ISO completely from RAM
Browse files Browse the repository at this point in the history
It has been presented to us a use case where the user wants to actually
"install" directly to the same device that was used to boot the live
ISO image (i.e. the ISO was written to a block device and then booted
from). The way the ISO boots today it mounts the ISO at /run/media/iso
and then mounts the CoreOS rootfs from a file under that mountpoint. In
this scenario /run/media/iso will be busy and can't be unmounted because
the root filesystem of the live running system depends on it.

We can adjust the strategy slightly to get a system that runs completely
from memory (similar to live PXE systems) by just copying the file out
of /run/media/iso and into memory before doing the rootfs mount, which
will allow /run/media/iso to be unmounted before the installation
commences.

This patchset adds a new coreos.liveiso.fromram option to allow
requesting this new behavior. We could consider making this new
behavior the default, but we'd need to consider the new RAM requirements.
For example, before this change on a 2G FCOS system the usage after
booting looks like:

```
[core@localhost ~]$ free -m
               total        used        free      shared  buff/cache   available
Mem:            1953         163        1286         125         503        1519
Swap:              0           0           0
```

With this change (and the coreos.liveiso.fromram kernel arguemnt
specified) the usage looks like:

```
[core@localhost ~]$ free -m
               total        used        free      shared  buff/cache   available
Mem:            1953         173         688         808        1091         824
Swap:              0           0           0
```

The usage would scale with the size of the rootfs. i.e. RHCOS is larger
so the memory requirements would be larger too.
  • Loading branch information
dustymabe committed Aug 14, 2023
1 parent da0bd62 commit 1334b72
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[Unit]
Description=Persist Osmet Files (ISO)
DefaultDependencies=false
ConditionPathExists=/run/ostree-live
ConditionKernelCommandLine=coreos.liveiso
RequiresMountsFor=/run/media/iso
Before=initrd-switch-root.target
# DefaultDependencies=true so this unit gets stopped on switchroot to
# 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 @@ -98,6 +98,9 @@ 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
[Mount]
What=/${isosrc}
Expand All @@ -106,16 +109,44 @@ 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
# 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
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
# Automatically generated by live-generator
[Unit]
DefaultDependencies=false
Before=initrd-root-fs.target
RequiresMountsFor=/run/media/iso
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

0 comments on commit 1334b72

Please sign in to comment.