Let’s go virtual with KVM on Ubuntu

jimmco
3 min readNov 11, 2020

--

As developers and other IT guys, we need to have playground to build and play. We need clean playground. We need cheap playground. We need Virtual Machines.

Although I used VirtualBox from Sun, later from Oracle, why not to try KVM. KVM is Kernel Virtual Machine solution, it has friendly license, it’s very flexible and very fast. Cons is, KVM is maybe not as user friendly as VirtualBox but it’s pretty close. Also KVM is not the best for GUI demanding virtualization. But for most kind of servers, it’s great. KVM works the best on Linux, possibly even on Mac and not at all on Windows. Here, I’m using Ubuntu 20.04 based distribution (Desktop for host, Server for VM). Let’s do it in 7 very single steps. Open your console and we can start.

Step 1 — Verify if your processor can make it

egrep -c '(vmx|svm)' /proc/cpuinfo

0 — your CPU cannot make it, other number means hooray!

Step 2 — Verify if your virtualization is enabled in BIOS

Install cpu-checker utility and run kvm-ok to find out.

apt install cpu-checker
kvm-ok

If you see something like this, then you’re good.

INFO: /dev/kvm exists
KVM acceleration can be used

If you are not good, restart computer go in to BIOS and enable VM support (see you motherboard manual for specifics)

Step 3— Install KVM

apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager

Short information about these packages:

  • qemu-kvm — fast processor emulator, compatibility wrapper for kvm
  • libvirt-daemon-system — cross-product C virtualization API, libvirt daemon configuration
  • libvirt-clients — API and libvirt shell virsh and other client binaries
  • bridge-utils — utils for creating Linux Ethernet bridge(s)
  • virt-manager — desktop application for managing virtual machines

Step 4— Add current user to libvirt and kvm group

sudo usermod -aG libvirt $LOGNAME
sudo usermod -aG kvm $LOGNAME

Step 5 — Check the installation

virsh -c qemu:///system list

You should see empty list of virtual instances.

Id   Name   State
--------------------

Step 6— Create VM from Ubuntu Server 20.04 ISO

  • Download Ubuntu Server ISO https://ubuntu.com/download/server
  • Open Virtual Machine Manager
  • Click “Create New Virtual Machine”
  • Forward
  • Choose ISO or CDROM install media: Add path to the downloaded Ubuntu ISO file
  • Next and repeat until Ubuntu Virtual Machine Starts
  • Install your Virtual Machine whatever way you like and restart it.
  • Run virsh the same way you did in previous step and you should see
Id   Name          State
-----------------------------
1 ubuntu20.04 running

If you see this, then everything works as expected. Congrats! Now you can use Virtual Machine however you want.

Step 7— Adjust VM resources and settings

If you need to boost your VM up or spare some resources, shut down your VM, open Virtual Machine Manager, select your VM with right mouse and click “Open”. Now you should see all the VM settings palette. Here you can change:

  • VM name, OS information
  • Current and maximum CPU allocation
  • Current and maximum Memory allocation
  • Boot options
  • Network, Display, Sound, USB settings
  • Etc.

After the changes and new VM start, your virtual machine will have adjusted resources and device settings. That’s it. Enjoy your VM on KVM.

--

--

No responses yet