Linux kvm installation and snapshot management, and linux kvm snapshot Management
I. Check the installation and status of kvm
1. Install software
Yum-y install kvm virt-manager libvirt
2. An error is reported when libmongod is started. Update device-mapper-libs.
Yum-y upgrade device-mapper-libs
Kvm bridging:
1. Delete the IP address configuration in the eth0 configuration file.
2. Add the configuration file from BRIDGE = "br0" to eth0.
3. Create a ifcfg-br0 configuration file
DEVICE="br0" NM_CONTROLLED="yes" ONBOOT="yes" TYPE="Bridge" BOOTPROTO=none IPADDR=192.168.1.63 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS1=192.168.1.1
4. Restart the network service.
Common virsh commands:
Virsh list # list running virtual machines
Virsh start vm1 # start vm1 VM
Virsh shutdown vm1 # Shut Down vm1 VM
Virsh destroy vm1 # force disable vm1 VM
Virsh undefine vm1 # delete a vm1 VM
Virsh suspend vm1 # Pause/restart the vm1 VM.
Virsh resume vm1 # restore a vm1 VM from the paused state
Ii. KVM snapshot management:
The kvm virtual machine consists of an img image file and an xml configuration file (/etc/libvirt/qemu)
Clone command: virt-clone-o rhel6-71-n xuegod63-kvm2-f/var/lib/libvirt/images/xuegod63-kvm2.img
Virt-clone-o original VM-n New VM-f New imgfile
Compare the configuration file and compare the two xml files with diff. Only the name, img, and maclocations are modified.
After cloning, You need to modify the NIC configuration file of the new virtual machine and delete the/etc/udev/rule. d/70-*-net file! (Similar to vmware clone), but you need to regenerate the NIC configuration file
Snapshot (snapshot ):
The default kvm format is raw. To create a snapshot, you must modify the image file format. You need to reconfigure the xml file
View the qemu-img info image file in the image format (you can also view snapshots)
1. Conversion format (convert raw format to qcow2 format ):
Qemu-img convert-f raw-O qcow2/var/lib/libvirt/images/xuegod63-kvm2.img/var/libvirt/images/xuegod63-kvm2.qcow2
You need to modify the xml file (the modification of the xml file in the directory cannot take effect immediately !)
Virsh edit Virtual Machine (this command takes effect immediately)
Note:-f Source image format-O Target Image Format
2. create a snapshot: qemu-img snapshot-create VM (you can use snapshot-create-as to specify the snapshot name)
3. snapshot management:
Qemu-img snapshot-list VM (or the above method)
4. Restore a snapshot:
1) view the status of the Virtual Machine: virsh domstate xuegod63-kvm2 (virsh list)
2) Restore snapshot: virsh snapshot-revert VM snapshot name
3) view the current snapshot: virsh snapshot-current xuegod63-kvm2 (xml file)
Snapshot Directory:/var/lib/libvirt/qemu/snapshot/Vm/
5. delete a snapshot:
Virsh snapshot-delete Virtual Machine snapshot name (files cannot be deleted directly at the time of deletion)