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.
Table of Contents
Prerequisites
Obviously, you should have installed KVM in your Linux server. The following guides explains how to install and configure KVM in CentOS 8, Ubuntu 20.04 LTS server and openSUSE Tumbleweed editions.
- Install And Configure KVM In CentOS 8 Server
- Install And Configure KVM In Ubuntu 20.04 Headless Server
- Install And Configure KVM In OpenSUSE Tumbleweed
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
On Fedora:
$ sudo dnf install virt-viewer
On Ubuntu, Debian:
$ sudo apt-get install virt-viewer
1. Manage KVM Virtual Machines Using Cockpit Web Console
1. Open your web browser and log in to Cockpit console by navigating to http://IP-address:9090 from the address bar.
In CentOS 8 system, the Cockpit login console should look like below:
2. 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.
3. 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.
1.1. Create a new KVM virtual machine
1.1.1. To create a kvm guest, click on the "Create VM" button in the Virtual machines section.
1.1.2. 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.
1.1.3 You will now see the overview of your new VM. Make sure all the selected parameters are correct.
1.1.4. 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.
1.1.5. 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:
1.1.6. 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.
1.1.7. Now start the guest OS installation by clicking on the "Install" button.
1.1.8. 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.
1.1.9. 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.
1.2. Import VMs
To import VMs via Cockpit, 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.
1.3. 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.
1.4. Configure KVM storage pools
On the top of the Virtual Machines section, you will see the following two sub-sections:
- Storage pools
- Networks
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.
1.5. 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.
Conclusion
In this guide, we have discussed how to manage KVM virtual machines using Cockpit web console. As you can see, 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.
- How To Manage KVM Virtual Machines With Virt-Manager
- Manage KVM Virtual Machines With Virsh Program
- Create A KVM Virtual Machine Using Qcow2 Image In Linux
- How To Migrate Virtualbox VMs Into KVM VMs In Linux
- How To Use Vagrant With Libvirt KVM Provider
- Enable UEFI Support For KVM Virtual Machines In Linux
- How To Enable Nested Virtualization In KVM In Linux
- Display Virtualization Systems Stats With Virt-top In Linux
- How To Find The IP Address Of A KVM Virtual Machine
- How To Rename KVM Guest Virtual Machine
- Access And Modify Virtual Machine Disk Images With Libguestfs
- Quickly Build Virtual Machine Images With Virt-builder
- How To Rescue Virtual Machines With Virt-rescue
- How To Extend KVM Virtual Machine Disk Size In Linux
- Setup A Shared Folder Between KVM Host And Guest
12 comments
Hi,
Thanks a lot
Good & useful article
Thanks for the detailed explanations! I’m having difficulties with the bidged network mode, though. You state that I should ” “choose Source as ‘br0′”, but I don’t have br0 as an option in the source dropdown menu. I suppose the bridge has to be created first. But how do I create a bridge in Cockpit?
You don’t have to choose bridge network unless you want to access the VM from remote systems other than the KVM host. Just leave the defaults and create VM as usual. If you still want to create bridge network, I have documented the steps to create bridge networking in the first article of this series here-> https://ostechnix.com/install-and-configure-kvm-in-ubuntu-20-04-headless-server/
thanks for the guides! ive been down the ? hole on this stuff for sure. why remove the default network created by libvirt, virbr0? couldnt you keep that and still add br0 and select that for vms you want to expose without conflict with the default interface? you would have both to choose from in case you wanted to keep some vms local.
Thanks for the super fast reply! Okay, so you have to create the bridge outside of cockpit.
My assumption was that cockpit provides a ui that lets you do manage your vms through a gui. I don’t quite understand how they can offer an option “Bridge to LAN” when you can’t use it without creating the bridge outside of Cockpit. Maybe I’m asking too much, but this kind of pitfall should at least be documented in the ui…
Thanks again for your excellent tutorial!
Yes, you need to configure KVM bridge outside of Cockpit.
Thanks, this was great and easy to follow along to.
Hi… after many researches to find good Tutos about virtualization with Raspberry Pi, I finally found your site. It’s really helpful (straightforward guides).
I did first install 2 Raspberry Pi with KVM on Ubuntu 20.04 LTS aarch64, using your article “install-and-configure-kvm-in-ubuntu-20-04-headless-server”.
Then I did install Cockpit on one RPI. But now, I am wondering how I could manage the VM on my 2 RPI from a central console. Cockpit is indeed apparently only to manage the local KVM.
I read your article to use the Virt Manager (“how-to-manage-kvm-virtual-machines-with-virt-manager”), but it’s a Fat UI. Could you recommend a solution with Web UI which can run on a RPI ?
I see on your site an article about proxmox (“setup-server-virtualization-environment-using-proxmox-ve”), but is seems that it’s not yet available for ARM hardware…
10.000 Thanks !!!
Install Cockpit on 2nd RPi and manage it from anywhere.
Thx… Indeed it’s that simple… Now, in the Dashboard I can pick the other RPI.
If someone already has KVM installed and running VMs what happens if I install cockpit afterwards
Nothing. It will work just fine. Cockpit is just a web-based tool to manage VMs.