Linux list a KVM vm guest using virsh command

See all GNU/Linux related FAQ
How do I list a KVM vm guest using virsh command on a Linux based hypervisor?

A hypervisor is nothing but Linux kernel module that isolates operating systems and applications from the underlying server. KVM turn Linux operating system into a hypervisor. This post shows how to list an installed KVM guest VM using virsh command line option.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux terminal
Category KVM Virtualization
OS compatibility AlmaLinux Alpine Arch CentOS Debian Fedora Linux Mint openSUSE Pop!_OS RHEL Rocky Stream SUSE Ubuntu
Est. reading time 3 minutes

How to: Linux list a KVM vm guest using virsh command

The syntax is:
virsh list
virsh list --all
virsh list [options]

Examples

Let us see some command examples.

Just list domains / KVM VM guest

Simply type the command:
virsh list
OR
virsh list --all
Linux list a KVM vm guest using virsh command
Name is the name of the domain (KVM VM guest name). ID the domain numeric id. State is the run state as follows:

  1. running – The domain is currently running on a CPU.
  2. idle – The domain is idle, and not running or runnable. This can be caused because the domain is waiting on IO (a traditional wait state) or has gone to sleep because there was nothing else for it to do.
  3. paused – The domain has been paused, usually occurring through the administrator running virsh suspend. When in a paused state the domain will still consume allocated resources like memory, but will not be eligible for scheduling by the hypervisor.
  4. in shutdown – The domain is in the process of shutting down, i.e. the guest operating system has been notified and should be in the process of stopping its operations gracefully.
  5. shut off – The domain is not running. Usually this indicates the domain has been shut down completely, or has not been started.
  6. crashed – The domain has crashed, which is always a violent ending. Usually this state can only occur if the domain has been configured not to restart on crash.
  7. pmsuspended – The domain has been suspended by guest power management, e.g. entered into s3 state.

To list domains with autostart enabled

virsh list --autostart
Sample outputs:

 Id    Name                           State
----------------------------------------------------
 1     openbsd62                      running
 2     freebsd11-nixcraft             running
 3     fedora28-nixcraft              running
 4     rhel7                          running
 5     centos7-nixcraft               running
 6     sles12sp3                      running

We can only list running vm as follows:
virsh list --state-running

Listing all stopped VMS on KVM

Simply exeute the following:
virsh list --state-shutoff
Here is what I see:

 Id   Name        State
----------------------------
 -    archlinux   shut off
 -    centos8     shut off
 -    mysql1      shut off
 -    node1       shut off
 -    node2       shut off

Getting help

Linux list a KVM vm guest using virsh command with the following options:
virsh list --help
Sample outputs:

  NAME
    list - list domains
 
  SYNOPSIS
    list [--inactive] [--all] [--transient] [--persistent] [--with-snapshot] [--without-snapshot] [--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.

virsh list command options

Table 1: List Running and Stopped VMS on KVM
Command Description
--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
--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

Conclusion

And there you have it, you know how to get list of KVM VM/domains using the virsh command. For more info see this page or read man page by typing the following man command:

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

2 comments… add one
  • Elise Kron Jul 14, 2021 @ 10:06

    i WANTED TO list all running and stopped VMS on KVM on my bare metal. This page is what I was looking for. Thank you <3

    • Seema Kumar Sep 27, 2022 @ 10:33

      ++1. helpful page. All my IT problems are sorted out by this site.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.