LoginSignup
0
0

More than 5 years have passed since last update.

kvm maintenance command memo

Posted at

kvm maintenance command memo

objectives

  • personal memo

maintenance

list all vm

virsh -c qemu:///system list --all

list all vm (another hypervisor)

TargetKVMIP=''

virsh -c qemu+ssh://root@$TargetKVMIP/system list --all

list used vnc port

for i in `virsh -c qemu:///system list --all | awk '{print $2}' | grep -v Name` ; do virsh dumpxml $i|grep vnc  ; done | sort

edit vm

  • dump xml
virsh dumpxml <domain name>
  • edit xml
virsh edit <domain name>

vm control

  • start
virsh start <domain name>
  • shutdown
virsh shutdown <domain name>
  • stop
virsh destroy <domain name>
  • remove
virsh undefine <domain name>

clone vm

  • on same kvm
CurrentVM=''
NewVM=''

virt-clone --connect=qemu:///system -o $CurrentVM -n $NewVM -f /mnt/export/hypervisor/datastore1/$NewVM.gcow2
  • on another kvm
CurrentVM=''
NewVM=''
TargetKVMIP=''

scp $CurrentVM.qcow2 $TargetKVMIP:/mnt/export/hypervisor/datastore1/.
scp /etc/libvirt/qemu/$CurrentVM.xml $TargetKVMIP:/etc/libvirt/qemu/.

virsh --connect=qemu+ssh://$TargetKVMIP/system define /etc/libvirt/qemu/$CurrentVM.xml

virsh -c qemu+ssh://root@$TargetKVMIP/system list --all

virt-clone --connect=qemu+ssh://$TargetKVMIP/system -o $CurrentVM -n $NewVM -f /mnt/export/hypervisor/datastore1/$NewVM.gcow2
  • take live snapshot
CurrentVM=''

virsh snapshot-create-as $CurrentVM snapshot1 "snapshot1 description" --disk-only --atomic
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0