Setting up virtual machines
Virtual machines are an incredibly useful tool both to developers, in order to test their applications on clean systems, and to users, to run applications only available for other operating systems.
To begin, install the libvirt
, virt-manager
, virt-manager-tools
and qemu
packages:
sudo xbps-install libvirt virt-manager virt-manager-tools qemu
Enable the libvirtd
, virtlockd
and virtlogd
services:
sudo ln -s /etc/sv/libvirtd /var/service
sudo ln -s /etc/sv/virtlockd /var/service
sudo ln -s /etc/sv/virtlogd /var/service
Lastly, add yourself to the libvirt
and kvm
groups:
sudo usermod -a -G libvirt,kvm <USER>
Creating a virtual machine
Open Virtual Machine Manager and press on the computer icon directly below "File" to create a new virtual machine. Set up the parameters to your liking; do consider giving a decent amount of RAM and CPU cores to your OS.
After creating the virtual machine, it will open up and run the ISO image you selected. Just install the OS as you normally would.
VirtIO for Windows
For Windows guests, you might want to install the VirtIO drivers for improved performance and integration.
First, download the VirtIO Drivers ISO.
Inside the open VM, press on the lightbulb on the toolbar to open hardware details, then go to "SATA CDROM 1".
In "Source path", press "Browse" and select the drivers ISO. This will load the ISO as a CDROM. Afterwards simply run the "virtio-win-gt-arch" and "virtio-win-guest-tools" found inside the CDROM in the Windows VM.
You can now optionally switch to using SCSI for I/O, which significantly improves virtual disk performance.
Shutdown the virtual machine and go back to hardware details.
Click "Add Hardware", select "Controller" and add a controller of type "SCSI" and model "VirtIO SCSI".
Click "Add Hardware" again, this time add "Storage" with bus type "SCSI", any size. We won't really use the disk, we just need it attached.
Boot the machine again. Check or wait until Windows' Device Manager shows the SCSI disk is detected (should appear as "QEMU QEMU HARDDISK SCSI Disk Device").
Shutdown the machine, then detach and delete the temporary SCSI disk you added in step 6. Afterwards, detach the SATA disk and reattach it as an SCSI disk.
You can also optionally switch the NIC interface in hardware details to "virtio", similarly increasing performance for network I/O.
If your connection goes out after making the change, see below.
Troubleshooting
Sometimes VM starts without an internet connection
There's a randomly occurring bug with either libvirt or virt-manager where it seems to fail to enable the virtual network and bridge devices. You can confirm this by running:
ip link
If the VM is running but virbr0
and vnet0
are set to DOWN
, then it bugged out.
You can either shut down and start the virtual machine again to fix it, or manually set the devices to UP
with:
sudo ip link set up virbr0
sudo ip link set up vnet0