How to Remotely Manage KVM Virtual Machines with the virt-manager GUI

Virtualization tutorial - IT technology blog
Virtualization tutorial - IT technology blog

2 AM, a KVM Server, and a Mess of virsh Commands

As a sysadmin, you’re probably no stranger to this scene: it’s 2 AM, and the phone rings off the hook. A critical virtual machine (VM) on a production server has suddenly become inaccessible. You jump out of bed, SSH into the KVM host, and your fingers fly across the keyboard.

The first command, virsh list --all, shows the VM is still “running”. But a ping returns “Destination Host Unreachable”. You want to view its console to check for a kernel panic or something similar, but in your sleep-deprived state, you can’t remember if the command is virsh console my-critical-vm or if you need to use virsh domdisplay to get the VNC address and then connect with a VNC client. Everything becomes confusing and stressful.

The command line (CLI) with virsh is extremely powerful for automation and scripting. But in emergency situations that require quick visual diagnosis, it’s not the most effective tool. This is precisely when we need something more intuitive.

Analyzing the Problem: Using the Wrong Tool in a High-Pressure Situation

The root of the problem isn’t that virsh is weak, but that we’re trying to “use a sledgehammer to crack a nut.” The CLI is for executing precise, repetitive commands. A GUI (Graphical User Interface), on the other hand, is for observing, interacting, and quickly grasping the big picture.

This situation immediately reminds me of my homelab. I run a homelab with Proxmox VE managing over 10 VMs and containers—a playground for testing everything before deployment. If this incident had happened on Proxmox, I would have been in the VM’s console in just two clicks. But life isn’t always that easy; this production server is a bare-bones KVM installation on CentOS, with no Proxmox.

So, is there a solution for bare-bones KVM that still offers a decent graphical interface? Absolutely.

Potential Solutions

  1. Powering Through with virsh: Continue fumbling with commands like virsh dominfo, virt-top, and figuring out how to connect to VNC manually. This approach can solve the problem, but it’s very slow and prone to errors under stress.
  2. Install a Complex Web GUI: Projects like Kimchi or WebVirtMgr are viable options. However, they require installing many additional components on the server, which can impact performance and increase the attack surface. This is not an ideal choice for a stable production system.
  3. Use Virtual Machine Manager (virt-manager): This is a desktop application for Linux that connects directly to the KVM host via SSH and gives you a management interface that’s nearly as good as Proxmox’s. It doesn’t require installing anything extra on the server beyond what KVM already provides. This is the solution we’re looking for!

Virt-manager: The GUI Lifesaver for KVM

Virt-manager is a lightweight graphical tool that allows you to manage KVM (as well as Xen and LXC) virtual machines remotely and securely over SSH. It communicates directly with the libvirt daemon on the server, just like virsh does. Therefore, everything you do in virt-manager is 100% compatible with your existing KVM infrastructure.

Step 1: Install virt-manager on Your Local Machine

Important note: You do not install virt-manager on the KVM server. You install it on the Linux desktop or laptop you use for your daily work.

Open a terminal on your machine and run the corresponding command:

On Ubuntu/Debian:

sudo apt update
sudo apt install virt-manager

On Fedora/CentOS/RHEL:

sudo dnf install virt-manager

Step 2: Ensure You Can SSH into the KVM Host Using an SSH Key

To allow virt-manager to connect without asking for a password every time, you should use SSH keys. This is also a more secure authentication method than passwords. If you haven’t already, create and copy your public key to the server.

ssh-copy-id user@your-kvm-server-ip

Replace user and your-kvm-server-ip with your login credentials. After this step, you should be able to SSH into the server without entering a password.

ssh user@your-kvm-server-ip

Step 3: Connect virt-manager to the Remote KVM Host

After the installation is complete, open “Virtual Machine Manager” from your application menu.

  1. From the main window, go to File → Add Connection…
  2. Check the box for Connect to remote host over SSH.
  3. Username: Enter your SSH username (e.g., root or `admin`).
  4. Hostname: Enter the IP address or domain of the KVM server.
  5. Click Connect.

If the connection is successful, you will see a new connection in the list, and all the virtual machines on that server will appear. If it fails, double-check your SSH and firewall configuration on the server.

Mastering KVM with virt-manager

Once connected, you’ll see that virt-manager acts as a true “control center” for your fleet of virtual machines.

The Overview Dashboard: Your “Radar Screen”

You immediately get a bird’s-eye view: which VMs are running, which are off, and a graph of the host’s overall CPU usage. Everything is clear in a single interface, without typing a single command.

Console Access: A Direct Window into the VM

This is the feature that solves the “2 AM problem.” Just double-click on a virtual machine, and a new window will open. Switch to the Console tab, and you’ll instantly see the login screen or any error messages from the OS inside the VM, exactly as if you were sitting in front of its physical monitor.

Visual Performance Monitoring

In the VM’s detail window, switch to the Performance tab. Here, you have real-time charts for CPU, Memory, Disk I/O, and Network I/O. For example, do you suspect a VM is slow due to excessive disk I/O? Instead of SSHing into the host and running iotop, you just need to glance at the Disk I/O chart. If you see the “write operations” column spike to thousands of IOPS and stay there, you have your answer right away.

Managing Hardware, Snapshots, and More

Need to mount an ISO file for a rescue operation? Go to the Hardware tab, select the CDROM device, and browse to the ISO file on the host. Need to add another virtual disk? Add hardware, create a disk image. It’s all done with a few clicks. You can also create and manage snapshots visually, which is much more convenient than having to remember the virsh snapshot-create-as command string with its dozens of complex parameters.

Conclusion

virsh and virt-manager are not rivals; they are teammates. virsh is an indispensable tool for automation and bulk management. But when you’re facing an incident that requires quick and accurate diagnosis, a graphical tool like virt-manager will save you time, reduce stress, and help you resolve the problem more effectively. Don’t wait until 2 AM to learn it. Install it and give it a try today; it will become an indispensable companion on your journey of KVM system administration.

Share: