Cockpit doesn't require any introduction. If you are a Linux admin, you should've definitely used it or at least heard about it. Cockpit is a free, open source web-based server administration tool used to monitor and administer Linux servers via a web browser. In this guide, we will see how to manage KVM virtual machines using Cockpit web console interface.
Obviously, you should have installed KVM in your Linux server. The following guides explains how to install and configure KVM in CentOS 8 and Ubuntu 20.04 LTS server editions.
- Install And Configure KVM In CentOS 8 Server
- Install And Configure KVM In Ubuntu 20.04 Headless Server
Next, you need to install Cockpit on your KVM host. Refer the following guide to install and configure Cockpit on different Linux distros.
Make sure you have installed "cockpit-machines" package, which gives the ability to manage VMs via a web browser.
Optionally, you can install Virt-viewer application if you want the ability to open a graphical console in your remote desktop client. Virt-viewer is available for most operating systems.
To install virt-viewer on RHEL, CentOS, run:
$ sudo yum install virt-viewer
$ sudo dnf install virt-viewer
On Ubuntu, Debian:
$ sudo apt-get install virt-viewer
Manage KVM Virtual Machines Using Cockpit Web Console
Open your web browser and log in to Cockpit console bay navigating to http://IP-address:9090 from the address bar.
In CentOS 8 system, the Cockpit login console should look like below:
You should now see a tab named "Virtual Machines" on the left pane. Click on it to view the list of available Kvm guest systems on the right side.
From here, we can manage all virtual machine management tasks such as,
- View the list of available virtual machines,
- View the details of a virtual machine,
- Edit the virtual machine parameters such as memory, disk and network interfaces etc.,
- Create a new VM,
- Import a VM,
- Run a VM,
- Delete a VM,
- View storage pools,
- Create a new network pool,
- Edit storage pools,
- View KVM default virtual networks,
- Edit networks,
- Create a new virtual network etc.
Create a new KVM virtual machine
To create a kvm guest, click on the "Create VM" button in the Virtual machines section.
Fill up the the virtual machine details:
- Name - Virtual machine name, for example Archlinux,
- Installation type - I already have the ISO image of the Arch linux OS, so choose Local Install Media. If you don't have ISO, choose download ISO option. The appropriate ISO will be downloaded.
- Operating System - The actual operating system type that you want to install on your kvm guest. Pick the OS you want to install from the drop-down list.
- Storage - Choose the disk storage (hard drive) for your guest. I don't have any existing hdd, so I choose "Create New Volume" option from the drop down list. Enter the size of your hdd or use the slider to select disk volume size.
- Memory - Choose the RAM size for your guest.
The last two are optional. I am going to uncheck these options, because I don't want to start the guest OS installation immediately. Once you entered all required details, click on "Create VM" at the bottom.
You will now see the overview of your new VM. Make sure all the selected parameters are correct.
Apart from the overview tab, there are a few other tabs exists:
- Usage - Shows the usage details memory and vCPU of a running VM.
- Disks - Shows the list of attached disk and cdrom details. In this tab, we can edit the disk, cdrom parameters, add new disk and delete the existing drives.
- Network Interfaces - Shows the network card interface details. In this tab, we we can create a new network interface, edit the exiting network card and unplug the attached network card etc.
- Consoles - In this section, we can choose different ways to access a console on the VM such as,
- using the web-based Graphics Console (VNC),
- the Graphics Console in Desktop Viewer (which uses virt-viewer),
- or the Serial Console.
The only setting you might probably want to configure mostly is the network settings. By default, KVM chooses its default network. If you want to access the VM from other remote hosts outside the network, you need to choose the bridged network (br0).
To do so, go to "Network Interfaces" tab and click "Edit" button:
Select the Interface Type as "Bridge To LAN" Or "Direct attachment" and choose Source as "br0". You can also choose your KVM host's physical network interface, for example enp0s3. Finally click Save.
Now start the guest OS installation by clicking on the "Install" button.
Once you clicked the Install button, you will be taken to the the guess OS installation window shown under the "Consoles" section in the Cockpit interface. Make sure you have chosen "Graphics Console (VNC)" as your Console type.
Now continue the guest OS installation as usual.
You can also access the guest machines using any VNC applications as described under "Access Virtual machines from remote systems via VNC client" section in the Kvm installation guide linked above.
If you already have created VMs, Cockpit has an option to import them. To do so, click on the "Import VM" option under the "Virtual Machines" tab. Enter the name to the VM, choose the existing disk image location on the host's file system, select the operating system type and memory size. Finally, click Import button.
Restart / Pause/ Shutdown Kvm guests
No need to memorize the virsh commands. We can reboot, suspend and power off KVM virtual machines right from the Cockpit interface.
Configure KVM storage pools
On the top of the Virtual Machines section, you will see the following two sub-sections:
- Storage pools
In the Storage pools section, we configure the storage path of all virtual machines. By default, all the virtual machine's disk files are stored under /var/lib/libvirt/images location.
You can create a new storage pool in anywhere in the file system. A storage pool's type can be a;
- Filesystem directory,
- Network file system,
- iSCSI target / iSCSI directory target,
- Physical disk device,
- LVM volume group.
As you can see, I have created two storage pools. Click on a pool to view its details. If you don't need a storage, either deactivate it temporarily or completely delete it.
Configure KVM virtual networks
By default KVM creates a private virtual bridge named virbr0 to let all VMs to connect with one another, within the host computer. The kvm default bridge provides its own subnet and DHCP to configure the guest’s network and uses NAT to access the host network.
You can configure as many virtual networks as you want. I already have configured a bridge network to allow a kvm guests to use same IP range of the host system.
Under Networks section, we can,
- view the IP address details of a network,
- create a new virtual network,
- deactivate a network,
- and delete a network.
Managing Kvm guests via Cockpit is very easy! No need to memorize the commands. Cockpit has simple web interface that allows us to do basic KVM management operations from a web browser with a couple mouse clicks.