Fri 15 Sep 2017 — Fri 26 Jan 2018

QEMU

QEMU lets you run an virtual machine emulated on a variety of hardware.

It doesn't have a graphical console, or any way to save a VM's state.

However, changes made to the image during operation are permenant.

You can make a layered file so that your changes are separated out from the base image.

Basic Operation

Run the binary specific to the architecture you want to emulate, such as qemu-system-arm.

  • -M some-machine to emulate a specific machine.
  • -cpu some-cpu
  • -m 2048 megabytes of memory
  • -drive format/raw,file=my-os-disk.img put in a disk
  • -kernel some-kernel-file
  • -append some stuff put in a kernel command line, e.g. to specify the boot partition with -append root=/dev/sda1.

Raspberry Pi Specifics

  curl https://raw.githubusercontent.com/dhruvvyas90/qemu-rpi-kernel/master/kernel-qemu-4.4.34-jessie > kernel-qemu

qemu-system-arm \
    -m versatilepb \
    -cpu arm1176 \
    -m 256 \
    -kernel kernel-qemu
    ## Whatever else you want

/etc/fstab likely entries about the memory card reader by default. This means that qemu will boot it in emergency mode, in which case lots of things won't work (like the network).

Networking

https://wiki.archlinux.org/index.php/QEMU#Networking

The default network (equivalent to -net nic -net user) works, but is slow. Ping doesn't work by default.

NIC -net nic
network device on the emulated guest machine.
TAP -net tap,ifname=eth0
makes a network device on the host machine available. You may have to sudo.
Virtual Distributed Ethernet (VDE)
useful for when you have multiple VMs.
Usermode network -net user
should give magical transparent network access.