Manage a KVM Guest with Virsh

KVM is a Linux-based virtualization system that allows you to virtualize a wide variety of operating systems and environments. When you want to manage your virtual machines or guests, you can use a program called virsh. As a command line tool, you can use virsh to manage guests and the hypervisor. It is built on the libvirt management API, and you can use it as an alternative to qemu-kvm or graphical tools like virt-manager.

To list available guests, type:

$ virsh list

This will give you a list of all current guests. The output will look like this:

Connecting to uri: qemu:///system

Id Name                 State


3 cobalt              running

To connect to the hypervisor, use the following command:

$ virsh connect qemu:///system

To start a guest named “cobalt” with virsh, run:

$ virsh start cobalt

To stop a guest, run:

$ virsh shutdown cobalt

There are many other commands you can run to control your guest, including reboot, suspend, resume, migrate, restore, and more. For a complete list of commands, you can type “man virsh” from the command line or see this online documentation.