diff options
author | Andrew Cady <d@jerkface.net> | 2019-10-06 15:15:16 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2019-10-06 20:57:52 -0400 |
commit | 0ac3b66470711b6535281be4d3bc8ec7e260bdab (patch) | |
tree | 90d25dccb269ac31b4fc4d77c9bb367b3eef4671 | |
parent | 5b289323280a3ead2440dc7022f89a29f5debe88 (diff) |
qemu: moving toward nesting VMs
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | conf/kvm.conf | 2 | ||||
-rwxr-xr-x | src/qemu.sh | 30 |
3 files changed, 35 insertions, 1 deletions
@@ -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" $< > $@ |
37 | include samizdat-paths.sh | 37 | include samizdat-paths.sh |
38 | 38 | ||
39 | install-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 | |||
39 | install-configuration: | 43 | install-configuration: |
40 | ifndef instdir | 44 | ifndef 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 @@ | |||
1 | options kvm_intel nested=1 | ||
2 | options 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" |
65 | fi | 65 | fi |
66 | 66 | ||
67 | if 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 | ||
75 | else | ||
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= | ||
87 | fi | ||
88 | |||
89 | mem_total=$(grep MemTotal /proc/meminfo | (read _ kb _; echo $((kb / 1024)))) | ||
90 | use_mem=640 | ||
91 | if [ "$mem_total" -le $((use_mem * 2)) ]; then | ||
92 | use_mem=$((mem_total / 2)) | ||
93 | fi | ||
94 | |||
67 | set -x | 95 | set -x |
68 | sudo ${qemu} -enable-kvm -smp 2 -m 640 -k en-us \ | 96 | sudo ${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"} \ |