virsh cheat sheet
| 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: |
|
| Create a new ReactOS VM with virt-install: |
|
| 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.xmlChange: <type arch='i686' machine='pc-1.0'>hvm</type> To: <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 |