How to Install and Use QEMU/KVM on Arch Linux
Categories:
6 minute read
QEMU (Quick Emulator) and KVM (Kernel-based Virtual Machine) together offer a powerful and efficient virtualization solution for Linux users. On Arch Linux—a minimalist, bleeding-edge distribution tailored for advanced users—setting up QEMU/KVM can unlock a world of possibilities, from testing different OS environments to building complex virtual labs.
This guide walks you through installing and using QEMU/KVM on Arch Linux, covering installation, configuration, and practical usage with virt-manager for convenience.
Introduction to QEMU and KVM
QEMU is a generic and open-source machine emulator and virtualizer. When used as a virtualizer, it achieves near-native performance by executing guest code directly on the host CPU using the KVM kernel module.
KVM turns your Linux machine into a Type 1 hypervisor by leveraging hardware virtualization extensions such as Intel VT-x or AMD-V. It is built into the Linux kernel and requires minimal setup.
Together, QEMU and KVM allow users to create and run virtual machines with good performance, support for a wide range of guest operating systems, and integration with graphical tools like virt-manager.
Prerequisites
Before jumping into installation, make sure your system supports hardware virtualization:
1. Check for Virtualization Support
Open a terminal and run:
lscpu | grep Virtualization
You should see VT-x
for Intel or AMD-V
for AMD CPUs.
Alternatively, check for the presence of the vmx
or svm
flags:
egrep -c '(vmx|svm)' /proc/cpuinfo
If the result is greater than 0, your CPU supports virtualization.
2. Enable Virtualization in BIOS/UEFI
Reboot your system and enter the BIOS/UEFI settings. Look for options like “Intel Virtualization Technology” or “SVM Mode” and ensure they are enabled.
Installing QEMU, KVM, and Virt-Manager
Arch Linux makes it simple to install the necessary packages via the pacman
package manager.
1. Update Your System
sudo pacman -Syu
2. Install Required Packages
Run the following to install QEMU, KVM, and management tools:
sudo pacman -S qemu virt-manager virt-viewer dnsmasq vde2 bridge-utils openbsd-netcat
These packages include:
qemu
: The main QEMU emulator.virt-manager
: A graphical tool for managing virtual machines.virt-viewer
: A simple viewer for virtual machines.dnsmasq
: Provides DHCP and DNS services to VMs.vde2
,bridge-utils
,openbsd-netcat
: Network bridging utilities.
3. Enable Required Services
Enable and start libvirtd
:
sudo systemctl enable --now libvirtd
Verify the service is active:
systemctl status libvirtd
4. Add Your User to the libvirt
and kvm
Groups
To run virtual machines without root:
sudo usermod -aG libvirt,kvm $(whoami)
After this, log out and back in to apply group changes.
Configuring Virtualization Environment
Once installed, it’s good to verify and configure your virtualization environment.
1. Check KVM Modules
Run:
lsmod | grep kvm
You should see either kvm_intel
or kvm_amd
depending on your CPU.
If not loaded, you can load the modules manually:
sudo modprobe kvm
sudo modprobe kvm_intel # For Intel
# or
sudo modprobe kvm_amd # For AMD
To ensure these modules are loaded at boot, add them to /etc/modules-load.d/kvm.conf
:
echo -e "kvm\nkvm_intel" | sudo tee /etc/modules-load.d/kvm.conf
# or for AMD:
# echo -e "kvm\nkvm_amd" | sudo tee /etc/modules-load.d/kvm.conf
2. Verify libvirt Networking
Check that the default virtual network is available and active:
virsh net-list --all
If inactive, activate it:
virsh net-start default
virsh net-autostart default
Creating and Managing VMs with Virt-Manager
virt-manager is a graphical interface that makes managing VMs significantly easier.
1. Launch Virt-Manager
Run:
virt-manager
You’ll see a clean interface where you can add and manage virtual machines.
2. Create a New VM
Steps:
- Click the “Create a new virtual machine” button.
- Choose how to install the OS:
- Local ISO
- Network install
- PXE boot
- Import existing disk image
- Select the ISO or path to your installation medium.
- Assign CPU and memory resources.
- Create or select a virtual disk.
- Configure network (default NAT or custom bridge).
- Review settings and click Finish to start the VM.
3. Accessing and Using VMs
Use virt-viewer or the built-in viewer to interact with your VMs. You can pause, reboot, snapshot, and clone VMs from the virt-manager interface.
Using QEMU from the Command Line
While virt-manager
is great, QEMU also supports a rich command-line interface for advanced use cases.
Here’s a simple example of running an Ubuntu ISO:
qemu-system-x86_64 \
-enable-kvm \
-m 2048 \
-cpu host \
-smp 2 \
-cdrom ubuntu.iso \
-boot d \
-drive file=ubuntu.qcow2,format=qcow2 \
-net nic -net user \
-name "Ubuntu Test VM"
Explanation:
-enable-kvm
: Enables hardware acceleration.-m 2048
: Allocates 2GB RAM.-cpu host
: Uses host CPU model.-smp 2
: 2 CPU cores.-cdrom ubuntu.iso
: Installation media.-boot d
: Boot from the CDROM.-drive
: Disk image.-net
: Basic user-mode network.
You can create disk images using:
qemu-img create -f qcow2 ubuntu.qcow2 20G
Optional: Configuring Bridged Networking
By default, libvirt provides NAT networking. For more advanced use (e.g., VMs with IPs accessible from LAN), you can set up bridged networking.
1. Install Required Packages
sudo pacman -S bridge-utils
2. Configure Bridge (Netplan/NetworkManager/systemd-networkd)
If you use NetworkManager, create a bridge like so:
nmcli connection add type bridge autoconnect yes con-name br0 ifname br0
nmcli connection add type ethernet slave-type bridge autoconnect yes con-name bridge-slave ifname enp2s0 master br0
nmcli connection up br0
3. Define and Use Bridge in Virt-Manager
You can now configure your VMs to use br0
instead of the default NAT network.
Managing Virtual Machines with virsh
virsh
is a command-line tool for managing VMs.
List VMs
virsh list --all
Start a VM
virsh start vmname
Shutdown a VM
virsh shutdown vmname
Delete a VM
virsh undefine vmname
Snapshot a VM
virsh snapshot-create-as --domain vmname snapshot1 "Snapshot description"
Tips and Best Practices
- Use VirtIO drivers for better performance with disk and network devices.
- Store ISO images and disk files in
/var/lib/libvirt/images/
for better organization. - Use
qcow2
disk format for features like snapshots and dynamic resizing. - Regularly update your host system and virtual tools.
Troubleshooting
libvirtd fails to start
Ensure your system has all required dependencies and no conflicting services like firewalld
blocking bridges.
VM doesn’t boot from ISO
Ensure the boot order is correct and ISO is valid. Try specifying -boot d
or checking the BIOS settings of the VM in virt-manager.
Conclusion
Installing and using QEMU/KVM on Arch Linux is a powerful way to take advantage of modern virtualization capabilities directly within your Linux environment. While it requires a bit of initial configuration, the result is a robust, flexible, and high-performance virtualization setup.
Whether you’re testing new Linux distributions, experimenting with Windows VMs, or setting up a home lab, QEMU/KVM provides the tools needed—with virt-manager offering ease of use and virsh enabling automation and scripting.
Once you’ve set everything up, the possibilities are virtually limitless.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.