How to Install KVM in Arch Linux and Configure Virtual Machine
Setting up a new virtual machine on Arch Linux using KVM and QEMU can seem daunting. But fret not, as it will be very easy to learn how to do it.
Want to run different operating systems on your Arch Linux installation? You can always use VirtualBox or VMware to create virtual machines, but KVM has the upper hand with its high performance and flexible feature set.
At first, setting up a new virtual machine on Arch Linux using KVM and QEMU can seem daunting. But fret not, as it will be very easy to learn how to do it.
Here's everything you need to know about installing KVM in Arch Linux and configuring your first virtual machine.
Step 1: Check if virtualization is enabled
The first step is to verify that you have enabled virtualization support on your computer. To do so, run the following command:
grep -Ec '(vmx|svm)' /proc/cpuinfo
Note the output. If it is greater than 0, then virtualization is enabled and you can safely continue. But in case this has not been done, you need to enable virtualization by accessing the BIOS of your computer.
Step 2: Install the necessary KVM packages
Now that you are sure about virtualization support, it's time to install the necessary packages for KVM. But first, update the existing packages on your system using:
sudo pacman -Syyu
Then run the following command to install all KVM related packages:
sudo pacman -S qemu-full virt-manager virt-viewer dnsmasq bridge-utils libguestfs ebtables vde2 openbsd-netcat
Enter Y when prompted for confirmation.
Step 3: Configure the libvirtd . service
Start the libvirtd service with:
sudo systemctl start libvirtd.service
Enable the service so that it automatically starts at boot:
sudo systemctl enable libvirtd.service
Check if libvirtd is currently running with the status command :
sudo systemctl status libvirtd.service
The output will show active (running) status in green. If it shows inactive (dead) , execute the systemctl start command again.
Next, you need to make some changes to the libvirtd configuration file located at /etc/libvirt/libvirtd.conf. Open the file with Vim (or your favorite text editor):
vim /etc/libvirt/libvirtd.conf
Locate and uncomment the following two lines by removing the # character from the beginning:
unix_sock_group = "libvirt" unix_sock_rw_perms = "0770"
Save changes and exit Vim to continue. Next, add your user to the libvirt group with:
sudo usermod -aG libvirt $USER
Restart the libvirtd service to save the changes:
systemctl restart libvirtd.service
You are now ready to create a KVM on your Arch Linux system. There are two ways to do it: Using the QEMU CLI or with virt-manager, which is a graphical user interface for QEMU/KVM. The choice depends on you!
But before that, make sure that you have downloaded the ISO image for the operating system you want to install. If you're still undecided, check out this list of the best Linux distributions for beginner, intermediate, and advanced users.
Create a new KVM on Arch Linux using virt-manager
If you are a beginner or don't want to deal with Linux terminal, the best way to create KVM on Arch Linux is to use virt-manager. It's easy to use and has a clean interface, similar to other GUI hypervisors like VirtualBox and VMware.
Start by launching virt-manager. Normally, it will appear as Virtual Machine Manager in the application menu, but you can also run the virt-manager command in the terminal to launch it.
When it launches, click Create a new virtual machine (just below the File option ). Select Local media install (ISO image or CDROM) and click Forward.
On the next screen, click Browse > Browse Local and select the downloaded ISO file. For this tutorial, install Manjaro, an Arch-based Linux distribution that has removed the complicated installation that Arch is famous for. With the file selected, click Forward.
If you see a prompt mentioning that the emulator may not have permission to search the path, just click Yes to continue.
Select the memory size and CPU cores for the virtual machine. In terms of memory, a quarter of actual physical memory is a good starting point.
For example, if you have 8GB of memory, anything between 2GB and 4GB will work. For CPU, enter the number of available cores (in this case 12). Click Forward to continue.
Next, configure the size of the KVM. 25GB would be more than enough to install Manjaro barebones or any other distro for that matter. Again, continue by clicking Forward.
Review the KVM information and click Finish if everything is fine. If you see a pop-up window Virtual Network is not active , select Yes to start the network.
virt-manager will start creating the KVM and as soon as it's done, a new virtual machine window will appear.
New KVM Configuration on Arch Linux Using QEMU CLI
To create a KVM on Arch Linux from the command line, you can use the qemu commands. To get started, first create a separate folder for the virtual machine and move the downloaded OS ISO file into the newly created folder:
mkdir kvm mv /path/to/linux-distro.iso ./kvm
Then create a 20G image file that will store KVM's data:
qemu-img create -f qcow2 Image.img 20G
Proceed by running the following command to start the virtual machine:
qemu-system-x86_64 -enable-kvm -cdrom linux-distro.iso -boot menu=on -drive file=Image.img -m 4G -cpu host -vga virtio -display sdl,gl=on
Make sure to replace linux-distro.iso in the above command with the correct file name and path. You can also change the value of the -m flag to configure how much memory you want to allocate to KVM.
A new virtual machine window will appear. Please check or install the operating system.
After installing the operating system to the image file, you do not need the -cdrom flag in the above command, because you will not be booting from the ISO file anymore. Instead, run:
qemu-system-x86_64 -enable-kvm -boot menu=on -drive file=Image.img -m 4G -cpu host -vga virtio -display sdl,gl=on
You can shorten the above command by creating a command line alias for it.
You should read it
- Should I install Arch Linux?
- Instructions for installing basic Arch Linux
- How to install Arch Linux on Raspberry Pi
- How to Update Arch Linux
- How to Install Gnome on Arch Linux
- 5 distributions based on the best Arch Linux
- Arch Linux for WSL is now available in Microsoft Store
- Is Arch Linux better than Ubuntu?
- How to Install Arch Linux
- How to install and use yay on Arch Linux
- How to set up XFCE desktop environment on Arch Linux
- How to install Snap application in Arch Linux
Maybe you are interested
How to enable parallel download in browser How to Save on Security Software Without Compromising Quality How to turn an old router into a switch What does Hangover mean? In what circumstances? How to use Calendo to create an appointment on Windows 10 Top 11 reasons why we are getting a little bit more