I have a relatively fresh Arch Linux install on my new laptop (Huawei Matebook X Pro 2019) and I didn't want to install VirtualBox or anything like that on it again, so I figured now was the time to actually learn out to setup a KVM VM with the underlying tools.
The following is how I went about creating and running a VM with just the command line tools for libvirt, qemu, etc.
First one must create a disk image for the OS to install into. The following command will create a qcow2 image of the size 15GB.
sudo qemu-img create -o preallocation=metadata -f qcow2 /var/lib/libvirt/images/test1.qcow2 15G
Next we want to start an installation with a given .iso file.
Before I could successfully start an installation, however, it required me to create some sort of networking adapter for the VM.
I decided to go for a simple bridge setup. Notes on creating it can be found here.
sudo virt-install --virt-type kvm --name ubuntu2010 --ram 2048 \ --disk /var/lib/libvirt/images/test1.qcow2,format=qcow2 \ --network bridge=vtbr10 \ --graphics vnc,listen=0.0.0.0 \ --os-type=linux --os-variant=ubuntu20.04 \ --cdrom=/opt/images/ubuntu-20.10-beta-desktop-amd64.iso
There are many flags for
virt-install, so I won't go over all of them here, but you can view its man page either on your system if you have it installed, or online here
Finally, these VMs can be started and stopped through