4.2 Linux Hypervisors, KVM/QEMU, VirtIO & Virtual Machine Lifecycle
Key Takeaways
The Linux KVM interface provides hardware-assisted virtualization. QEMU supplies the guest machine and device model and can use KVM when available.
SVM and VMX identify AMD and Intel x86 virtualization support in Linux. Check host access and exposed guest capabilities before assuming acceleration or nesting works.
VirtIO devices use cooperating guest drivers. Confirm boot-critical drivers and the actual network and storage devices.
Use qemu-img for unused images and inspect both virtual capacity and host allocation. Use the management layer for supported live changes.
A controlled VM stop, clone, migration and snapshot address different tasks. Validate guest state, storage dependencies and network behavior after changes.
4.2 Linux Hypervisors, KVM/QEMU, VirtIO & Virtual Machine Lifecycle
A virtual machine has virtual CPUs, memory, storage and interfaces, and it boots a guest operating system. A bare-metal Linux installation runs on the hardware directly. Virtualization lets guests share physical resources, so an administrator monitors both guest behavior and the resource limits, policies, and backing devices on the host.
Hypervisors and the KVM/QEMU split
A bare-metal hypervisor is integrated with the system layer that controls hardware access for guests. A hosted hypervisor uses a general-purpose host OS. KVM is integrated into Linux, so the Linux kernel supplies the virtualization component on a KVM host. QEMU and management tools still run as user-space processes. The labels are useful architectural descriptions. For troubleshooting, identify which component controls the operation in question.
| Component | Role |
|---|---|
| KVM (Kernel-based Virtual Machine) | The Linux kernel interface for hardware-assisted virtualization on supported architectures. User-space programs use /dev/kvm to configure a virtual machine and run virtual CPUs. |
| QEMU | Provides the guest's machine and virtual devices. It can use KVM where available, or use its software translation accelerator (TCG) on supported configurations. |
| libvirt | Manages guests, networks and storage through a driver and management API. virsh uses that API for commands; it is not the CPU accelerator. |
On x86, Linux commonly exposes Intel hardware virtualization as the vmx flag and AMD hardware virtualization as svm. Check the host visible to the workload:
grep -E -m 1 '(^|[[:space:]])(vmx|svm)([[:space:]]|$)' /proc/cpuinfo
ls -l /dev/kvm
A reported CPU feature is only one check. Confirm firmware settings, device access, the installed platform, and the permissions of the process that starts the guest. A nested setup runs an inner hypervisor inside a guest. On x86 KVM, support depends on host parameters and the outer VM's CPU configuration. The relevant virtual CPU extension needs to be exposed to the outer guest; a host-side setting alone is insufficient.
Paravirtualized devices and VirtIO
QEMU can emulate familiar hardware, which can be useful with a guest that lacks virtual device drivers. VirtIO defines virtual device interfaces. A guest driver can submit requests and receive completions via virtqueues, giving the implementations ways to reduce device-emulation overhead. Performance still depends on the backend, workload and configuration.
| Device | What you may see in a Linux guest |
|---|---|
| VirtIO network | virtio_net drives the virtual interface. |
| VirtIO block | virtio_blk commonly exposes disk names such as /dev/vda. |
| VirtIO SCSI | virtio_scsi presents guest storage through a virtual SCSI controller. |
| VirtIO balloon | A cooperative driver can make guest pages available to the host or return pages according to the balloon target. It is distinct from changing the configured memory maximum. |
When switching the boot disk to a different virtual controller, verify the corresponding guest driver is available at early boot. Use guest tools such as lsblk and lspci -k to confirm what the guest sees and what is bound. As with other kernel drivers, built-in support need not appear in lsmod.
Virtual disk formats and offline image operations
Virtual storage may come from a host file, logical volume or network-backed device. A raw file is a direct representation of the virtual disk bytes and can be sparse on a suitable filesystem. A qcow2 image stores metadata and has features such as sparse allocation, backing files, and snapshot capabilities where supported. A 50 GiB virtual disk may occupy far less than 50 GiB on the host, but the host still needs space as the guest writes. Monitor both capacities.
For an inactive, unused set of lab images and a new output file:
qemu-img info -f raw lab-source.raw
qemu-img convert -f raw -O qcow2 -c lab-source.raw lab-copy.qcow2
qemu-img info -f qcow2 lab-copy.qcow2
qemu-img check -f qcow2 lab-copy.qcow2
convert copies disk contents into another format. -O qcow2 selects the output and -c requests compressed output for that format. The created file's actual allocation depends on the data and runtime writes. qemu-img check checks the container's consistency where the format supports it. A consistent image can still contain a damaged guest filesystem.
qemu-img resize -f qcow2 lab-copy.qcow2 +20G grows the logical size of an unused image by 20 GiB. Avoid running offline image-modification commands on any in-use image. For a live change that the hypervisor and storage support, coordinate with the management layer, for example libvirt's blockresize. Confirm that the guest detects the new device size, then adjust partitions, LVM and filesystems as applicable using their own rules.
Guest resources, networking and lifecycle
Inspect the host definition and guest's actual resources. The virtual CPU count is not proof that the guest gets exclusive physical cores. CPU pinning constrains placement. Configured memory and a balloon target describe different limits or states. Check virtual disk allocation separately from its capacity, and inspect the virtual NIC's link and network attachment.
| Networking mode | Typical behavior |
|---|---|
| NAT | The libvirt host translates guest IPv4 traffic sent upstream. IPv6 uses plain routing unless IPv6 NAT is explicitly enabled on a supported libvirt release. Inbound reachability depends on routing and firewall configuration. |
| Bridged | Connects the guest interface to a bridge, which can place it on the connected network segment. Addressing and access policy still apply. |
| Host-only or isolated virtual network | Allows local guest and host communication according to configuration. Libvirt configures no upstream forwarding for the network. |
| Routed | Forwards through the host without source NAT in the ordinary routed configuration. The upstream network needs a route back to the guest subnet. |
| Open | Uses host routing and requires an upstream return route. Libvirt installs no network firewall rules for this mode. Apply the required access policy separately. |
The virt-manager desktop client can create guests, change resource assignments and open a guest console through libvirt. For scriptable inspection, virsh list --all, virsh domstate webserver01, and virsh dominfo webserver01 distinguish configured and active guests. A running guest differs from a paused guest with execution suspended, or a shut-off guest with no VM instance running. Use virsh dumpxml to inspect a supported domain definition, and edit through the management API instead of directly changing the daemon's files.
virsh start webserver01 boots a defined inactive VM. virsh shutdown webserver01 requests a guest shutdown and depends on guest support and mode. Confirm the resulting state. virsh destroy forces an active domain to stop without orderly guest shutdown. Guest data or in-flight writes can be lost. It does not itself delete the persistent disk image. Undefining a domain changes its persistent definition and is a separate operation.
Templates, cloning, migration and snapshots
A baseline image can save repeated installations. Keep the base protected and versioned. Clone through a full independent copy or a supported copy-on-write overlay, and track a linked clone's base dependency. Verify each clone gets the intended network address, machine identity and credentials through the guest's provisioning procedure. For example, virt-clone can copy the source guest's disks and configuration under a new libvirt identity, while guest-internal settings may still require provisioning. Use virt-install to create a new guest from supported media, and choose install source and console options that work together.
A snapshot records a point in time for specified VM state. It may be disk-only or include memory, depending on the configuration and tool. Use virsh snapshot-list and virsh snapshot-info to inspect managed snapshots. A snapshot can be suitable for a short rollback when its storage coverage and consistency are understood. An active application may need to quiesce writes for application-consistent recovery. Snapshots share dependencies with the original storage; keep an independent backup.
Migration moves an existing guest instead of creating another identity. Offline and live migration have different disruption and compatibility requirements. Before a live migration, verify CPU compatibility, destination memory and network mappings, and whether disks are shared or require a supported storage copy. After the move, check the destination VM's state and application traffic. A "live" migration can still have a short pause or fail if prerequisites are unmet.
A Linux host on AMD x86 exposes its hardware virtualization feature in /proc/cpuinfo. Which flag identifies it?
vmx
vring
svm
virtio
A raw lab disk image at /images/database.raw is offline and unused. Which command copies its contents into a new qcow2 image with compressed output?
qemu-img convert -f raw -O qcow2 -c /images/database.raw /images/database.qcow2
qemu-img create -f qcow2 /images/database.qcow2 100G
qemu-img resize /images/database.raw +100G
qemu-img info /images/database.raw
A libvirt guest named app-cluster02 is still active, will not shut down normally, and an authorized incident decision requires an abrupt stop. The persistent definition and disks should remain. Which command performs the stop?
virsh undefine app-cluster02
virsh dominfo app-cluster02
virsh snapshot-list app-cluster02
virsh destroy app-cluster02
Sections you finish are checked off in the contents.