How Can We Help?

How to Install and Use KVM libvirt on Ubuntu

You are here:
< All Topics

Virtualization Compatibility Check

 

Execute the below command to install the cpu-checker package.

 

apt install -y cpu-checker

 

check if your CPU supports virtualization by running this command.

 

kvm-ok

 

If you get the following result, your CPU supports virtualization with KVM:

 

root@asus:~# kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used
root@asus:~#

 

 

Installing KVM on Ubuntu

 

Provided your CPU supports virtualization, you can install KVM on your machine.

 

To install KVM on Ubuntu, run the apt command below.

 

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

 

These are the packages that will be installed:

 

qemu-kvm – This package provides accelerated KVM support. This is a userspace component for QEMU, responsible for accelerating KVM guest machines.

 

libvirt-daemon-system – This is the libvirt daemon and related management tools used for creating, managing, and destroying virtual machines on the host machine.

 

libvirt-clients – This provides the libvirt command-line interface for managing virtual machines.

 

bridge-utils – This package provides the userland tools used for configuring virtual network bridges. On a hosted virtualization system like KVM, the network bridge connects the virtual guest VM network with the real host machine network.

 

virt-manager – This provides a graphical user interface (GUI) for managing your virtual machines should you wish to use it.

 

If you want the libvirt daemon to start automatically at boot then enable libvirtd:

 

systemctl enable libvirtd

 

If libvirtd is not already running, do:

 

systemctl start libvirtd

 

Check if KVM is loaded in the kernel with:

 

lsmod | grep -i kvm

 

 

 

Overview of basic libvirt commands

 

 

To launch the libvirt KVM GUI Virtual Machine Manager run:

 

 

virt-manager

 

Alternatively you can use the virt-install commands to launch machines from the CLI.

 

Example:

 

virt-install –name fedora1 –vcpu 1 –memory 2048 –cdrom /root/Fedora-Workstation-Live-x86_64-36-1.5.iso –disk size=12 –check disk_size=off

 

 

This creates a Fedora machine with hostname fedora1 with 2GB RAM and a 12GB virtual hard drive.

 

 

To list all VMs:

 

virsh list –all

 

To shutdown the machine:

 

 

virsh shutdown fedora1

 

 

To start the machine:

 

 

virsh start fedora1

 

 

To display the storage allocated to the machine:

 

 

virsh domblklist fedora1

 

To destroy the machine:

 

virsh destroy fedora1

 

To delete the machine and its disk image use virsh undefine. This deletes the VM, and the –storage option takes the comma-separated list of storage you wish to remove. Example:

 

virsh undefine fedora1 -storage /var/lib/libvirt/images/fedora1-1.qcow2

 

 

Table of Contents