KVM (Kernel-based Virtual Machine) is an open-source virtualization technology that turns Linux into a hypervisor, allowing multiple guest operating systems to run concurrently on a single host. In this blog post, we’ll walk you through the process of how to set up KVM virtualization on Arch Linux.
Table of Contents
- Installing KVM and Required Packages
- Configuring Networking
- Creating a Virtual Machine
- Managing Virtual Machines with Virt-Manager
How to Set up KVM Virtualization on Arch Linux
Before we get started, ensure that your system meets the following requirements:
- Arch Linux installed and up-to-date.
- A CPU with hardware virtualization support (Intel VT-x or AMD-V).
- Sufficient disk space and memory for running virtual machines.
To check if your CPU supports hardware virtualization, run the following command:
grep -E 'vmx|svm' /proc/cpuinfo
If you see
vmx (for Intel) or
svm (for AMD) in the output, your CPU supports virtualization. If not, you’ll need to enable it in your BIOS/UEFI settings.
You should also ensure your Arch Linux system is up-to-date by running:
sudo pacman -Syu
Installing KVM and Required Packages on Arch Linux
First, we need to install KVM and the required packages. To do this, run the following command:
sudo pacman -S qemu virt-manager virt-viewer dnsmasq vde2 bridge-utils openbsd-netcat
This will install the following packages:
- qemu: The QEMU emulator and KVM support.
- virt-manager: A graphical management tool for virtual machines.
- virt-viewer: A viewer application for virtual machines.
- dnsmasq: A lightweight DHCP and DNS server.
- vde2: A virtual distributed ethernet switch.
- bridge-utils: Utilities for configuring Linux ethernet bridges.
- openbsd-netcat: The OpenBSD netcat implementation.
Next, enable and start the
sudo systemctl enable libvirtd.service sudo systemctl start libvirtd.service
Verify the installation by checking the KVM version:
You should see the QEMU emulator version as output.
Configuring Networking on Arch Linux
KVM uses a virtual network switch called
virbr0 by default, which provides NAT-based networking to virtual machines. However, for better performance and flexibility, we’ll create a network bridge.
- Install the
bridge-utilspackage if you haven’t already:bash
sudo pacman -S bridge-utils
/etc/systemd/network/br0.netdev file and add the following content:
[NetDev] Name=br0 Kind=bridge
/etc/systemd/network/br0.network file and add the following content, adjusting the
DNS values to match your network configuration:
[Match] Name=br0 [Network] Address=192.168.1.100/24 Gateway=192.168.1.1 DNS=188.8.131.52 DNS=184.108.40.206
Save and close the file, then restart the systemd-networkd service to apply the changes:
sudo systemctl restart systemd-networkd
Configure the Virtual Machines on KVM
Now it’s time to create and configure the virtual machines. You can use the
virt-install command to create new virtual machines. Here’s an example of creating a new VM with 2 CPU cores, 4GB of RAM, and a 40GB disk:
sudo virt-install --name=myvm --vcpus=2 --memory=4096 --cdrom=/path/to/your/iso/file.iso --disk size=40 --os-type=linux --os-variant=generic --graphics spice --network bridge=br0
/path/to/your/iso/file.iso with the path to the ISO file for your desired guest operating system. The
--os-variant options allow you to specify the type and variant of the guest OS. You can find a list of supported OS types and variants in the official libvirt documentation.
Manage Virtual Machines with
virsh command is a powerful tool for managing virtual machines created with KVM. Here are some useful commands:
- List all VMs:css
virsh list --all
Start a VM:
virsh start myvm
Shut down a VM:
virsh shutdown myvm
Pause a VM:
virsh suspend myvm
Resume a paused VM:
virsh resume myvm
Delete a VM:
virsh undefine myvm
Note that this command will only delete the VM configuration, not the associated disk images. To delete the disk images as well, use the
virsh undefine myvm --remove-all-storage
Install Virt-Manager (Optional)
If you prefer a graphical user interface to manage your virtual machines, you can install Virt-Manager:
sudo pacman -S virt-manager
Once installed, run
virt-manager from the terminal or find it in your applications menu. It provides a convenient way to create, manage, and monitor your virtual machines.
You have successfully set up KVM virtualization on your Arch Linux system. With KVM, you can run multiple virtual machines with different operating systems on a single host, which can be useful for testing, development, or server consolidation. For more advanced configurations, you may want to explore other virtualization tools and learn about additional security measures to protect your virtualized environment.