How to Install KVM on Ubuntu

Update Ubuntu

Run the command below:

sudo apt update

Check Virtualization Support on Ubuntu

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

Output:

rogerp@skynet:~/.ssh$ sudo egrep -c '(vmx|svm)' /proc/cpuinfo
16

If the command returns a value of 0, your processor is not capable of running KVM. On the other hand, any other number means you can proceed with the installation.

Next, check if your system can use KVM acceleration:

sudo kvm-ok

    The output should look like this:

    rogerp@skynet:~/.ssh$ sudo kvm-ok
    INFO: /dev/kvm exists
    KVM acceleration can be used
    

    If kvm-ok returns an error, install cpu-checker to resolve the issue.

    To install cpu-checker, run the following command:

    sudo apt install cpu-checker
    

      When the installation completes, rerun the command to check KVM acceleration availability, and if everything is ok, you are ready to start installing KVM.


      Install KVM Packages

        Install the essential KVM packages with the following command:

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

        Wait until the system installs all the packages.


        Authorize Users

        Only members of the libvirt and kvm user groups can run virtual machines. If you want specific users to run VMs, add them to those user groups. Follow the steps below:

        Add the user you want to run the virtual machines to the libvirt group:

        sudo adduser [username] libvirt
        

          Replace [username] with the actual username.

          Next, do the same for the kvm group:

          sudo adduser [username] kvm
          

            Verify the Installation

            sudo virsh list --all
             Id   Name   State
            --------------------
            

            Alternatively, use the systemctl command to check the status of libvirtd, the daemon that provides the backend services for the libvirt virtualization management system:

            sudo systemctl status libvirtd
            

            If everything is functioning properly, the output returns an active (running) status.

            Create Virtual Machine on Ubuntu

            Before you choose one of the two methods below for creating a VM, install virt-manager, a tool for creating and managing VMs:

            sudo apt install virt-manager -y
            

            Start virt-manager by running the command below:

            sudo virt-manager
            

            Leave a Comment