blob: 55ad73cf368509d4bf434e2bb3c840e2fc60f394 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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 -smp 2 -m 1024 -display none -serial stdio -no-reboot \
-kernel "/usr/lib/modules/$(uname -r)/vmlinuz" -initrd "$stage.cpio" \
-append "console=ttyS0 quiet panic=-1"
|