From d6f736cd831c34d0c2286412b9540cb7f676c445 Mon Sep 17 00:00:00 2001 From: "re:fi.64" Date: Tue, 21 Jul 2026 20:43:19 -0500 Subject: [PATCH] nix/spindle: fix almalinux10 images having an undersized rootfs systemd-volatile-root uses only 25% of RAM for the rootfs, which is below the tmpfs default of 50% and makes it hard to do anything useful. There is no way to change this, so instead, we use a simple custom script to set up the rootfs before the initrd exits, with a better size used. --- nix/pkgs/spindle-almalinux-image.nix | 43 ++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/nix/pkgs/spindle-almalinux-image.nix b/nix/pkgs/spindle-almalinux-image.nix index 7ef9f115..98a1ff5c 100644 --- a/nix/pkgs/spindle-almalinux-image.nix +++ b/nix/pkgs/spindle-almalinux-image.nix @@ -75,6 +75,41 @@ ext4 ''; + # systemd-volatile-root defaults the overlay tmpfs size to 25% of RAM, which + # is smaller than the 50% default, too small to do anything useful + # (25% of 4GiB -> 1GiB, vs 50% -> 2GiB), and can't currently be customized: + # https://github.com/systemd/systemd/issues/25976 + # instead, we create our own spindle-volatile-root service for the initrd that + # does the same thing but using the default tmpfs size + volatileRootScript = writeText "spindle-volatile-root.sh" '' + #!/bin/bash + set -ex + + statedir=/run/spindle-volatile-root + mkdir -p $statedir + mount -t tmpfs tmpfs $statedir -o mode=0755 + + mkdir -p $statedir/{upper,work} + mount -t overlay overlay /sysroot -o lowerdir=/sysroot,upperdir=$statedir/upper,workdir=$statedir/work + + umount $statedir + rm -d $statedir # use rm, because rmdir isn't in the default initramfs + ''; + + volatileRootService = writeText "spindle-volatile-root.service" '' + [Unit] + Description=Spindle Volatile Root + DefaultDependencies=no + Conflicts=shutdown.target + After=sysroot.mount sysroot-usr.mount + Before=initrd-root-fs.target shutdown.target + + [Service] + Type=oneshot + RemainAfterExit=yes + ExecStart=/usr/bin/spindle-volatile-root + ''; + initService = writeText "spindle-init.service" '' [Unit] Description=Spindle system initialization @@ -142,8 +177,6 @@ "root=/dev/vda" "rootfstype=squashfs" - # volatile rootfs - "systemd.volatile=overlay" # selinux is not particularly useful for microvm CI "selinux=0" @@ -227,6 +260,12 @@ in # place the modules-load.d configuration in the initramfs, because # systemd-modules-load does not exist in the default rootfs install -D -m 0644 ${modulesConf} initrd-tree/etc/modules-load.d/spindle-modules.conf + # add the custom volatile root service + install -D -m 0755 ${volatileRootScript} initrd-tree/usr/bin/spindle-volatile-root + install -D -m 0755 ${volatileRootService} initrd-tree/usr/lib/systemd/system/spindle-volatile-root.service + mkdir -p initrd-tree/usr/lib/systemd/system/initrd-root-fs.target.requires + ln -s ../spindle-volatile-root.service initrd-tree/usr/lib/systemd/system/initrd-root-fs.target.requires/ + # build the initrd (cd initrd-tree && find . | bsdtar --format=newc --uid=0 --gid=0 -cnf - -T -) \ | zstd -12 > initrd -- 2.51.2