Comprehensive Guide: Installing and Configuring Virtual Machines in Arch Linux
Virtualization on Arch Linux provides a powerful, native, and highly performant environment for running guest operating systems. By leveraging the Kernel-based Virtual Machine (KVM) module built into the Linux kernel, along with QEMU for hardware emulation and virt-manager for a graphical interface, users can achieve near-native performance for their virtual machines. This guide provides a complete, step-by-step walkthrough for installing, configuring, and optimizing a complete virtual machine manager setup on Arch Linux.
Prerequisites and Hardware Support
Before beginning the installation process, it is essential to verify that the host system’s processor supports hardware virtualization. This feature is known as VT-x for Intel processors and AMD-V for AMD processors. Hardware virtualization allows the hypervisor to execute guest instructions directly on the host CPU, significantly improving performance.
To check for hardware virtualization support, execute the following command in the terminal:
LC_ALL=C.UTF-8 lscpu | grep Virtualization
If the output displays VT-x or AMD-V, the processor supports hardware virtualization. If the command returns no output, virtualization may be disabled in the system’s BIOS or UEFI settings, and must be enabled before proceeding.
Additionally, ensure that the Arch Linux kernel includes the necessary KVM modules. These modules are typically included by default. Verify their presence with:
zgrep CONFIG_KVM /proc/config.gz
The output should indicate CONFIG_KVM=y or CONFIG_KVM=m. Finally, confirm that the modules are loaded:
lsmod | grep kvm
This should list kvm along with either kvm_intel or kvm_amd.
Package Installation
A complete virtualization environment requires several interconnected components. Arch Linux provides these through its official repositories. The following packages form the core of the setup:
| Package | Description |
|---|---|
| qemu-full | The complete QEMU suite, providing full-system emulation for all supported architectures, including GUI components. Alternatively, qemu-desktop can be used for x86_64 emulation only. |
| libvirt | An open-source API, daemon, and management tool for platform virtualization. It serves as the bridge between the user interface and the hypervisor. |
| virt-manager | A graphical user interface for managing virtual machines via libvirt. |
| virt-viewer | A lightweight graphical console for connecting to the displays of running virtual machines. |
| dnsmasq | A lightweight DNS forwarder and DHCP server, required for libvirt’s default NAT networking. |
| edk2-ovmf | Provides UEFI firmware support for virtual machines, essential for modern guest operating systems. |
| swtpm | A software emulator for Trusted Platform Modules (TPM), required for installing operating systems like Windows 11. |
| guestfs-tools | A set of extended command-line tools for managing and modifying virtual machine disk images. |
To install all necessary packages, execute the following command:
sudo pacman -S qemu-full libvirt virt-manager virt-viewer dnsmasq edk2-ovmf swtpm guestfs-tools
Daemon Configuration and Service Management
The libvirt package provides the background services necessary to manage virtual machines. Historically, libvirt used a single monolithic daemon (libvirtd). However, modern setups favor a modular approach, where individual daemons handle specific virtualization drivers. This modular architecture improves stability and security.
To enable and start the modular libvirt daemons, execute the following loop:
for drv in qemu interface network nodedev nwfilter secret storage; do
sudo systemctl enable --now virt${drv}d.service
sudo systemctl enable --now virt${drv}d{,-ro,-admin}.socket
done
Alternatively, if the traditional monolithic daemon is preferred, it can be enabled with:
sudo systemctl enable --now libvirtd.service
User Permissions
By default, managing virtual machines through the system connection (qemu:///system) requires root privileges. To allow a standard user to manage virtual machines without entering a password or using sudo, the user must be added to the libvirt group.
Execute the following command, replacing $USER with the actual username if necessary:
sudo usermod -aG libvirt $USER
For this change to take effect, the user must log out and log back in, or the system can be rebooted.
Network Configuration
Virtual machines require network access to communicate with the host and the internet. Libvirt provides a default NAT (Network Address Translation) network, which routes guest traffic through the host’s IP address.
To ensure the default network starts automatically when the system boots, and to start it immediately, execute the following commands:
sudo virsh net-autostart default
sudo virsh net-start default
This configuration creates a virtual bridge interface, typically named virbr0, and uses dnsmasq to assign IP addresses to the guest machines.
Advanced Configuration and Optimization
For users seeking maximum performance or specific features, several advanced configurations can be applied.
Nested Virtualization
Nested virtualization allows a virtual machine to act as a hypervisor and run its own virtual machines. This is particularly useful for testing and development environments.
To enable nested virtualization persistently, create a configuration file in /etc/modprobe.d/.
For Intel processors:
echo "options kvm_intel nested=1" | sudo tee /etc/modprobe.d/kvm-intel.conf
For AMD processors:
echo "options kvm_amd nested=1" | sudo tee /etc/modprobe.d/kvm-amd.conf
IOMMU and PCI Passthrough
IOMMU (Input-Output Memory Management Unit) is required for PCI passthrough, a technique that allows a virtual machine to take direct, exclusive control of a physical hardware device, such as a dedicated graphics card (GPU). This is essential for achieving near-native gaming performance in a Windows guest.
To enable IOMMU, the kernel parameters must be modified in the bootloader configuration.
For the GRUB bootloader, edit /etc/default/grub and append the appropriate parameters to the GRUB_CMDLINE_LINUX_DEFAULT line:
- Intel:
intel_iommu=on iommu=pt - AMD:
amd_iommu=on iommu=pt
After modifying the file, regenerate the GRUB configuration:
sudo grub-mkconfig -o /boot/grub/grub.cfg
A system reboot is required for these changes to take effect.
Creating the First Virtual Machine
With the environment fully configured, virt-manager can be used to create and manage virtual machines.
- Launch Virtual Machine Manager from the application menu.
- Go to File > Add Connection. Ensure the Hypervisor is set to
QEMU/KVMand the connection is set toSystem. - Click the Create a new virtual machine icon.
- Select the installation media (e.g., a downloaded ISO file).
- Allocate memory (RAM) and CPU cores. It is generally recommended to leave at least 2 cores and sufficient RAM for the host system.
- Create a virtual disk image. The default
qcow2format is recommended as it supports snapshots and dynamic allocation. - Before finalizing the creation, check the box labeled Customize configuration before install.
- In the customization window, navigate to the Overview section. If installing a modern OS, change the Firmware to
UEFI. - Begin the installation process.
By following this comprehensive guide, users can establish a robust, high-performance virtualization environment on Arch Linux, capable of handling everything from simple testing to demanding, hardware-accelerated workloads.