#!/bin/bash set -Eeuo pipefail if [[ -d "/secrets" ]]; then /usr/local/bin/devbox-template fi # Add some /dev devices [ -e /dev/loop-control ] || mknod /dev/loop-control c 10 237 for i in {0..7}; do [ -e "/dev/loop$i" ] || mknod "/dev/loop$i" b 7 $i done # Rootless podman also opens /dev/net/tun (container network) and /dev/fuse # (fuse-overlayfs fallback). They have to be world-readable, since the dev user # is the one opening them. [ -d /dev/net ] || mkdir -p /dev/net [ -e /dev/net/tun ] || mknod /dev/net/tun c 10 200 [ -e /dev/fuse ] || mknod /dev/fuse c 10 236 chmod 0666 /dev/net/tun /dev/fuse # Nothing loads modules in a kata guest: there is no systemd, so no # systemd-modules-load.service. These are what nested podman needs, and # modprobe is a no-op for any of them that is built into the guest kernel. for mod in loop overlay veth bridge; do modprobe -q "$mod" 2>/dev/null || true done # 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() { local storage="$1" img="$2" owner="$3" local size="${DEVBOX_STORAGE_SIZE:-40G}" fstype loop 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 if mountpoint -q "$storage"; then return 0 fi # 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" 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" "root:root" overlay_fs "/home/dev/.local/share/containers/storage" "/home/dev/.local/share/containers/img" "dev:dev" # Without systemd nothing delegates the cgroup tree to dev, and rootless podman # then cannot create a cgroup for a container. This is all delegation is; it is # only safe when this container owns the tree it can see, which is the case with # its own cgroup namespace (podman's default) and not with --cgroupns=host. if [ "$(cat /proc/self/cgroup 2>/dev/null)" = "0::/" ] && [ -w /sys/fs/cgroup ]; then for ctrl in $(cat /sys/fs/cgroup/cgroup.controllers 2>/dev/null); do echo "+$ctrl" >/sys/fs/cgroup/cgroup.subtree_control 2>/dev/null || true done chown -R dev:dev /sys/fs/cgroup 2>/dev/null || true fi # Everything above needed root; from here on this is the dev user. exec so that # the shell replaces the entrypoint instead of being a child of it: as it was, # `su dev` ran a shell whose exit dropped you into a root one, and the container # only stopped when that second shell exited too. exec runuser -u dev -- /bin/bash # if [[ -z "${PASEO_PASSWORD:-}" ]]; then # echo "PASEO_PASSWORD is required" >&2 # exit 1 # fi # echo "[devbox] starting Paseo daemon on ${PASEO_LISTEN} (web UI: ${PASEO_WEB_UI_ENABLED})" # exec runuser -u dev -- paseo daemon run