virsh cheat sheet

Virsh is a command line utility for managing KVM (Kernel Virtual Machine) guests. This is its cheat sheet.

The material that follows comes from a post by Jaime Frutos Morales in 2010. Many thanks to Jaime for bringing this info together in such a clear and concise way.

In kvm terms guests are referred to as domains, so in the examples that follow “nameofdomain” would be replaced by something like “linuxtest1”.

Information

List all defined domains (guests):

virsh list --all

Show info about a domain:

virsh dominfo nameofdomain

Start and Stop

Start a guest:

virsh start nameofdomain

Shutdown:

virsh shutdown nameofdomain

Force Shutdown:

virsh destroy nameofdomain

Suspend:

virsh suspend nameofdomain

Resume:

virsh resume nameofdomain

Autostart:

virsh autostart nameofdomain

Disable autostart:

virsh autostart --disable nameofdomain

Creating and Modifying Domains

Create domain from xml file:

virsh create domainfile.xml

Dump domain definition to xml:

virsh dumpxml nameofdomain >domainfile.xml

Modify domain definition:

virsh edit nameofdomain

Remove domain definition:

virsh undefine nameofdomain

Backup and Restore

Save domain state:

virsh save nameofdomain domainfile

Restore domain from file:

virsh restore domainfile
This entry was posted in System Administration on by .

About phil

My name is Phil Lembo. In my day job I’m an enterprise IT architect for a leading distribution and services company. The rest of my time I try to maintain a semi-normal family life in the suburbs of Raleigh, NC. E-mail me at philipATlembobrothersDOTcom. The opinions expressed here are entirely my own and not those of my employers, past, present or future (except where I quote others, who will need to accept responsibility for their own rants).