Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

The Short Answer

A virtual machine needs a disk controller and a network card. The hypervisor can give it a software copy of a real, well-known device, or a VirtIO device designed only for virtual machines. Real-device emulation works with any guest but costs CPU time on every operation. VirtIO devices cut that cost, so they are the normal choice for Linux guests on KVM.

Emulated vs Paravirtualized Devices

With an emulated device, the guest's driver writes to registers of a card that does not exist. Each write traps into the hypervisor, which works out what real hardware would do and does it. That is many small round trips per packet or disk block.

With paravirtualization, the guest driver is written for a virtual device from the start. Guest and host share rings of buffers in memory, called virtqueues. The guest places a batch of requests in the ring and signals the host once; the host processes them and signals back. Fewer exits from the guest mean lower latency and less CPU used for I/O.

The Main VirtIO Devices

DeviceWhat it providesName in the guest
virtio-netNetwork cardeth0, ens3
virtio-blkDisk, one per device/dev/vda
virtio-scsiSCSI controller with disks/dev/sda
virtio-balloonMemory the host can reclaimNo device file
virtio-rngRandom numbers from the host/dev/hwrng
virtio-serialChannel for a guest agentA port device

The network name depends on the system's naming rules, not on VirtIO.

virtio-blk vs virtio-scsi

virtio-blk is the simpler path: each disk is its own device, named vda, vdb, and so on, which is why many virtual servers have /dev/vda instead of /dev/sda. virtio-scsi puts a virtual SCSI controller in the guest, which can carry many disks and passes SCSI commands through. With it, disks appear as sda, sdb. Both can pass discard requests (on virtio-blk with Linux 5.0 or later), so fstrim can return unused blocks to the host's storage, but only when discard is enabled for the disk on the host.

The Memory Balloon

The balloon driver lets the host ask the guest for memory back. The driver allocates memory inside the guest so that the guest stops using it, and the host can then give those pages to others. The guest's total memory as shown by free can change while the balloon is inflated. Not every host uses it.

Check VirtIO Inside a Linux Guest

lspci | grep -i virtio
lsblk
ls /sys/bus/virtio/drivers/

lspci lists the virtual PCI devices; VirtIO ones have Virtio in their description. lsblk shows vda for virtio-blk disks. The last command lists the VirtIO drivers registered in the running kernel, such as virtio_blk, virtio_net, and virtio_balloon.

lsmod | grep virtio
ethtool -i eth0

lsmod shows VirtIO drivers loaded as modules. If it prints nothing while the devices work, the drivers are built into the kernel rather than loaded as modules. ethtool -i prints driver: virtio_net for a VirtIO network card; use your interface name from ip link.

Linux Has the Drivers Built In

The VirtIO drivers have been part of the mainline Linux kernel for many years, and every current release of Ubuntu, Debian, AlmaLinux, and Rocky Linux includes them in the kernel and the initramfs. There is nothing to install for disks and networking. For a guest agent, which lets the host freeze file systems before a snapshot or read the guest's addresses, install qemu-guest-agent with apt or dnf; it also needs a matching channel on the host side.

On Your Own KVM Host

If you run your own host, choose VirtIO when you define a Linux guest. With virt-install, the disk option takes bus=virtio and the network option takes model=virtio. Host setup is in how to install KVM on Ubuntu and how to install Proxmox VE. To see whether the disk is the limit inside a guest, use the tools in how to check disk I/O in Linux.

Was this answer helpful?
Loading...