-
Notifications
You must be signed in to change notification settings - Fork 3
/
vm
executable file
·73 lines (61 loc) · 1.16 KB
/
vm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
BASE=$HOME/p/linux-trees
TREE=$BASE/linux
BUILD_DIR=$BASE/build-linux
QEMU_ARCH="x86_64"
QEMU="qemu-system-${QEMU_ARCH}"
QEMU_OPTS="-enable-kvm -smp 2 -m 1024"
VDISK="$HOME/p/virty.qcow2"
QEMU_MNT="/mnt/qemu"
TARGET="qemu"
set -e
function vm_mount_old {
sudo mount -o loop,offset=32256 $VDISK $QEMU_MNT
}
function vm_mount {
sudo modprobe nbd max_part=63
sudo qemu-nbd -c /dev/nbd0 $VDISK
sudo partprobe /dev/nbd0
sudo mount /dev/nbd0p1 $QEMU_MNT
}
function vm_umount {
sudo umount $QEMU_MNT
sudo qemu-nbd -d /dev/nbd0
sudo killall -q qemu-nbd
}
function vm_boot {
$QEMU -hda $VDISK \
${QEMU_OPTS} \
-kernel $BUILD_DIR/$TARGET/arch/x86/boot/bzImage \
-append "root=/dev/sda1 debug console=ttyS0 console=ttyS1 console=tty1" \
-net nic -net user,hostfwd=tcp::5555-:22 \
-serial stdio \
-device virtio-gpu-pci,virgl -display gtk,gl=on 2> /dev/null
}
function mk_help {
echo -e "Usage: $0 [target] cmd"
echo -e "\nCommands:\n" \
"\tmount\n" \
"\tumount\n" \
"\tospack <pack>\n" \
"\tboot\n" \
"\thelp"
}
case "$1" in
mount)
vm_mount
;;
umount)
vm_umount
;;
boot)
vm_boot
;;
help)
mk_help
;;
*)
mk_help
exit 1
esac
exit 0