KVM Virtual Machines 101

I normally advocate the use of container technologies like LXC, LXD or Docker which share the host OS kernel and are initiated from an image. Virtual machines also use images to emulate a disk drive, but the operating system is installed just like on a physical machine.

Virtual Machines have their own dedicated kernel which can be an advantage for certain applications which may require custom kernel access.

Check to make sure that your computer supports virtualization.
egrep -c '(vmx|svm)' /proc/cpuinfo

Install KVM
sudo apt install -y qemu-kvm virt-manager libvirt-daemon-system virtinst libvirt-clients bridge-utils

Enable and start Virtualization.

sudo systemctl enable --now libvirtd
sudo systemctl start libvirtd

Add your user account to virtualization groups.

sudo usermod -aG kvm $USER
sudo usermod -aG libvirt $USER

Check to see if nesting is enabled.
cat /sys/module/kvm_intel/parameters/nested

If the above command returns a “Y”, then nesting is already enabled.

To enable nesting on an Intel system.

sudo modprobe -r kvm_intel
sudo modprobe kvm_intel nested=1

To enable Nesting permanently.

sudo nano /etc/modprobe.d/kvm.conf
options kvm_intel nested=1

If you have an AMD processor, replace the instances of “intel” above with “amd”.

To create a KVM VM, use “virt-manager” as seen in the video.

To install LXD in your VM.
sudo snap install lxd

As seen in my other videos, you must initialize LXD before use.
sudo lxd init

Add your user account to the lxd group and see that it is added.

sudo usermod -aG lxd $USER
newgrp lxd

Create your first LXD container.

lxc launch ubuntu:20.04 mylxd --profile default -c boot.autostart=true

Be sure to watch my 30+ videos that discuss LXD in depth.