henriquehbr.xyz

Blog Supporters Resume
Part time open-sourcerer, Linux enthusiast, Rust fanatic

Creating a virtual machine with QEMU

February 04, 2022 — (Last edited on February 05, 2022)

Summary

Disclaimer

This guide makes assumes that:

These are far from being requirements, and are just a matter of my personal preference based on my system, you can use whatever you’re comfortable with

As a consequence, all the package names and file paths mentioned along this guide might differ, depending on your distro

Installing QEMU

doas pacman -S qemu

Creating virtual machine storage

The virtual machine storage is a file that holds all the data from a given virtual machine, run the command below to create it:

qemu-img create \
    -f qcow2 \
    Storage.img \
    16G

Running virtual machine

qemu-system-x86_64 \
    -enable-kvm \
    -cdrom OS_ISO.iso \
    -boot menu=on \
    -drive file=Image.img \
    -m 2G

Useful keybindings

UEFI support

First, install the edk2-ovmf package:

doas pacman -S edk2-ovmf

OVMF enables UEFI support for virtual machines, it contains sample UEFI firmware for QEMU and KVM

Then, run qemu with the same parameters mentioned on the Running virtual machine step, but this time with the -bios flag, example below:

qemu-system-x86_64 \
    -bios /usr/share/edk2-ovmf/OVMF.fd \
    -enable-kvm \
    -cdrom OS_ISO.iso \
    -boot menu=on \
    -drive file=Image.img \
    -m 2G

The -bios flag allow us to specify a custom firmware for the virtual machine, in this case, we are passing the path to edk2-ovmf UEFI firmware file

3D acceleration support

In case you’re running a wayland compositor like Sway, river or Mutter, having 3D acceleration enabled is a must in order to have a working graphical environment

To enable it, simply add the -device virtio-vga-gl flag when running the virtual machine

Special thanks