diff --git a/lib.shs b/lib.shs index 4de0032..3a77288 100644 --- a/lib.shs +++ b/lib.shs @@ -1,6 +1,9 @@ #!/bin/false -mach=$(basename $(dirname "$0")) +mach="${0#*machines/}" +mach="${mach%%/*}" +net="${0#*networks/}" +net="${net%%/*}" netns=netns nethorror_root="`pwd`" # and hope? @@ -49,7 +52,7 @@ bridge_name() { } make_bridge() { - br="$(bridge_name "$mach")" + br="$(bridge_name "$net")" ip link add name "$br" type bridge ip link set dev "$br" up } diff --git a/machines/loc1xe/setup.sh b/machines/loc1xe/setup.sh index d1f968e..6e79802 100755 --- a/machines/loc1xe/setup.sh +++ b/machines/loc1xe/setup.sh @@ -29,5 +29,5 @@ nsenter --net="$vm_netns" ip route add 2a01:4f8:c0c:36b8:ff01:8000:0:0001/128 de nsenter --net="$vm_netns" ip route add default via 2a01:4f8:c0c:36b8:ff01:8000:0:0001 dev wg-vms nsenter --net="$vm_netns" sysctl net.ipv6.conf.all.forwarding=1 - +nsenter --net="$vm_netns" ./machines/$mach/vm1/start.sh #nsenter --net="$vm_netns" ip route add 2a01:4f8:c0c:36b8:ff01:8000:0:0001/128 dev wg-vms onlink diff --git a/machines/loc1xe/vm1/create.sh b/machines/loc1xe/vm1/create.sh new file mode 100755 index 0000000..54563a9 --- /dev/null +++ b/machines/loc1xe/vm1/create.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# LEdoian's absurdly simple initrd generator (ad-hoc arc) + +set -eu +outdir="$1" + +mkdir "$outdir/initrd" +cp init "$outdir/initrd/" + +busybox="$(which busybox)" +cp "$busybox" "$outdir/initrd/busybox" + +# TODO: get kernel version from /boot/vmlinuz-linux (which we use) +kver="$(uname -r)" +zstdcat /usr/lib/modules/$kver/kernel/drivers/net/ethernet/intel/e1000/e1000.ko.zst > "$outdir/initrd/e1000.ko" + +pushd "$outdir/initrd" +find . | cpio -o -H newc > ../initrd.img +popd diff --git a/machines/loc1xe/vm1/init b/machines/loc1xe/vm1/init new file mode 100755 index 0000000..2418c7d --- /dev/null +++ b/machines/loc1xe/vm1/init @@ -0,0 +1,12 @@ +#!/busybox ash + +/busybox echo START +#/busybox mdev -s +# we know the modules, lol :-) +/busybox insmod /e1000.ko +/busybox ip link set lo up +/busybox ip addr add 2a01:4f8:c0c:36b8:ff01:8000:0:3/128 dev eth0 +/busybox ip link set eth0 up +/busybox ip route add default via 2a01:4f8:c0c:36b8:ff01:8000:0:1 dev eth0 onlink + +/busybox ash diff --git a/machines/loc1xe/vm1/run.sh b/machines/loc1xe/vm1/run.sh new file mode 100755 index 0000000..7eab8c7 --- /dev/null +++ b/machines/loc1xe/vm1/run.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +set -eu + +arch=x86_64 +kernel=/boot/vmlinuz-linux +initrd_dir="$1" +shift 1 +exec qemu-system-"$arch" -m 1G -kernel "$kernel" -initrd "$initrd_dir/initrd.img" -nographic -append console=ttyS0,115200n1 "$@" diff --git a/machines/loc1xe/vm1/start.sh b/machines/loc1xe/vm1/start.sh new file mode 100755 index 0000000..9e4208c --- /dev/null +++ b/machines/loc1xe/vm1/start.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +. ./lib.shs + +mkdir state/$mach/initdir +tmux new-window -d vm1 sh -c machines/$mach/vm1/create.sh state/$mach/initdir \&\& machines/$mach/vm1/run.sh state/$mach/initdir