diff options
Diffstat (limited to 'login.sh')
| -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 |
