Stop using kernel IP autoconfig for runtime VMs

Avoid the Alpine boot stall caused by kernel ip= autoconfig running before
virtio_net is available.

Split runtime and image-build boot args so managed VMs boot without kernel
network autoconfig, inject a static guest network config plus bootstrap
script into the runtime overlay, and keep image builds on the old path for
compatibility with existing base images.

Preserve executable bits when patching guest files into ext4 images and add
coverage for the new boot-arg split and guest network config generation.

Validated with go test ./..., a rebuilt Alpine image, and a fresh alp-fast
create/ssh check that brought vm.start down to about 2.7s.
This commit is contained in:
Thales Maciel 2026-03-21 21:54:18 -03:00
parent 092d848620
commit 14d8563f3c
No known key found for this signature in database
GPG key ID: 33112E6833C34679
7 changed files with 186 additions and 28 deletions

View file

@ -2,25 +2,59 @@
set -eu
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
CONFIG_PATH="/etc/banger-network.conf"
if ! command -v ip >/dev/null 2>&1; then
exit 0
fi
cmdline="$(cat /proc/cmdline 2>/dev/null || true)"
ip_arg=""
for arg in $cmdline; do
case "$arg" in
ip=*)
ip_arg="${arg#ip=}"
break
;;
esac
done
guest_ip=""
gateway_ip=""
netmask=""
iface_hint=""
dns1=""
dns2=""
if [ -z "$ip_arg" ]; then
exit 0
fi
load_file_config() {
if [ ! -r "$CONFIG_PATH" ]; then
return 1
fi
# shellcheck disable=SC1090
. "$CONFIG_PATH"
guest_ip="${GUEST_IP:-}"
gateway_ip="${GATEWAY_IP:-}"
netmask="${NETMASK:-}"
iface_hint="${INTERFACE:-}"
dns1="${DNS1:-}"
dns2="${DNS2:-}"
[ -n "$guest_ip" ]
}
load_cmdline_config() {
cmdline="$(cat /proc/cmdline 2>/dev/null || true)"
ip_arg=""
for arg in $cmdline; do
case "$arg" in
ip=*)
ip_arg="${arg#ip=}"
break
;;
esac
done
if [ -z "$ip_arg" ]; then
return 1
fi
guest_ip="$(field 1)"
gateway_ip="$(field 3)"
netmask="$(field 4)"
iface_hint="$(field 6)"
dns1="$(field 8)"
dns2="$(field 9)"
[ -n "$guest_ip" ]
}
field() {
printf '%s' "$ip_arg" | cut -d: -f"$1"
@ -81,12 +115,9 @@ find_iface() {
return 1
}
guest_ip="$(field 1)"
gateway_ip="$(field 3)"
netmask="$(field 4)"
iface_hint="$(field 6)"
dns1="$(field 8)"
dns2="$(field 9)"
if ! load_file_config; then
load_cmdline_config || exit 0
fi
if [ -z "$guest_ip" ]; then
exit 0