QEMU Configuration & Usage

This will cover some QEMU options I have found useful beyond the basics.

Machine Type

-M q35 configures a more modern chipset to be emulated. The Q35 chipset supports PCI-e and includes an AHCI controller 1.

UEFI
Get UEFI support by replacing the bios with -bios ovmf-x64/OVMF-pure-efi.fd or OVMF-with-csm.fd if legacy boot is desired.
OVMF can be downloaded from https://www.kraxel.org/repos/jenkins/edk2/ (edk2.git-ovmf-x64-...), bsdtar can extract rpms.
Attaching disk images using VirtIO

Use -drive file=disk.img,if=virtio for improved disk performance. Windows guests require additional drivers 2 to use this.

Attaching raw disks
-drive file=/dev/sdb,if=virtio,format=raw,cache=no
When attaching entire disks, partitions or logical volumes cache=no is a good idea.
Share host directory to guest

-drive file=fat:/path/to/dir,snapshot=on creates a read-only virtual FAT-formatted disk image from the given directory.

Multiple CD-ROM images
-drive file=X.iso,index=0,media=cdrom -drive file=Y.iso,index=1,media=cdrom
The index=N parameter is optional but can be used to explicitly order drives.
Bridged Network Adapter
-netdev bridge,br=br0,id=mynet -device virtio-net-pci,netdev=mynet
short syntax: -nic bridge,br=br0,model=virtio
For virtio, Windows needs additional drivers 2.
Aside from virtio-net-pci QEMU also supports emulating real cards such as:
e1000e (Intel 82574L GbE) which is the default, e1000 (Intel 82540EM GbE) or rtl8139 (Realtek RTL-8139C 10/100M)
CPU type
The default is -cpu qemu64.
To get the full CPU feature set in the guest use -cpu host or the appropriate family, e.g. -cpu Haswell.
Alternatively, flags can also be enabled individually: -cpu qemu64,+ssse3,+sse4.2,+avx,+avx2
-cpu kvm64 is legacy and should not be used 3.
VNC

-display vnc=localhost:1,lossy starts VNC on port 5901 with enabled lossy compression to save bandwidth.

USB Input Devices

-usb -device usb-tablet -device usb-kbd improves mouse support especially when using VNC.

VGA driver
-vga qxl offers improved performance over the default (std). Windows needs drivers, again 2.
3D acceleration for Linux guests is possible with -vga virtio 4.
Serial console

-serial pty connects the serial port to a PTY, which can then be interacted with using screen.

Emulated SCSI controller
(because it's possible, not because it's useful)
-device lsi,id=lsi -drive file=somewhere.img,if=none,id=disk0 -device scsi-hd,drive=disk0,bus=lsi.0