mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
On an x86_64 Linux host, a --from base made from a Debian image (node:24) booted Debian's cloud kernel, which has no 9p (CONFIG_NET_9P is not set). Lima mounts with nofail, so every mount was an empty folder, and the shared tools' build VM failed at `cd /mnt/devvm-tools/.build`. Not a race and not nesting: it fails every time on that image, on the Debian 13 KVM guest and on bare-metal Fedora alike. - assets/oci/bootify.sh: Debian gets linux-image-$arch on every architecture (the generic kernel, already used on arm64 for gpio_keys), and net.ifnames=0 on its kernel command line: with the generic kernel udev's enp0s4 came up from Lima's MAC match before cloud-init's rename to eth0, which failed as busy and stopped its init stage, leaving no ssh host keys. - assets/shared-tools/build.sh: wait_share waits up to 60 s for .build/mise.lock, mounting the folder again from fstab while it isn't mounted, then fails naming the folder and mount's last error. - tools.txtar: wait_share there at once, mounted late, never mounted. - docs: internals/images.md (the wait), internals/design.md (the cloud kernel's missing 9p, the rename). Both scripts are in image keys: --from bases and every tool image rebuild. Co-Authored-By: Claude Opus 5.5 <[email protected]>
89 lines
5.7 KiB
Bash
Executable File
89 lines
5.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# Make a container image bootable as a Lima VM. Runs as root in a chroot of any Debian/Ubuntu or
|
|
# Alpine image (oci/build.sh). Adds what a container lacks: a kernel and initramfs, an init
|
|
# system, cloud-init (applies Lima's cidata: SSH key, guest agent, mounts, ports), sshd and sudo.
|
|
# Pre-creates the Lima guest user (USER_NAME/USER_UID/USER_HOME in the environment) so later layers
|
|
# can install into its home, in place of an image's own user with that uid. Writes the kernel command line the image needs to /etc/devvm/cmdline.
|
|
set -eu
|
|
# shellcheck source=/dev/null
|
|
. /etc/os-release
|
|
case " $ID ${ID_LIKE:-} " in
|
|
*" ubuntu "*|*" debian "*) family=debian ;;
|
|
*" alpine "*) family=alpine ;;
|
|
*) echo "bootify: unsupported distro '$ID' (supported: Debian/Ubuntu and Alpine families)" >&2; exit 1 ;;
|
|
esac
|
|
mkdir -p /etc/devvm /etc/cloud/cloud.cfg.d
|
|
|
|
if [ "$family" = debian ]; then
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
arch=$(dpkg --print-architecture)
|
|
# Debian's generic kernel, not its cloud one, which lacks two things devvm needs: 9p, which
|
|
# QEMU's mounts on a Linux host use (without it each mount is an empty folder), and on arm64 the
|
|
# gpio_keys driver, which Virtualization.framework's shutdown key needs (Lima's stop then times
|
|
# out and hard-kills the VM, losing unsynced writes). Ubuntu's virtual kernel has both.
|
|
if [ "$ID" = ubuntu ]; then extra="linux-image-virtual netplan.io"
|
|
else extra="linux-image-$arch"; fi
|
|
apt-get update
|
|
# shellcheck disable=SC2086 # $extra is a package list
|
|
apt-get install -y --no-install-recommends initramfs-tools $extra \
|
|
systemd systemd-sysv systemd-timesyncd systemd-resolved libpam-systemd udev dbus kmod \
|
|
cloud-init cloud-guest-utils e2fsprogs iproute2 openssh-server sudo bash \
|
|
ca-certificates curl less locales tzdata lsb-release rsync
|
|
rm -rf /var/lib/apt/lists/*
|
|
# Debian kernels build the virtio drivers as modules, so the initramfs must load them to find
|
|
# the root disk and console (Ubuntu's virtual kernel has them built in; listing them is harmless).
|
|
printf '%s\n' virtio_pci virtio_mmio virtio_blk virtio_net virtio_console ext4 >> /etc/initramfs-tools/modules
|
|
update-initramfs -u -k all
|
|
# cloud-init sets LANG=en_US.UTF-8; Debian's locale-gen only builds locales listed in locale.gen.
|
|
if [ -f /etc/locale.gen ]; then sed -i 's/^# *\(en_US.UTF-8 UTF-8\)/\1/' /etc/locale.gen && locale-gen; fi
|
|
echo gpio_keys > /etc/modules-load.d/devvm.conf
|
|
systemctl enable ssh systemd-networkd systemd-resolved
|
|
# Without netplan (Debian), cloud-init writes Lima's eth0 config with RequiredForOnline=no, so
|
|
# networkd-wait-online has no link to wait for: every boot waited 2 minutes and ended "degraded".
|
|
# Wait for eth0 (Lima's network) itself instead.
|
|
if [ "$ID" != ubuntu ]; then
|
|
mkdir -p /etc/systemd/system/systemd-networkd-wait-online.service.d
|
|
printf '[Service]\nExecStart=\nExecStart=/usr/lib/systemd/systemd-networkd-wait-online --interface=eth0 --timeout=30\n' \
|
|
> /etc/systemd/system/systemd-networkd-wait-online.service.d/devvm.conf
|
|
fi
|
|
# No LLMNR/mDNS: their listeners on 5355/5353 would otherwise be forwarded to the host by Lima.
|
|
mkdir -p /etc/systemd/resolved.conf.d
|
|
printf '[Resolve]\nLLMNR=no\nMulticastDNS=no\n' > /etc/systemd/resolved.conf.d/devvm.conf
|
|
# Keep the image's apt sources: cloud-init would otherwise rewrite them.
|
|
printf 'datasource_list: [ NoCloud, None ]\napt:\n preserve_sources_list: true\n' > /etc/cloud/cloud.cfg.d/90-devvm.cfg
|
|
# Debian keeps the kernel's name for Lima's network card, eth0, the name Lima's config gives it:
|
|
# udev's name (enp0s4 on QEMU) came up from that config's MAC match before cloud-init renamed
|
|
# it, the rename failed as busy, and cloud-init's init stage stopped there with no ssh host keys.
|
|
cmdline="root=/dev/vda rw console=hvc0"
|
|
[ "$ID" = ubuntu ] || cmdline="$cmdline net.ifnames=0"
|
|
echo "$cmdline" > /etc/devvm/cmdline
|
|
# Another user with the uid (Ubuntu's own ubuntu, 1000, a Linux host's usual uid) goes: files are
|
|
# told apart by uid.
|
|
other=$(getent passwd "$USER_UID" | cut -d: -f1 || true)
|
|
if [ -n "$other" ] && [ "$other" != "$USER_NAME" ]; then userdel -r "$other" 2>/dev/null || userdel "$other"; fi
|
|
useradd --create-home --home-dir "$USER_HOME" --uid "$USER_UID" --shell /bin/bash "$USER_NAME"
|
|
else
|
|
apk add --no-cache linux-virt mkinitfs alpine-base openrc cloud-init e2fsprogs e2fsprogs-extra \
|
|
openssh sudo bash shadow ca-certificates curl rsync tzdata blkid
|
|
# cloud-init finds Lima's cidata disk by its ISO 9660 label: needs the full blkid (busybox's
|
|
# can't read the label) and the isofs module loaded at boot.
|
|
echo isofs >> /etc/modules
|
|
# Services a booted Alpine needs (a container image has none enabled).
|
|
for s in devfs dmesg mdev hwdrivers; do rc-update add "$s" sysinit; done
|
|
for s in modules sysctl hostname bootmisc syslog networking; do rc-update add "$s" boot; done
|
|
rc-update add sshd default
|
|
setup-cloud-init
|
|
echo 'datasource_list: [ NoCloud, None ]' > /etc/cloud/cloud.cfg.d/90-devvm.cfg
|
|
echo "root=/dev/vda rootfstype=ext4 rw console=hvc0 modules=virtio_blk,ext4" > /etc/devvm/cmdline
|
|
other=$(getent passwd "$USER_UID" | cut -d: -f1 || true)
|
|
if [ -n "$other" ] && [ "$other" != "$USER_NAME" ]; then deluser --remove-home "$other"; fi
|
|
adduser -D -h "$USER_HOME" -u "$USER_UID" -s /bin/bash "$USER_NAME"
|
|
usermod -p '*' "$USER_NAME" # no password, but not "locked" (sshd refuses locked accounts)
|
|
fi
|
|
|
|
# The root filesystem is the whole disk (no partition table); Lima attaches it as /dev/vda.
|
|
echo '/dev/vda / ext4 defaults 0 1' > /etc/fstab
|
|
rm -f /etc/ssh/ssh_host_* # generated per VM by cloud-init
|
|
echo "$USER_NAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-devvm
|
|
chmod 440 /etc/sudoers.d/90-devvm
|