diff options
| author | delusionalai <delusionalai@users.noreply.git.jnsn.dev> | 2026-11-16 22:09:56 +0000 |
|---|---|---|
| committer | delusionalai <delusionalai@users.noreply.git.jnsn.dev> | 2026-11-16 22:09:56 +0000 |
| commit | e237acf0f5161db48b9553db541e91e02b191f97 (patch) | |
| tree | fc80717c81eea2fa071839d5368b24374dd88afc | |
| parent | 83b26ae8184c4e3ab5a62021f371d2d656fb72ae (diff) | |
| download | devbox-e237acf0f5161db48b9553db541e91e02b191f97.tar.gz devbox-e237acf0f5161db48b9553db541e91e02b191f97.zip | |
login.sh: put the graphroot on a filesystem overlayfs can live on
Podman's overlay storage driver cannot be built on virtiofs, which is what the
graphroots sit on in a kata guest, so nested podman fails with "mount overlay:
invalid argument". The loop-mounted ext4 that was supposed to fix it never
happened, for two independent reasons:
- `df -PT "$STORAGE"` runs before anything has created $STORAGE, and df exits 1
on a nonexistent path, so the test is never true. mkdir -p was inside the if.
- even when df did answer, `cut -d' ' -f2` returns an empty string, because df
separates its columns with runs of spaces rather than single ones.
Once it does fire, three more things go wrong: truncate and mkfs run
unconditionally, so every start wipes every image and container; the ext4 is
root-owned, so the dev user gets EACCES on its own graphroot; and a failed
--make-rshared is swallowed with `|| true`, which leaves nested containers
without the shared mount propagation they need.
Also covers 9p, fuse, nfs, cifs and an overlay root, all of which need the loop
just as much as virtiofs does, and treats ext*/xfs/btrfs/f2fs/tmpfs as the
native case they are.
Co-Authored-By: pi <pi@pi.dev>
| -rw-r--r-- | login.sh | 49 |
1 files changed, 34 insertions, 15 deletions
@@ -10,29 +10,48 @@ fi for i in {0..7}; do [ -e "/dev/loop$i" ] || mknod "/dev/loop$i" b 7 $i done - -# Allocate a space for containers +# Podman's overlay storage driver cannot live on virtiofs, so those graphroots +# get a loop-mounted ext4 instead. Runs as root and hands the result to owner, +# who is the user that will run podman on it. function overlay_fs() { - STORAGE="$1" - IMG="$2" - SIZE=40G + local storage="$1" img="$2" owner="$3" + local size="${DEVBOX_STORAGE_SIZE:-40G}" fstype loop - if [ "$(df -PT "$STORAGE" | tail -1 | cut -d' ' -f2)" = "virtiofs" ]; then - mkdir -p "$STORAGE" + mkdir -p "$storage" + # df has to run after the mkdir, it fails on a path that does not exist, and + # it pads its columns with runs of spaces, so the type has to come from awk + # rather than `cut -d' '`. + fstype="$(df -PT "$storage" | tail -1 | awk '{print $2}')" + case "$fstype" in + virtiofs | 9p | fuse* | nfs* | cifs | overlay) ;; + # ext2/3/4, xfs, btrfs, f2fs and tmpfs can all host an overlayfs natively. + *) return 0 ;; + esac - # Create a sparse file for the fs - truncate -s "$SIZE" "$IMG" - mkfs.ext4 -qF -O dir_index,extent,has_journal "$IMG" + if mountpoint -q "$storage"; then + return 0 + fi - LOOP=$(losetup -f --show "$IMG") - mount -o noatime "$LOOP" "$STORAGE" + # Never truncate or format over an image that already holds a filesystem, + # that is how a restart used to wipe every image and container. + [ -e "$img" ] || truncate -s "$size" "$img" + blkid "$img" >/dev/null 2>&1 || mkfs.ext4 -qF -O dir_index,extent,has_journal "$img" - mount --make-rshared "$STORAGE" || true + loop="$(losetup -f --show "$img")" + if ! mount -o noatime "$loop" "$storage"; then + losetup -d "$loop" + exit 1 fi + # Nested containers need shared propagation, or podman's mounts are invisible + # in the namespaces it creates. Failing here means the outer container was + # started without it, so say so instead of carrying on. + mount --make-rshared "$storage" + + chown -R "$owner" "$storage" } -overlay_fs "/var/lib/containers/storage" "/var/tmp/containers.img" -overlay_fs "/home/dev/.local/share/containers/storage" "/home/dev/.local/share/containers/img" +overlay_fs "/var/lib/containers/storage" "/var/tmp/containers.img" "root:root" +overlay_fs "/home/dev/.local/share/containers/storage" "/home/dev/.local/share/containers/img" "dev:dev" su dev |
