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
73
74
|
#!/bin/sh
. samizdat-paths.sh
iso=${samizdat_iso_dir}/samizdat.iso
disk=${samizdat_iso_dir}/samizdat.disk.img
layered=${samizdat_iso_dir}/${iso%.iso}.layered.iso
[ -f "$layered" ] && iso=$layered
[ "$1" ] && iso=$1
initrd.sh || { echo "initrd.sh failed" >&2; exit 1; };
[ "$NO_NET" ] || USE_NET=y
NET='tap,vlan=0,ifname=tap0,script=no,downscript=no'
[ "$SLOW_BOOT" ] || QEMU_LOADS_LINUX=y
# To use qemu built-in pxe boot server:
# NET='user,tftp=isolinux,bootfile=/pxelinux.0'
nbd_filename=samizdat.btrfs
[ "$NBD_FILENAME" ] && nbd_filename=$NBD_FILENAME
initrd=${samizdat_isolinux_dir}/linux/initrd.img
kernel=${samizdat_isolinux_dir}/linux/vmlinuz
kcmdline_CDROM='boot=samizdat components quiet splash'
kcmdline_CDROM_NET="${kcmdline_CDROM} nbdroot=,${nbd_filename}, nbddev=/dev/nbd0 ip=dhcp"
kcmdline_NET="${kcmdline_CDROM_NET} netkeys"
MAC='52-54-00-12-34-56'
kcmdline_BOOTIF="BOOTIF=01-$MAC"
set --
if [ "$USE_ISO" ]; then
set -- "$@" -cdrom "$iso"
if [ "$QEMU_LOADS_LINUX" ]; then
set -- "$@" -initrd "$initrd" -kernel "$kernel"
if [ "$NO_NET" ]; then
set -- "$@" -append "$kcmdline_CDROM"
else
set -- "$@" -append "$kcmdline_CDROM_NET"
fi
else
set -- "$@" -boot d
fi
else
if [ "$QEMU_LOADS_LINUX" ]; then
set -- "$@" -initrd "$initrd" -kernel "$kernel" -append "$kcmdline_NET $kcmdline_BOOTIF"
else
set -- "$@" -boot n
fi
fi
case $(arch) in
x86_64) qemu=qemu-system-x86_64 ;;
*) qemu=qemu-system-i386 ;;
esac
if [ ! -e "$disk" ]; then
fallocate -l 10GB "$disk"
fi
set -x
sudo ${qemu} -enable-kvm -smp 2 -m 640 -k en-us \
-vga qxl \
-net nic,vlan=0,model=virtio,macaddr=$MAC \
${USE_NET:+ -net "$NET"} \
-rtc base=localtime \
-drive index=0,media=disk,format=raw,file="$disk" \
"$@"
|