2.KVM virtual machine cloning and snapshot

outline:

2.1 the KVM VM cloning procedure
 2.2 virtual machine image format commonly Comparative
 2.3 the KVM virtual machine snapshot function to use
 2.4 virsh command common usage
 2.5 KVM common image format conversion

2.1 KVM virtual machine cloning method
2.1.1 kvm clone a virtual machine
before cloning, centos7.0 need to shut down in advance.

Syntax: virt-clone -o -n new original virtual machine virtual machine - f new virtual machine image storage path 
options: -o Old - the n-new new 
virtual machine images: that is, the entire virtual machine files. Ji is the operating system CD image rhel6,. . 5 .iso 
example: KVM virtual machine image file 

[Linzi the root @ ~] # CD / var / lib / the libvirt / Images / 
[the root @ Linzi Images] # LL 
total volume 11,427,672 
-RW- ------ 1 qemu qemu 10739318784 dated. 6 14:03. 6 centos7.0.qcow2
 -rw-R & lt - r--. 1 962 592 768 QEMU QEMU. 6. 7-dated the CentOS-10:17. 6 the x86_64-Minimal-1810 . ISO 
drwx ------ 2 root root 16384 6 Yue 10:53 Lost + 6 found 
[root @ Linzi ImagesRF Royalty Free] # du -SH * 
11G centos7.0.qcow2 
919M CentOS-7-x86_64-Minimal-1810.iso
16K     lost+found

2.1.2 Based centos7.0 clone a virtual machine: linzi2

[Linzi the root @ ~] # the virt-clone -o centos7.0 -n linzi2 -f /data2/linzi2.qcow2 
are assigned ' linzi2.qcow2 '                                                                                                                            | 00:00:26 10 GB      

cloned ' linzi2 ' .

View cloned virtual machine files and disk usage

[root@linzi ~]# ll /data2/
总用量 1462872
-rw------- 1 root root 1498021888 6月   6 14:50 linzi2.qcow2
drwx------ 2 root root      16384 6月   6 14:32 lost+found
[root@linzi ~]# du -sh /data2/*
1.4G    /data2/linzi2.qcow2
16K     /data2/lost+found

2.1.3 KVM virtual machine composed of
a KVM virtual machine consists of two parts: the virtual machine configuration file and image img
view the virtual machine's configuration file:

[root@linzi ~]# cd /etc/libvirt/qemu/
[root@linzi qemu]# ll
总用量 16
drwxr-xr-x 2 root root    6 6月   6 11:41 autostart
-rw------- 1 root root 4601 6月   6 11:42 centos7.0.xml
-rw------- 1 root root 4575 6月   6 14:50 linzi2.xml
drwx------ 3 root root   42 6月   6 10:55 networks

Check the contents of the virtual machine configuration file:

[root@linzi qemu]# cat centos7.0.xml 
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
  virsh edit centos7.0
or other application using the libvirt API.
-->

<domain type='kvm'>
  <name>centos7.0</name>
  <uuid>2d64a767-252b-4eab-99ec-42ab1e0a57ec</uuid>
  <memory unit='KiB'>524288</memory>
  <currentMemory unit='KiB'>524288</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <cpu mode='custom' match='exact' check='partial'>
    <model fallback='allow'>Broadwell</model>
  </cpu>
  <clock offset='utc'>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <pm>
    <suspend-to-mem enabled='no'/>
    <suspend-to-disk enabled='no'/>
  </pm>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/centos7.0.qcow2'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <target dev='hda' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <controller type='usb' index='0' model='ich9-ehci1'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci1'>
      <master startport='0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0' multifunction='on'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci2'>
      <master startport='2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci3'>
      <master startport='4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <controller type='virtio-serial' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </controller>
    <interface type='bridge'>
      <mac address='52:54:00:bd:d1:58'/>
      <source bridge='br0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target type='isa-serial' port='0'>
        <model name='isa-serial'/>
      </target>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <channel type='unix'>
      <target type='virtio' name='org.qemu.guest_agent.0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    </channel>
    <channel type='spicevmc'>
      <target type='virtio' name='com.redhat.spice.0'/>
      <address type='virtio-serial' controller='0' bus='0' port='2'/>
    </channel>
    <input type='tablet' bus='usb'>
      <address type='usb' bus='0' port='1'/>
    </input>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='spice' autoport='yes'>
      <listen type='address'/>
      <image compression='off'/>
    </graphics>
    <sound model='ich6'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </sound>
    <video>
      <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='2'/>
    </redirdev>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='3'/>
    </redirdev>'
    <memballoon model =virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </memballoon>
    <rng model='virtio'>
      <backend model='random'>/dev/urandom</backend>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </rng>
  </devices>
</domain>

View distinguish the original virtual machine and clone complete virtual machine configuration file:

[@ Linzi the root QEMU] # vimdiff centos7.0.xml linzi2.xml 

Note: This can be seen that both the MAC address is not the same. So after clone or copy out the virtual machine starts, to modify the network network, because the MAC address ifcfg-eth0 MAC address and the real operating system cloned virtual machines in different

Start linzi2 test:

[root @ Linzi QEMU] # virsh Start linzi2 
domain linzi2 has begun

2.1.4 test the new clone machines:

In the new clone machines IP address can change it, or change the mac address

2.2 virtual machine image format commonly used contrast

mainly virtual machine image formats: raw, cow, qcow, qcow2 , vmdk.

2.2.1 raw image format

raw: Old Pan's image format, with one word, it is naked, is naked, you just dd simulates a file on a raw image format. Due to the completely bare, if performance is good. 
centos6 on KVM and XEN default format or is this a format. centos7 above default qcow2.

There is a simple bare benefits, support for virtual machine images converted into other formats to bare it is still very simple (If you need to convert other formats, sometimes still need it as an intermediate format), use of space point of view, this is much like disk, how much use is the number (du - H to see the size is to use size).

Example: qcow2 Switch vmdk is: qcow2 into raw, and then into the raw vmdk. It can also be converted directly qcow2 vmdk

Extended: fidelity on Canon cameras is this raw format. RAW intent is "raw." It can be understood as: RAW image is CMOS or a CCD image sensor to convert the captured light signals to digital signals of the original data.
RAW understood as "digital negatives"
Disadvantages: does not support snapshot snapshots.

2.2.2 cow, qcow, qcow2 format

1 , Cow format: Not yet mature, it was abandoned. It was later replaced by qcow format.
2 , qcow format: When just appeared to have better properties, but its performance and compare raw format is still a large gap, it has now been replaced by a new version of qcow2.
3 , qcow2 format: more mainstream now a virtual image formats, optimized generation now approaching the performance of raw bare format of the performance qcow2 the
 
qcow2 format support snapshot, you can do N multiple snapshots on the mirror, has the following advantages :
less storage space supports creating a mirror image supports multiple snapshot, to scold snapshot Zhong Li line management support zlib compression disk encryption support for AES

2.2.3 vmdk format:

VMware format, the best overall performance, because the original is doing VMware virtualization started. From a performance and functional point, vmdk should be considered the best, due to the combination of a lot of ability vmdk VMware, the present situation, KVM and XEN love this format using the 
situation is not too much. But VMware's enterprise-class virtualization Esxi point of view, its stability and ability in all aspects are good

2.3 KVM virtual machine snapshot function to use
the role of snapshots: 1, 2 hot backup, disaster recovery 3, roll back to a state historical
snapshot of the use of space:

kvm snapshot, in two ways:
Method 1: Use lvm snapshots, if the partition is lvm, lvm can use the snapshot backup kvm
Method 2: Use qcow2 format image snapshot. 

 

2.3.2 Creating a snapshot KVM

In centos6, kvm virtual machines using the default raw format image format, the performance of the best, fastest, its drawback is that not support some new features, such as support for mirroring, zlib disk compression, AES encryption.

To use the snapshot feature, disk format must be qcow2.

View disk formats:

[root@linzi qemu]# qemu-img info /var/lib/libvirt/images/centos7.0.qcow2 
image: /var/lib/libvirt/images/centos7.0.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 10G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true

[root@linzi qemu]# qemu-img info /data2/linzi2.qcow2 
image: /data2/linzi2.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 1.4G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true

Note: qcow2 format can create snapshots directly


2.3.3 snapshot management for virtual machines

 Create a snapshot of the virtual machine linzi2
syntax: virsh name snapshot-create the virtual machine
Example: create a snapshot

[root @ Linzi ImagesRF Royalty Free] # virsh linzi2 the Create Snapshot- 
generated domain snapshots 1559807904

Note: When you create a snapshot without shutting down the virtual machine, create a snapshot shut down faster, boot need to create a snapshot of the contents of memory to disk, the recording state of the virtual machine of the moment. 

Kai names when you create a snapshot:

 

 Syntax: virsh snapshot-create-as KVM virtual machine snapshot name name
Example: a raw snapshot name is: httpd

[root @ Linzi ImagesRF Royalty Free] # virsh the Create Snapshot-AS linzi2 httpd- 
generated domain snapshots httpd 

[root @ Linzi ImagesRF Royalty Free] # virsh Snapshot List linzi2 #-view mirror snapshots of virtual machines list of 
names generation time state
 ------- -------------------------------------------------- --- 
 1559807904 2019-06-06 15:58:24 +0800 running 
 httpd                 2019-06-06 16:16:01 +0800 running

View a snapshot of the most recent version to use:

[root@linzi images]# virsh snapshot-current linzi2

Snapshot configuration file in the / var / lib / libvirt / qemu / snapshot / virtual machine name

[root@linzi images]# ll /var/lib/libvirt/qemu/snapshot/linzi2/*
-rw------- 1 root root 5447 6月   6 16:16 /var/lib/libvirt/qemu/snapshot/linzi2/1559807904.xml
-rw------- 1 root root 5493 6月   6 16:16 /var/lib/libvirt/qemu/snapshot/linzi2/httpd.xml

Go to snapshots occupy Size:

[root@linzi images]# qemu-img info /data2/linzi2.qcow2 
image: /data2/linzi2.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 2.2G
cluster_size: 65536
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1         1559807904             433M 2019-06-06 15:58:24   00:48:07.473
2         httpd                  433M 2019-06-06 16:16:01   01:05:42.410
Format specific information:
    compat: 1.1
    lazy refcounts: true

2.3.4 restore a virtual machine snapshot
to restore a virtual machine snapshot of the virtual machine must be shut down. Note: Ali cloud also need to close and then revert to the snapshot

 

 

Guess you like

Origin www.cnblogs.com/hbxZJ/p/10985716.html