ClickCease The Essential KVM Cheat Sheet for Administrators

Content Table

Join Our Popular Newsletter

Join 4,500+ Linux & Open Source Professionals!

2x a month. No spam.

The Essential KVM Cheat Sheet for System Administrators

Rohan Timalsina

April 22, 2024 - TuxCare expert team

  • The virsh command is used for managing guest virtual machines. 
  • You can start, stop, reboot, and get information about VMs effortlessly with commands.
  • Automating security patching on KVM virtualization systems is possible with the QEMUCare live patching solution.


KVM (Kernel-based Virtual Machine) is a powerful open-source virtualization technology built into the Linux kernel. It allows you to create and manage virtual machines (VMs) on Linux systems. For Linux administrators, mastering KVM commands and their options is necessary for efficient virtualization management. This guide provides a comprehensive KVM cheat sheet for administrators working with KVM, offering essential commands and their usage.


KVM Commands for Virtualization Management


Basic Management [KVM Cheat Sheet]


List only running VMs


The following command displays the currently running virtual machines. It shows the information summary of the active VMs, including their names, state (running, paused, or shut off), and IDs.


$ sudo virsh list


List all Virtual Machines


You can use this command to view all virtual machines, regardless of their current state. It provides a summary of all VMs that are currently running and those that are defined but not running.


sudo virsh list –all


Start a Virtual Machine


The virsh start command starts a specified virtual machine. It essentially initiates the boot process, allowing it to run and be accessible.


sudo virsh start <vm-name>


Shutdown a Virtual Machine


The virsh shutdown command attempts a graceful shutdown of a running virtual machine. It sends an ACPI shutdown signal to the VM, allowing the guest operating system to perform a proper shutdown sequence. This allows the guest OS to close applications and save data before powering off.


sudo virsh shutdown <vm-name>


Reboot a Virtual Machine


The virsh reboot command reboots a running virtual machine. Unlike shutdown, it doesn’t involve the guest OS. It causes the VM to perform a restart, similar to pressing the reset button on a physical machine. The guest OS may not have a chance to properly shut down, potentially leading to data loss.


sudo virsh reboot <vm-name>


Advanced Management [KVM Cheat Sheet]


Destroy a Virtual Machine


The virsh destroy command forcefully shuts down a running virtual machine. Unlike virsh shutdown, which performs a graceful shutdown, virsh destroy terminates the VM abruptly, similar to pulling the plug on a physical machine. This command should be used with caution as it can lead to data loss or corruption if the VM’s filesystem is not properly shut down.


sudo virsh destroy <vm-name>


Save the XML configuration file of a VM


The dumpxml command prints the XML configuration of a virtual machine. The XML configuration contains detailed information about the virtual machine’s settings, including its name, memory allocation, CPU configuration, disk devices, network interfaces, and other attributes. It can be useful for backup, migration, or manual configuration of virtual machines.


By default, dumpxml outputs to STDOUT when executed. To save the XML configuration to a file, you can use the shell redirect operators (“>”).


For example, this command saves the XML configuration of the specified VM to a file named “vm-config.xml”.


virsh dumpxml vm-name > vm-config.xml


View VM Details


The virsh dominfo command provides detailed information about a specified virtual machine. It displays various details regarding the virtual machine, such as domain ID, name, OS type, state, CPU, max memory, used memory, security model, etc.


virsh dominfo <vm-name>


Check VM Status


You can use the virsh domstate command to check the state of a specific virtual machine, whether it’s running or stopped.


virsh domstate <vm-name>


Connect to VM console


The following command connects to the console of a virtual machine, allowing direct interaction with its operating system.


sudo virsh console <vm-name>

The Essential KVM Cheat Sheet for Administrators
Article Name
The Essential KVM Cheat Sheet for Administrators
Learn essential commands for efficient virtualization management with our comprehensive KVM cheat sheet for system administrators.
Publisher Name
Publisher Logo

Looking to automate vulnerability patching without kernel reboots, system downtime, or scheduled maintenance windows?

Learn About Live Patching with TuxCare

Become a TuxCare Guest Writer

Get started




Linux & Open Source

Subscribe to
our newsletter