How to Setup Linux KVM Kernel Virtualization Module on Ubuntu Linux

|

|

KVM (Kernel-based Virtual Machine), an open-source virtualization solution for Linux systems, can be installed on Ubuntu servers, filling a similar role to VirtualBox and VMware. The tutorial guides through checking CPU compatibility for KVM, package installation, network bridge configuration, and creating new virtual machines. KVM allows administration through a graphical user interface or CLI commands.

KVM (Kernel-based Virtual Machine) is an open-source complete virtualization solution for Linux systems, including Ubuntu. Like VirtualBox and VMware Workstation, KVM is a virtualization infrastructure for the Linux kernel that turns it into a hypervisor.

This brief tutorial shows students and new users how to install KVM kernel modules on the Ubuntu server to enable full virtualization.

If you can’t install VirtualBox or VMware Workstation virtualization solutions on Ubuntu, you can try KVM. After installing, use the KVM module to install and run multiple virtual machines (guest) on Linux servers.

This virtual machine can be managed via the virtual-manager graphical user interface or first-install & virsh CLI commands.

When you’re ready to install KVM, follow the steps below:

Check your System

Not all systems can install and run KVM modules. For example, if you’re running a server that isn’t compatible, KVM can’t be used. To check, run the commands below to install a CPU checker tool:

sudo apt install cpu-checker
sudo kvm-ok

After installing the above commands, check the CPU compatibility with KVM. If KVM is compatible, you should get the message that KVM acceleration can be used.

KVM acceleration can be used

if KVM isn’t compatible with your system, you’ll get a message that reads

INFO: Your CPU does not support KVM extensions
KVM acceleration can NOT be used

The message above shows you can’t run KVM.

Install KVM Packages

If step 1 is good, run the commands below to install KVM packages to enable full virtualization functionality on Ubuntu via the Linux kernel.

sudo update
sudo apt install qemu qemu-kvm libvirt-bin  bridge-utils  virt-manager

After installing the KVM packages, run the commands below to start and enable it to automatically startup when the system boots.

sudo systemctl start libvirtd
sudo systemctl enable libvirtd

Configure Network Bridge for the Virtual Machine

KVM virtualization module requires a network bridge for its virtual guest machines. On Ubuntu 18.04 server, a new file /etc/netplan/50-cloud-init.yaml file is created for network configurations. Use this file to configure static IP; bridge and netplan utility will refer to this file.

Run the commands below to open the Ubuntu network config file to create a new network bridge.

sudo nano /etc/netplan/50-cloud-init.yaml

Then, save a new bridge section [highlighted] to the file.

network:
  ethernets:
    enp0s3:
      dhcp4: no
      dhcp6: no
  version 2

  bridges:
    br0:
      interfaces: [enp0s3]
      dhcp4: no
      dhcp6: no
      addresses: [172.168.0.10/24]
      gateway4: 172.168.0.1
      nameservers:
        addresses: [172.168.0.1]

Save the file and exit.

Next, run the commands below to apply the changes.

sudo netplan apply
sudo netplan --debug  apply

Next, continue below to start creating your VMs.

Create New VMs

Now that the server is configured, open the KVM virtual machine manager and create a new virtual guest machine. First, connect to the server, then create a new machine by clicking New Virtual Machine.

Then, choose how to install the guest machine. You can use local ISO media or via network / PXE install.

Next, browse for the ISO file if you’re installing via ISO and select the file with the OS. In this post, we’re going to be installing the Ubuntu server.

After selecting the OS file, continue to create a setup of a local disk, system memory, and other settings.

When you’re done, boot the VM to install Ubuntu

That’s it!

You may also like the post below:


Discover more from Geek Rewind

Subscribe to get the latest posts to your email.

Like this:



2 responses to “How to Setup Linux KVM Kernel Virtualization Module on Ubuntu Linux”

  1. Konrad Avatar
    Konrad

    My setup looks like this… very different from yours:

    network:
    version: 2
    renderer: networkd
    ethernets:
    eno1:
    dhcp4: yes

    Should I be appending:
    bridges:
    br0:
    interfaces: [enp0s3]
    dhcp4: no
    dhcp6: no
    addresses: [192.168.1.10/24]
    gateway4: 192.168.1.1
    nameservers:
    addresses: [192.168.1.1]

    1. Where 192.168.1.10 is the ip of the host machine, is that what’s suppose to go under addresses?
    2. Do I need a gateway? Is that just my router?
    3. Do I need a nameserver specified? And is that my router again?
    4. The VMs will be assigned MAC addresses I presume, so dhcp is ok as the router will assign them an IP. So dhcp4 should be ‘no’ correct?

  2. persu Avatar
    persu

    “KVM acceleration can NOT be used” and from that you have implicated a claim that “The message above shows you can’t run KVM…”
    …your claim is not true. Please do not post false truths around the internet.

Leave a Reply to persuCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Discover more from Geek Rewind

Subscribe now to keep reading and get access to the full archive.

Continue reading