KVM is Kernel-based Virtual Machine. It's a module built directly into the Linux kernel that allows the operating system to act as a hypervisor. Although some people may prefer a third-party solution like VirtualBox, there's no need to install extra software since the Linux kernel already gives us the necessary tools we need to make virtual machines.
KVM requires a little configuration if you want some conveniences like a graphical manager or the ability to allow VM guests to login from your network - but we'll cover that in this guide. Once it's up and running, you'll find that KVM provides the most stable and seamless experience for your virtualization needs on Linux.In this tutorial you will learn:
- How to install necessary KVM utilities on Ubuntu 20.04
- How to install and configure virt-manager
- How to configure network interfaces for bridged connection
- How to create a new virtual machine
|Category||Requirements, Conventions or Software Version Used|
|System||Installed or upgraded Ubuntu 20.04 Focal Fossa|
|Other||Privileged access to your Linux system as root or via the |
|Conventions|| # - requires given linux commands to be executed with root privileges either directly as a root user or by use of |
Install the KVM packages
Although KVM is a module built into the Linux kernel itself, it doesn't mean that all the necessary packages are included in your Ubuntu install by default. You'll need a few to get started, and they can be installed with this command in the terminal:
$ sudo apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virt-manager
Configure the network bridge
In order for your virtual machines to access your network interface and be assigned their own IP addresses, we need to configure bridged networking on our system.
First, run the following Linux command in order to find out what name your network interface has been assigned. Knowing this will allow us to do additional configuration later.
$ ip a
In our case, the network interface is called
enp0s3. Yours will likely be very similarly named.
In order to tell Ubuntu that we want our connection to be bridged, we'll need to edit the network interfaces configuration file. Doing this won't negatively impact your connection at all. It'll just allow that connection to be shared with the VMs.
nano or your favorite text editor to open the following file:
$ sudo nano /etc/network/interfaces
When you first open this file, it may be empty or contain just a couple lines. Your bridge interface is called
br0, so add the following line for the interface to come up by default:
Below this line, add the following line for your current network interface (the one whose named we determined earlier).
iface enp0s3 inet manual
Next, you can add the bridge information. These lines tell Ubuntu that your bridge will use DHCP for automatic IP address assignment, and your bridge will manage your current interface.
iface br0 inet dhcp bridge_ports enp0s3
This is how your file should look once all the changes have been applied (if you also have a couple lines that were already there, it's fine to have them too):
Save your changes and exit the file.
Add your user to the groups
In order to manage your virtual machine(s) without root privileges, your user will need to belong to two user groups. Run the following commands to add your user to the appropriate groups (replacing
user1 with the name of your user):
$ sudo adduser user1 libvirt $ sudo adduser user1 libvirt-qemu
When you're done, you should restart your system to ensure that all of the changes done to your user and network configuration have a chance to take effect.
Creating a VM
When Ubuntu boots back up, you can open virt-manager from the application launcher. Although it may not look like much, this window will provide us with everything we need to manage our VMs.
To get started creating a new VM, click the upper left icon, which looks like a shiny computer screen.
Your new virtual machine is going to need an operating system. You'll most likely be installing from an .iso file, so select this option on the first window. If you still need an operating system image, head over to Ubuntu 20.04 download and download one for free.
Browse to your installation file and select it.
You'll also need to tell virt-manager what operating system you're trying to install, if it doesn't automatically determine it successfully.
On the next screen, allocate a reasonable amount of CPU and memory resources to your new virtual machine. Be careful not to give it too much.
The next screen will ask you about hard drive size. Once again, enter a reasonable amount - a virtual machine probably doesn't need much.
Give your virtual machine a name and finalize your changes on the next screen. Click 'Finish' when you're ready to begin the installation.
After clicking finish, the operating system will install as it usually would on a physical computer. When finished, you can continue using the virt-manager application to manage your virtual machine(s), including turning them on and off.
In this article, we learned how to use KVM and virt-manager to install and manage virtual machines on Ubuntu 20.04 Focal Fossa. We also saw how to configure network interfaces for bridged connections between the host machine and guest operating systems.
KVM is a very powerful tool, and paired with virt-manager makes for sleek and easy management of multiple virtual machines. Now that KVM is set up, you'll have access to just about any operating system in a virtualized form, directly from your Ubuntu desktop.