summaryrefslogtreecommitdiff
path: root/build/kernel_vm.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build/kernel_vm.sh')
-rw-r--r--build/kernel_vm.sh19
1 files changed, 19 insertions, 0 deletions
diff --git a/build/kernel_vm.sh b/build/kernel_vm.sh
new file mode 100644
index 0000000..ac7c576
--- /dev/null
+++ b/build/kernel_vm.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+# usage: kernel_vm.sh INIT COMMANDS FILE...
+# Boots this machine's kernel in QEMU on an initramfs of the files given
+# (and the C library, for the dynamic ones): INIT is its /init and runs each
+# line of COMMANDS as root. What the console says goes to stdout.
+set -e
+stage=$(mktemp -d)
+trap 'rm -rf "$stage" "$stage.cpio"' EXIT
+mkdir -p "$stage/proc" "$stage/sys" "$stage/dev" "$stage/lib64" "$stage/usr/lib"
+cp "$1" "$stage/init"
+cp "$2" "$stage/commands"
+shift 2
+cp "$@" "$stage/"
+cp /lib64/ld-linux-x86-64.so.2 "$stage/lib64/"
+cp /usr/lib/libc.so.6 "$stage/usr/lib/"
+(cd "$stage" && find . | cpio -o -H newc --quiet) >"$stage.cpio"
+timeout 120 qemu-system-x86_64 -enable-kvm -cpu host -m 512 -display none -serial stdio -no-reboot \
+ -kernel "/usr/lib/modules/$(uname -r)/vmlinuz" -initrd "$stage.cpio" \
+ -append "console=ttyS0 quiet panic=-1"