Virtualisation with QEMU¶
Note
Please bear in mind that invoking QEMU manually may sometimes require your user to be part of the kvm
group.
QEMU is a machine emulator that can run operating systems and programs for one machine on a different machine. However, it is more often used as a virtualiser in collaboration with KVM kernel components. In that case it uses the hardware virtualisation technology to virtualise guests.
Although QEMU has a command line interface and a monitor to interact with running guests, they are typically only used for development purposes. libvirt provides an abstraction from specific versions and hypervisors and encapsulates some workarounds and best practices.
Running QEMU/KVM¶
While there are more user-friendly and comfortable ways, the quickest way to get started with QEMU is by directly running it from the netboot ISO. You can achieve this by running the following command:
qemu-system-x86_64 -enable-kvm -cdrom http://archive.ubuntu.com/ubuntu/dists/bionic-updates/main/installer-amd64/current/images/netboot/mini.iso
Downloading the ISO provides for faster access at runtime. We can now allocate the space for the VM:
qemu-img create -f qcow2 disk.qcow 5G
And then we can use the disk space we have just allocated for storage by adding the argument: -drive file=disk.qcow,format=qcow2
.
These tools can do much more, as you’ll discover in their respective (long) manpages. They can also be made more consumable for specific use-cases and needs through a vast selection of auxiliary tools - for example virt-manager for UI-driven use through libvirt. But in general, it comes down to:
qemu-system-x86_64 options image[s]
So take a look at the QEMU manpage, qemu-img
and the QEMU documentation and see which options best suit your needs.
Next steps¶
QEMU can be extended in many different ways. If you’d like to take QEMU further, you might want to check out this follow-up guide on virtualizing graphics using QEMU/KVM, or this guide on how you can use QEMU to create MicroVMs.