This article describes how to manage KVM virtual machines with Virt-manager in Linux. We already knew how to install and configure KVM in CentOS 8 server, how to setup KVM in Ubuntu 20.04 LTS server and how to manage the kvm guests using Cockpit web-console. The virt-manager application is for managing KVM guests hosted in Linux systems that have graphical desktop environments.
Virt-manager, short for Virtual Machine Manager, is a graphical user interface application used for managing virtual machines through libvirt. Even though it is mainly created for KVM guests, it also can manage XEN and LXC containers as well. It has an embedded VNC and SPICE client viewer application to view the full screen console of a running VM.
Virtual Machine Manager allows the users to:
- create, edit, start, suspend, resume and stop VMs,
- view and control each VM's console,
- view all running VMs and hosts,
- view the performance and utilization statistics of each VM,
- view the live performance and resource utilization statistics of VMs and hosts,
- manage KVM, Xen or QEMU virtual machines, running either locally or remotely,
- manage LXC containers etc.
Virt-manager is written in Python and developed by Red Hat.
Install Virt-Manager in Linux
Virt-manager has been packaged for many popular Linux distros.
On Arch Linux and its variants like Manjaro Linux, run the following command to install Virt-manager:
$ sudo pacman -S virt-manager
On Debian, Ubuntu:
$ sudo apt install virt-manager
In Ubuntu make sure you have enabled [universe] repository.
On RHEL, CentOS, Fedora:
$ sudo dnf install virt-manager
$ sudo zypper install virt-manager
In addition to Virt-manager, the following supporting tools will also be installed as well:
- virt-install - a command line tool to provision new virtual machines. It creates a new KVM, Xen, or Linux container guests from command line using the "libvirt" hypervisor management library.
- virt-viewer - a lightweight UI interface to view and interact with the graphical display of virtualized guest OS. It can display VNC or SPICE, and uses libvirt to lookup the graphical connection details.
- virt-clone - a command line tool used to clone existing inactive guests. It copies the disk images, and defines a config with new name, UUID and MAC address pointing to the copied disks.
- virt-xml - a command line tool to edit libvirt domain XML.
- virt-convert - a command line tool to convert OVF and VMX VM configurations to run with libvirt.
- virt-bootstrap - a command tool providing an easy way to setup the root file system for libvirt-based containers.
Manage KVM Virtual Machines With Virt-Manager
Once Virt-manager is installed, launch it from Dash or menu. The default interface of Virt-manager should look like below:
Managing KVM guests with Virt-manager is very easier than you think. Let me show you basic Kvm management tasks with screenshots.
Create a new virtual machine
Go to File -> New Virtual Machine from Virt-manager main window. Choose how would you like to install the guest OS. You will be give four choices as listed below:
- Local install media (E.g. ISO or CDROM),
- Network install such as HTTP, HTTPS, or FTP,
- Network Boot (E.g. PXE),
- Import existing disk image.
I go with "Local install media" option. Click Forward to continue:
Choose the ISO file location of the OS. If you have the physical CD/DVD medium, choose it instead. You operating system type will automatically be selected depending on the installation medium you choose. If Virt-manager can't detect the OS type, uncheck the option that says "Automatically detect from the installation media / source" and select "Generic default" as your OS type. I selected POP_OS! 20.04 ISO file, but Virt-manager could not detect the OS type, so I choose Generic default.
Choose memory size and number of cores for virtual CPU:
Choose the disk size for the Kvm guest:
Enter the name for your Kvm guest. The name should not contain any blank spaces. Click Finish to create the virtual machine.
Once the Virtual machine is created, you will be automatically taken to the virtual machine's graphical console window.
Continue the guest OS installation as usual.
Switch between normal mode and full screen screen mode
By default, the guest will start in normal window mode. You can toggle to full screen mode by clicking on the "Switch to full screen view" button on the top right side of console window.
To go back to normal window, move the mouse cursor to the top middle side (over the date and time of VM) and you will see "Leave full screen" option, just click on it to switch to normal window.
View all running kvm guests and their resource usage
The Virt-manager main window shows all running kvm guests and resource utilization by the guests.
From here, you can start, pause, save the current state of a VM, restart and shutdown VMs.
View Kvm virtual machine details
The virtual hardware details window shows the information about all hardware resources configured to the kvm guest.
In this window, you can,
- view running guest OS details,
- view the Hypervisor details,
- view guest operating system's type,
- view resource utilization by cpu, memory, disk and network,
- view number of vCPUs,
- view allocated memory size,
- view boot options,
- view virtual disk and cdrom details,
- view network settings,
- view keyboard and mouse settings,
- view display card details,
- view sound card details,
- view information of all other hardware attached to the guest machine,
- add a new virtual hardware,
- modify the parameters of a virtual hardware,
- remove virtual hardware etc.
Add a virtual hardware
Open Virtual hardware details window and click "Add Hardware" button at the bottom.
Choose the hardware type you want to add from the left pane and pick a device from the list to attach to the guest machine.
View Kvm host and guest CPU usage
From Virt-manager main window, we can view the all guest machines' cpu usage by default. To view the KVM host's CPU usage, go to View -> Graph and select "Host CPU Usage" option.
Clone Kvm guests
Virt-manager allows us to clone the existing virtual machines. First make sure the guest machine is switched off. Right click on the guest machine and choose "Clone" from the menu.
It creates a new independent copy of the original virtual disk and defines a config with new name, UUID and MAC address pointing to the copied disks.
View Disk I/O, Network I/O, Memory stats
By default, Virt-manager will only shows the CPU usage. If you want to view the statistics of Disk I/O, Network I/O and Memory, you must enable them from Virt-manager main window.
Go to View -> Preferences and check those options to enable them.
Then go to View -> Graph and select Memory Usage, Disk I/O and Network I/O. Now you will see these statistics from the Virt-manager main window.
Virt-manager is poor man's Vmware ESXi server and a great replacement for other standalone virtualization applications like Oracle VirtualBox and Vmware workstation. Deploying and managing VMs using Virt-manager is easy and fast. Since it is from Red Hat, we can get consistent updates and bug fixes. If you have sufficient hardware, you could setup a perfect server virtualization environment for your organization using Virt-manager without much hassle.