For over a decade I have been an happy VirtualBox user and it has been my go-to desktop virtual machine manager. KVM/QEMU virtualisation never has never offered a good user experience for me, so the decision to continue using VirtualBox was always an ovious one. Some weeks ago, after an annoying VirtualBox installation on a SecureBoot enabled machine I decided to give KVM/QEMU. It worked nicely on the first try and, after some days of features testing, it became my new default choice.

This is not a guide on how to set up QEMU/KVM; rather, it is a list of four tips on how to use them with libvirt. It took me several hours to get started the first time, so hopefully this post will save you some time.

Note that commands and configurations are from my Fedora machine, so they may differ slightly on other distributions.

GUI - virt-manager

Gnome boxes is a GUI application for managing VMs and containers that comes pre-installed in many Linux distributions. Ignore it and install the full-featured virt-manager GUI.

$ sudo dnf install virt-manager

Both applications use the libvirt APIs to interact with QEMU/KVM but virt-manager UI exposes more features than Gnome-boxes.

Network

If you start a KVM/QEMU VM and it uses virt-manager’s (libvirt) default NAT, the Internet connection may not work as expected. This was the most annoying issues I encountered during the first run but the solution is simple. Edit your /etc/libvirt/network.conf file and set firewall_backend=iptables on the last line.

# Master configuration file for the network driver.
# All settings described here are optional - if omitted, sensible
# defaults are used.

# firewall_backend:
#
#   determines which subsystem to use to setup firewall packet
#   filtering rules for virtual networks.
#
#   Supported settings:
#
#     iptables - use iptables commands to construct the firewall
#     nftables - use nft commands to construct the firewall
#
#   If firewall_backend isn't configured, libvirt will choose the
#   first available backend from the following list:
#
#     [nftables, iptables]
#
#   If no backend is available on the host, then the network driver
#   will fail to start, and an error will be logged.
#
#   (NB: switching from one backend to another while there are active
#   virtual networks *is* supported. The change will take place the
#   next time that libvirtd/virtnetworkd is restarted - all existing
#   virtual networks will have their old firewalls removed, and then
#   reloaded using the new backend.)
#
firewall_backend = "iptables"

Restart the libvirt daemon after this change (make sure you stop any running VMs first).

$ sudo systemctl restart libvirtd

The default nftables backend does not work out of the box so you need to switch to iptables. Despite their differences, the iptables backend is still based on ntftables) so check whether the iptables-nft package is already installed on your machine.

Migrate VirtualBox OVA to QEMU

Use tar to extract the VMDK files from the OVA.

$ tar -xvf myvm.ova
myvm.ovf
myvm-disk001.vmdk

Then convert the VMDK disk file to qcow2 (QEMU disk format) using qemu-img.

$ qemu-img convert -O qcow2 myvm-disk001.vmdk myvm.qcow2

The qemu-img CLI tool is the QEMU disk image utility that allows you to create, convert and modify images. It supports a variety of formats, which you can check with a single command.

$ qemu-img -h | tail -n1
Supported formats: vvfat vpc vmdk vdi sheepdog raw host_cdrom host_floppy
host_device file qed qcow2 qcow parallels nbd dmg tftp ftps ftp https http
cow cloop bochs blkverify blkdebug

Increase QEMU qcow2 disk size

Lastly, if you want to resize a qcow image, qemu-img is (again) the tool you need. To increase the disk size run qemu-img resize filename.qcow2 +SIZE as shown below.

# Increase the image adding 30GB
$ qemu-img resize FreeBSD-14.3-RELEASE-amd64-zfs.qcow2 +30G

The SIZE argument can be a number of bytes or a number followed by a suffix (see qemu-img doc):

SIZE is the disk image size in bytes.
Optional suffixes are supported:
    k or K (kilobyte, 1024)
    M (megabyte, 1024k)
    G (gigabyte, 1024M)
    T (terabyte, 1024G)
    b is ignored

Keep in mind that after resizing it, you need to extend your partitions at OS level. However, this is an OS/file system specific task, so you will need to research it yourself.