diff options
Diffstat (limited to 'login.sh')
| -rw-r--r-- | login.sh | 68 |
1 files changed, 26 insertions, 42 deletions
@@ -6,72 +6,58 @@ if [[ -d "/secrets" ]]; then 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. +# Load the required kernel modules 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 + local storage="$1" + local img="$2" + local owner="$3" + local size="40G" 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}')" + chown -R "$owner" "$storage" + local fstype="$(df -PT "$storage" | tail -1 | awk '{print $2}')" + echo "$fstype" 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 ;; + virtiofs | 9p | fuse* | nfs* | cifs | overlay) ;; + *) 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. + # Set us up for loopback + [ -e /dev/loop-control ] || mknod /dev/loop-control c 10 237 || true + for i in {0..7}; do + [ -e "/dev/loop$i" ] || mknod "/dev/loop$i" b 7 $i || true + done + [ -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")" + local 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" +overlay_fs "/var/lib/containers/storage" "/var/tmp/containers.img" "root:root" || + echo "/var/lib/containers/storage must be bind mounted to a real filesystem" +overlay_fs "/home/dev/.local/share/containers/storage" "/home/dev/.local/share/containers/img" "dev:dev" || + echo "/home/dev/.local/share/containers/storage must be bind mounted to a real filesystem" + + +chmod u+s /bin/newgidmap +chmod u+s /bin/newuidmap -# 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 @@ -79,8 +65,6 @@ if [ "$(cat /proc/self/cgroup 2>/dev/null)" = "0::/" ] && [ -w /sys/fs/cgroup ]; chown -R dev:dev /sys/fs/cgroup 2>/dev/null || true fi -su dev - # if [[ -z "${PASEO_PASSWORD:-}" ]]; then # echo "PASEO_PASSWORD is required" >&2 # exit 1 @@ -88,4 +72,4 @@ su dev # echo "[devbox] starting Paseo daemon on ${PASEO_LISTEN} (web UI: ${PASEO_WEB_UI_ENABLED})" # exec paseo daemon run -exec /bin/bash +exec runuser -u dev -- /bin/bash |
