Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| docs:guide-user:virtualization:qemu_host [2018/06/04 12:07] – [Introduction] added qemu-bridge-helper link sebastian | docs:guide-user:virtualization:qemu_host [2022/05/30 09:04] (current) – [Download installer files] use https sebastian | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== OpenWrt |
| ===== Introduction ===== | ===== Introduction ===== | ||
| - | It's possible to use OpenWrt as a QEMU host and run guests on it. If you want to run OpenWrt as a QEMU guest, see [[docs: | + | It's possible to use OpenWrt as a QEMU host and run guests on it. If you want to run OpenWrt as a QEMU guest itself, see [[docs: |
| - | + | ||
| - | OpenWrt provides QEMU packages for ARM and x86 platforms. This article focuses on the x86 target, the networking is done via [[https:// | + | |
| + | OpenWrt provides QEMU packages for ARM and x86 platforms. This article focuses on the x86 target, the networking is done via [[https:// | ||
| ===== Installing QEMU ===== | ===== Installing QEMU ===== | ||
| You need the following packages on your device: [[packages: | You need the following packages on your device: [[packages: | ||
| Line 26: | Line 25: | ||
| </ | </ | ||
| - | **Line 3** creates a virtio net device with a fixed MAC address | + | **Line 3** creates a virtio net device with a fixed MAC address |
| If your guest uses DHCP it should now receive an address by the server running in '' | If your guest uses DHCP it should now receive an address by the server running in '' | ||
| You can choose any other bridge interface available on your OpenWrt host as well. See [[docs: | You can choose any other bridge interface available on your OpenWrt host as well. See [[docs: | ||
| + | If you want to change which networks QEMU is allowed to connect to, you can do so via ''/ | ||
| ===== Installing Debian as guest OS ===== | ===== Installing Debian as guest OS ===== | ||
| Line 42: | Line 42: | ||
| ==== Download installer files ==== | ==== Download installer files ==== | ||
| <code bash> | <code bash> | ||
| - | wget http:// | + | wget https:// |
| - | wget http:// | + | wget https:// |
| </ | </ | ||
| Both files can be savely removed after finishing the installation. | Both files can be savely removed after finishing the installation. | ||
| Line 76: | Line 76: | ||
| To automatically start the VM at boot and shut it down cleanly using [[https:// | To automatically start the VM at boot and shut it down cleanly using [[https:// | ||
| <WRAP center round important 60%> | <WRAP center round important 60%> | ||
| - | Be careful with copying the heredoc part. This code block is left unindented on purpose to avoid problems with whitespaces. If you want, you can indent the lines with tabs and use '' | + | Be careful with copying the heredoc part. This code block is left unindented on purpose to avoid problems with whitespaces. If you want, you can indent the lines with tabs and use '' |
| </ | </ | ||
| Line 84: | Line 84: | ||
| START=99 | START=99 | ||
| STOP=1 | STOP=1 | ||
| + | |||
| + | qemu_pidfile="/ | ||
| start() { | start() { | ||
| qemu-system-x86_64 -enable-kvm -cpu host -smp 2 -m 2G \ | qemu-system-x86_64 -enable-kvm -cpu host -smp 2 -m 2G \ | ||
| - | | + | -drive file=/ |
| - | -device virtio-net-pci, | + | -device virtio-net-pci, |
| - | -netdev bridge, | + | -netdev bridge, |
| - | -qmp tcp: | + | -qmp tcp: |
| - | -daemonize &> / | + | -daemonize &> / |
| + | |||
| + | / | ||
| + | echo "QEMU: Started VM with PID $(cat $qemu_pidfile)." | ||
| } | } | ||
| stop() { | stop() { | ||
| + | echo "QEMU: Sending ' | ||
| nc localhost 4444 << | nc localhost 4444 << | ||
| - | { " | + | { " |
| - | { " | + | { " |
| QMP | QMP | ||
| - | sleep 10s | + | if [ -e $qemu_pidfile ]; then |
| + | if [ -e /proc/$(cat $qemu_pidfile) ]; then | ||
| + | echo "QEMU: Waiting for VM shutdown." | ||
| + | while [ -e /proc/$(cat $qemu_pidfile) ]; do sleep 1s; done | ||
| + | echo "QEMU: VM Process $(cat $qemu_pidfile) finished." | ||
| + | else | ||
| + | echo "QEMU: Error: No VM with PID $(cat $qemu_pidfile) running." | ||
| + | fi | ||
| + | |||
| + | rm -f $qemu_pidfile | ||
| + | else | ||
| + | echo "QEMU: Error: $qemu_pidfile doesn' | ||
| + | fi | ||
| } | } | ||
| </ | </ | ||
| - | FIXME This script currently uses a fixed time of 10 seconds to wait for the VM shutdown. Provide a better way to wait for the qemu process to finish | ||
| Test the the script by running ''/ | Test the the script by running ''/ | ||
| If the script works as desired, enable it for every boot: ''/ | If the script works as desired, enable it for every boot: ''/ | ||
| + | |||
| + | FIXME This script needs to be ported to [[: | ||