John Siu Blog

Tech - Business Tool, Personal Toys

KVM Command

☰ Table of Content

Some KVM frequently used commands.

Connection string

virsh and virt-manager use same connection string.

  • Local

    1
    
    virsh -c qemu:///system
    
  • Remote

    1
    
    virsh -c qemu+ssh://user@hostname/system
    
  • Remote from MacOS

    1
    
    virsh -c qemu+ssh://user@hostname/system?socket=/var/run/libvirt/libvirt-sock
    

VM

1
2
3
4
5
6
virsh list      # List running VMs only
virsh list -all # List VMs regardless of running state
virsh list --with-snapshot

virsh start <vm name>
virsh stop <vm name>

Snapshot

  • List

    1
    
    virsh snapshot-list <vm name>
    
  • Create

    1
    2
    
    virsh snapshot-create -domain <vm name>
    virsh snapshot-create-as --domain <vm name> --name <snapshot name>
    
  • Revert

    1
    
    virsh snapshot-revert <vm name> <snapshot name>
    
  • Delete

    1
    
    virsh snapshot-delete --snapshotname <snapshot name> <vm name>
    

Network

1
2
virsh net-list
virsh net-list --all

Pool and Vol

1
2
3
4
5
virsh pool-list
virsh pool-list --all

virsh vol-list <pool name>
virsh vol-list default

Image

  • Create

    1
    2
    
    qemu-img create -f <format> <filename> <size>
    qemu-img create -f qcow2 ubuntu.img 500M
    

    vmdk(vmware) and vdi(virtualbox) are supported.

  • Snapshot

    1
    
    qemu-img create -f qcow2 -b ubuntu.master.qcow2 ubuntu.qcow2
    
  • Info

    1
    
    qemu-img info <filename>
    
  • Resize

    1
    2
    3
    4
    
    qemu-img resize <filename> [+|-]<size>
    qemu-img resize ubuntu.img 550M # set image to new size, use --shrink if new size is smaller
    qemu-img resize ubuntu.img +10M # increase image size by 10M
    qemu-img resize --shrink ubuntu.img -10M # decrease image size by 10M
    

    Check Linux Commands for resizing partition after an image resize.

John Siu

Update: 2022-05-12
comments powered by Disqus