Lightweight Linux Hypervisor
There is a variaty of options and tools to provision VMs on linux, I personally prefer this method over installing other hypervisors like: vmware or virtualbox, because they are really bloated, and heavy softwares and it's a bit hard to set up on linux, especially if you are using a DIY distros like arch or gentoo. Instead we are going to use kvm
which is a kernel based VM, qemu
which is quick emulator that will interact with kvm, libvirt
a lib that exports apis to interact with qemu/kvm, finally the GUI interface virt-manager
wich we will be using most of the time to set up and start our VMs.
1. Installation
First we need to install the required utilities:
pacman -Sy --needed \
qemu \
dhclient \
virt-viewer \
libvirt \
dnsmasq \
dmidecode \
ebtables \
virt-install \
virt-manager \
bridge-utils
we don't need to install kvm because it is part of the kernel.
2. Permissions
Communication between virt-manager
and libvirt
is going through polkit, When using qemu:///system. So you need to have the correct privileges.
P.S: Polkit provides an organized way for non-privileged processes to communicate with privileged ones.
to have permission you need to edit /etc/polkit-1/rules.d/50-libvirt.rules
/* Allow users in wheel group to manage the libvirt
daemon without authentication */
polkit.addRule(function(action, subject) {
if (action.id == "org.libvirt.unix.manage" &&
subject.isInGroup("wheel")) {
return polkit.Result.YES;
}
});
the restart polkit:
doas systemctl restart polkit
now polkit will allow access for wheel group, so you should add yourself to it:
doas usermod -aG wheel `id -u`
3. Usage
you should be ready now, first we need to start libvirtd:
doas systemctl start libvirtd
finally you can start the gui:
virt-manager
the interface is clear enough if you ever setup a VM before.
if you don't like gui you can use a cli:
virt-install \
--name archlinux \
--ram 2048 \
--disk path=/var/lib/libvirt/images/arch.qcow2,size=8 \
--vcpus 2 \
--os-type linux \
--os-variant generic \
--console pty,target_type=serial \
--cdrom ~/storage/archlinux-2020.09.01-x86_64.iso
BTW you can find all your VMs images in /var/lib/libvirt/images
.
to clone existing VM you can use virt-clone
:
virt-clone \
--original arch \
--name arch-clone \
--file /var/lib/libvirt/images/arch_clone.qcow2