summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2019-10-06 15:15:16 -0400
committerAndrew Cady <d@jerkface.net>2019-10-06 20:57:52 -0400
commit0ac3b66470711b6535281be4d3bc8ec7e260bdab (patch)
tree90d25dccb269ac31b4fc4d77c9bb367b3eef4671
parent5b289323280a3ead2440dc7022f89a29f5debe88 (diff)
qemu: moving toward nesting VMs
-rw-r--r--Makefile4
-rw-r--r--conf/kvm.conf2
-rwxr-xr-xsrc/qemu.sh30
3 files changed, 35 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index ce5803e..4f75fe9 100644
--- a/Makefile
+++ b/Makefile
@@ -36,6 +36,10 @@ samizdat-paths.sh: src/samizdat-paths.in
36 @sed -e "s?PREFIX?$(prefix)?g" $< > $@ 36 @sed -e "s?PREFIX?$(prefix)?g" $< > $@
37include samizdat-paths.sh 37include samizdat-paths.sh
38 38
39install-nested-kvm: conf/kvm.conf
40 install -m0644 conf/kvm.conf ${instdir}/etc/modprobe.d/
41 modprobe -r kvm-intel kvm-amd kvm; modprobe kvm; modprobe kvm-intel; modprobe kvm-amd; true
42
39install-configuration: 43install-configuration:
40ifndef instdir 44ifndef instdir
41 $(error "You must specify instdir, for safety.") 45 $(error "You must specify instdir, for safety.")
diff --git a/conf/kvm.conf b/conf/kvm.conf
new file mode 100644
index 0000000..dfc2d9d
--- /dev/null
+++ b/conf/kvm.conf
@@ -0,0 +1,2 @@
1options kvm_intel nested=1
2options kvm_amd nested=1
diff --git a/src/qemu.sh b/src/qemu.sh
index 8f365cb..2ae982d 100755
--- a/src/qemu.sh
+++ b/src/qemu.sh
@@ -64,8 +64,36 @@ if [ ! -e "$disk" ]; then
64 fallocate -l 10GB "$disk" 64 fallocate -l 10GB "$disk"
65fi 65fi
66 66
67if grep -q '^flags.*\<vmx\>' /proc/cpuinfo; then
68 kvm='-enable-kvm -cpu host'
69 read nested < /sys/module/kvm_intel/parameters/nested
70 if [ "$nested" != Y ]; then
71 printf '%s\n' \
72 'Warning: nested KVM is not available' \
73 'Try "make install-nested-kvm"'
74 fi
75else
76 >&2 printf '%s\n' \
77 '' \
78 'Warning: kernel virtual machine extensions (KVM) not available.' \
79 'The VM will be intolerably slow.' \
80 'If your hardware supports KVM, you need to enable it in the BIOS.' \
81 '' \
82 'If you are trying to run qemu in a virtual machine, you need to append' \
83 'the kvm-(intel|amd) module parameter "nested=1" on the _host_ machine.' \
84 'Use "make install-nested-kvm" to do so.' \
85 ''
86 kvm=
87fi
88
89mem_total=$(grep MemTotal /proc/meminfo | (read _ kb _; echo $((kb / 1024))))
90use_mem=640
91if [ "$mem_total" -le $((use_mem * 2)) ]; then
92 use_mem=$((mem_total / 2))
93fi
94
67set -x 95set -x
68sudo ${qemu} -enable-kvm -smp 2 -m 640 -k en-us \ 96sudo ${qemu} ${kvm} -smp 2 -m ${use_mem} -k en-us \
69 -vga qxl \ 97 -vga qxl \
70 -net nic,model=virtio,macaddr=$MAC \ 98 -net nic,model=virtio,macaddr=$MAC \
71 ${USE_NET:+ -net "$NET"} \ 99 ${USE_NET:+ -net "$NET"} \