summaryrefslogtreecommitdiff
path: root/src/qemu.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/qemu.sh')
-rwxr-xr-xsrc/qemu.sh129
1 files changed, 0 insertions, 129 deletions
diff --git a/src/qemu.sh b/src/qemu.sh
deleted file mode 100755
index 0300c71..0000000
--- a/src/qemu.sh
+++ /dev/null
@@ -1,129 +0,0 @@
1#!/bin/sh
2
3. samizdat-paths.sh
4
5case "$(id -u)" in
6 0) sudo= ;;
7 *) sudo=sudo ;;
8esac
9
10iso=${samizdat_iso_dir}/samizdat.iso
11disk=${samizdat_iso_dir}/samizdat.disk.img
12layered=${samizdat_iso_dir}/${iso%.iso}.layered.iso
13
14[ -f "$layered" ] && iso=$layered
15
16[ "$1" ] && iso=$1
17
18[ "$NO_NET" ] || USE_NET=y
19
20NET='tap,ifname=tap0,script=no,downscript=no'
21
22[ "$SLOW_BOOT" ] || QEMU_LOADS_LINUX=y
23
24# To use qemu built-in pxe boot server:
25# NET='user,tftp=isolinux,bootfile=/pxelinux.0'
26
27nbd_filename=samizdat.btrfs
28[ "$NBD_FILENAME" ] && nbd_filename=$NBD_FILENAME
29
30initrd=${samizdat_isolinux_dir}/linux/initrd.img
31kernel=${samizdat_isolinux_dir}/linux/vmlinuz
32kcmdline_CDROM='boot=samizdat components quiet'
33kcmdline_CDROM_NET="${kcmdline_CDROM} nbdroot=,${nbd_filename}, nbddev=/dev/nbd0 ip=dhcp"
34kcmdline_NET="${kcmdline_CDROM_NET} netkeys"
35
36find_mac()
37{
38 start_mac=$1
39 for mac in $(ip link show | grep link/ether | (read _ mac _; echo $mac | tr : -)); do
40 if [ "${mac%??}" = "${start_mac%??}" ]; then
41 prefix=${mac%??}
42 suffix=$(printf %x $(( 0x${mac##*-} + 1 )))
43 MAC=${prefix}${suffix}
44 return
45 fi
46 done
47 MAC=$start_mac
48}
49find_mac 52-54-00-12-34-56
50
51kcmdline_BOOTIF="BOOTIF=01-$MAC"
52
53set --
54if [ "$USE_ISO" ]; then
55 set -- "$@" -cdrom "$iso"
56 if [ "$QEMU_LOADS_LINUX" ]; then
57 set -- "$@" -initrd "$initrd" -kernel "$kernel"
58 if [ "$NO_NET" ]; then
59 set -- "$@" -append "$kcmdline_CDROM"
60 else
61 set -- "$@" -append "$kcmdline_CDROM_NET"
62 fi
63 else
64 set -- "$@" -boot d
65 fi
66else
67 if [ "$QEMU_LOADS_LINUX" ]; then
68 set -- "$@" -initrd "$initrd" -kernel "$kernel" -append "$kcmdline_NET $kcmdline_BOOTIF"
69 else
70 set -- "$@" -boot n
71 fi
72fi
73
74case $(arch) in
75 x86_64) qemu=qemu-system-x86_64 ;;
76 *) qemu=qemu-system-i386 ;;
77esac
78
79try_fallocate()
80{
81 for size in "$@"; do
82 fallocate -l "$size" "$disk"~tmp || continue
83 mv "$disk"~tmp "$disk"
84 return
85 done
86 false
87}
88
89if [ ! -e "$disk" ]; then
90 try_fallocate 16GB 8GB 4GB 2GB 1GB ||
91 echo "Warning: no virtual disk (could not create $disk)" >&2
92fi
93
94if grep -q '^flags.*\<vmx\>' /proc/cpuinfo; then
95 kvm='-enable-kvm -cpu host'
96 read nested < /sys/module/kvm_intel/parameters/nested
97 if [ "$nested" != Y ]; then
98 printf '%s\n' \
99 'Warning: nested KVM is not available' \
100 'Try "make install-nested-kvm"'
101 fi
102else
103 >&2 printf '%s\n' \
104 '' \
105 'Warning: kernel virtual machine extensions (KVM) not available.' \
106 'The VM will be intolerably slow.' \
107 'If your hardware supports KVM, you need to enable it in the BIOS.' \
108 '' \
109 'If you are trying to run qemu in a virtual machine, you need to append' \
110 'the kvm-(intel|amd) module parameter "nested=1" on the _host_ machine.' \
111 'Use "make install-nested-kvm" to do so.' \
112 ''
113 kvm=
114fi
115
116mem_total=$(grep MemTotal /proc/meminfo | (read _ kb _; echo $((kb / 1024))))
117use_mem=640
118if [ "$mem_total" -le $((use_mem * 2)) ]; then
119 use_mem=$((mem_total / 2))
120fi
121
122set -x
123$sudo ${qemu} ${kvm} -smp 2 -m ${use_mem} -k en-us \
124 -vga qxl \
125 -net nic,model=virtio,macaddr=$MAC \
126 ${USE_NET:+ -net "$NET"} \
127 -rtc base=localtime \
128 -drive index=0,media=disk,format=raw,file="$disk" \
129 "$@"