virsh cheat sheet

virsh cheat sheet logo
Show VM information
Show a list of all the defined VM's: virsh list --all
Show a VM's info: virsh dominfo VM_name
Start and stop VM's
Start a VM: virsh start VM_name
Shutdown a VM (gently): virsh shutdown VM_name
Shutdown a VM (wild): virsh destroy VM_name
Suspend a VM: virsh suspend VM_name
Resume a suspended VM: virsh resume VM_name
Create and modify VM's
List OS Variants: virt-install --os-variant list
Create a new CentOS VM with virt-install:
virt-install --name=VM_name --arch=x86_64 --vcpus=1 --ram=512
     --os-type=linux --os-variant=rhel6 --hvm --connect=qemu:///system
     --network bridge:br0 --cdrom=centos6.iso --disk path=sda.img,size=20
     --accelerate --vnc --noautoconsole
Create a new ReactOS VM with virt-install:
virt-install --name=reactos --arch=i686 --vcpus=1 --ram=128
     --os-type=windows --os-variant=win2k --hvm --connect=qemu:///system
     --arch=i686 --network model=ne2k_pci,bridge=default
     --cdrom=ReactOS.iso --disk path=ReactOS.vmdk,size=2
     --accelerate --vnc --noautoconsole --video=cirrus
Modify a VM definition: virsh edit VM_name
Remove a VM definition, but keep the files: virsh undefine VM_name
Backup and restore VM's
Save a VM's state on a file: virsh save VM_name VM_state_file
Restore a VM from a state file: virsh restore VM_state_file
Export and Import VM
List VM's:virsh list --all
Dump the XML configuration for the VM:virsh dumpxml VM_name > VM_name.xml
Create a tarball of the VM:tar zcf VM_name.tar.gz VM_name.xml /var/lib/libvirt/images/VM_name.img
MD5Sum the tarfile for transfer:md5sum VM_name.tar.gz
Extract the tarball:tar zxf VM_name.tar.gz -C /
Define VM from XML file:virsh define /VM_name.xml
Change architecture from 32-bit to 64-bit:Edit VM_name.xml


<type arch='i686' machine='pc-1.0'>hvm</type>

<type arch='x86_64' machine='pc-1.0'>hvm</type>
Make ISO from CD/DVD:dd if=/dev/sr0 of=out.iso
mkdir -p /var/lib/libvirt/iso
mv out.iso /var/lib/libvirt/iso
Sandboxing with virt-sandbox
Run a command in a KVM sandbox:virt-sandbox -c qemu:///session /bin/date
Run a command in a KVM sandbox:virt-sandbox -c qemu:///session /bin/cat /proc/cpuinfo
Run a BASH shell in a LXC sandbox:virt-sandbox -c lxc:/// /bin/bash
categories: linux | virsh | qemu | libvirt | kvm |