Follow through this guide to learn how to list running and stopped vms on KVM. KVM, an acronym for Kernel-based Virtual Machine, is an open source virtualization technology built into Linux. Specifically, KVM lets you turn Linux into a hypervisor that allows a host machine to run multiple, isolated virtual environments called guests or virtual machines (VMs).
So you could be using KVM to run your virtual machines and wondering how you can list running and stopped VMS? Well, as much as it is possible to get this information from the KVM UI, the terminal centric nerds can also be able to obtain the same information from the command line.
Listing Running and Stopped VMS on KVM
KVM ships with a command line tool called virsh
, which is the main interface for managing virsh guest domains. The program can be used to create, pause, and shutdown domains. It can also be used to list current domains.
You can use the virsh
command with the domain monitoring option, list
.
The basic command syntax is;
virsh list
virsh list [OPTION]
Where [OPTION] can be one of the very many options as shown in the help page. See below output from virsh list --help
.
NAME
list - list domains
SYNOPSIS
list [--inactive] [--all] [--transient] [--persistent] [--with-snapshot] [--without-snapshot] [--with-checkpoint] [--without-checkpoint] [--state-running] [--state-paused] [--state-shutoff] [--state-other] [--autostart] [--no-autostart] [--with-managed-save] [--without-managed-save] [--uuid] [--name] [--table] [--managed-save] [--title]
DESCRIPTION
Returns list of domains.
OPTIONS
--inactive list inactive domains
--all list inactive & active domains
--transient list transient domains
--persistent list persistent domains
--with-snapshot list domains with existing snapshot
--without-snapshot list domains without a snapshot
--with-checkpoint list domains with existing checkpoint
--without-checkpoint list domains without a checkpoint
--state-running list domains in running state
--state-paused list domains in paused state
--state-shutoff list domains in shutoff state
--state-other list domains in other states
--autostart list domains with autostart enabled
--no-autostart list domains with autostart disabled
--with-managed-save list domains with managed save state
--without-managed-save list domains without managed save
--uuid list uuid's only
--name list domain names only
--table list table (default)
--managed-save mark inactive domains with managed save state
--title show domain title
In this tutorial, we are only interested in listing KVM guest vms that are either in running, stopped/shutoff, or paused state.
List Running VMS on KVM
By default, when you run virsh list
command with no other option, it lists currently running or paused vms;
virsh list
Id Name State
-----------------------------------
5 ubuntu20.04-clone paused
6 ubuntu20.04 running
If you want to explicitly list running vms, then run the command below;
virsh list --state-running
Id Name State
-----------------------------
6 ubuntu20.04 running
You can also get the vms in various states, including the running state by using the --all
option.
virsh list --all
Id Name State
------------------------------------
5 ubuntu20.04-clone paused
6 ubuntu20.04 running
- kolla-ansible shut off
List Stopped VMS on KVM
To list stopped KVM virtual machines, you can pass the --state-shutoff
option to virsh list
command.
virsh list --state-shutoff
Id Name State
--------------------------------
- kolla-ansible shut off
Similarly, you can use the –all option to check vms in all states, including stopped vms;
virsh list --all
Id Name State
------------------------------------
5 ubuntu20.04-clone paused
6 ubuntu20.04 running
- kolla-ansible shut off
You can list other states of the KVM virtual machines by passing specific state option to virsh list
command.
That is how easy it is to list running or stopped vms on KVM.
Other tutorials
How to Clone KVM Virtual Machines