
Mastering KVM: A Simple Guide to Listing Your Virtual Machines
Managing a virtualization environment requires clear visibility into your resources. When working with KVM (Kernel-based Virtual Machine), knowing which virtual machines are running and which are powered off is a fundamental administrative task. Fortunately, KVM provides a powerful command-line tool, virsh
, that makes this process straightforward.
Whether you’re performing routine maintenance, troubleshooting an issue, or simply auditing your setup, being able to quickly list your VMs by their status is essential. This guide will walk you through the simple commands needed to see all your active, inactive, and overall virtual machine inventory.
The Essential Tool: virsh
The primary command-line interface for managing KVM and other virtualization platforms through the libvirt API is virsh
. Almost all routine management tasks, from starting and stopping machines to checking their status, are handled with this versatile utility. To use these commands, you will typically need root privileges or to be a member of the appropriate user group (such as libvirt
or kvm
).
How to List Running KVM Virtual Machines
To get an immediate overview of all currently active and running virtual machines on your host system, you can use the most basic list command.
Open your terminal and run:
virsh list
This command will produce a table showing only the VMs that are currently powered on. The output will look something like this:
Id Name State
----------------------------------------------------
2 ubuntu-server-2204 running
5 rocky-linux-9 running
The key columns here are:
- Id: A unique numerical identifier assigned to the VM while it is running.
- Name: The descriptive name you assigned to the virtual machine.
- State: The current status, which in this case will always be running.
This is the command you’ll use most often for a quick check of what’s active on your hypervisor.
Finding Inactive (Stopped) KVM VMs
Equally important is knowing which virtual machines are configured but not currently running. These inactive, or “shut off,” VMs still consume disk space and are part of your environment’s inventory. To see only these machines, you need to add the --inactive
flag.
Execute the following command:
virsh list --inactive
The output will list all VMs that are defined on the host but are not powered on:
Id Name State
----------------------------------------------------
- centos-stream-8-template shut off
- win11-test-env shut off
Notice that the Id column contains a hyphen (-
) for inactive machines, as they do not have a runtime ID. The State column clearly indicates they are shut off. This command is perfect for finding a specific VM you need to start or for identifying unused machines that can be cleaned up.
How to See All KVM VMs (Running and Stopped)
For a complete and comprehensive inventory of every single virtual machine defined on your host, regardless of its current state, you can use the --all
flag. This gives you a master view of your entire KVM environment.
To see every VM, run this command:
virsh list --all
This combines the output of the previous two commands into a single, unified list:
Id Name State
----------------------------------------------------
2 ubuntu-server-2204 running
5 rocky-linux-9 running
- centos-stream-8-template shut off
- win11-test-env shut off
This master list is invaluable for auditing, capacity planning, and comprehensive management tasks.
Practical Tips for VM Management
- Find a Specific VM: If you have dozens of VMs, combine
virsh
withgrep
to quickly find a specific machine. For example:virsh list --all | grep 'win11'
. - Automation and Scripting: These simple commands can be easily integrated into shell scripts for automated health checks, reporting, or daily status updates.
- Resource Management: Regularly listing inactive VMs is a good security and resource management practice. It helps you identify forgotten or unnecessary machines that can be decommissioned to free up disk space and reduce the attack surface of your environment.
By mastering these fundamental virsh list
commands, you gain essential control and visibility over your KVM hypervisor, ensuring you can manage your virtual machines efficiently and effectively.
Source: https://kifarunix.com/list-running-and-stopped-vms-on-kvm/