Cluster 23. Converting qcow2 to LVM storage.
If you want target machine to remain working while we changing it's storage (it's only recommended for VM's which are NOT having their data updated continuously - like NTP server, if your VM data is updated continuously - you MUST stop the VM and then convert VM's storage and then start VM on the new storage, otherwise you will lose data):
virsh # entry to the virsh console
list # list all running VMs
Id Name State
----------------------------------------------------
4 rntp running
5 rftp running
18 agisrv running
19 squid running
23 cc_replica running
27 nagios running
29 rvoip running
domblklist rntp # list block-devices for given VM name
Target Source
------------------------------------------------
vda /var/lib/libvirt/images/rntp.qcow2
hdc -
domblkinfo rntp vda # view size for an image (we need "Capacity")
Capacity: 16106127360
Allocation: 1576611840
Physical: 1576611840
or:
qemu-img info /var/lib/libvirt/images/rntp.qcow2 # we need "virtual size"
image: /var/lib/libvirt/images/rntp.qcow2
file format: qcow2
virtual size: 15G (16106127360 bytes)
disk size: 1.5G
cluster_size: 65536
Create LV with needed size:
lvcreate -L 16106127360b -n vm01-rntp_0 agrp-c01n01_vg0
virsh dumpxml rntp > /root/rntp.xml
Calculate md5 checksum (md5 sums only verifies/works with the file content rather than the file name):
md5sum /var/lib/libvirt/images/rntp.qcow2 > rntp.md5
md5sum /root/rntp.xml >> rntp.md5
Copy qcow2 image to the destination node:
scp root@10.10.10.2:/var/lib/libvirt/images/rntp.qcow2 /var/lib/libvirt/images/
scp root@10.10.10.2:/root/rntp.xml /etc/libvirt/qemu/
scp root@10.10.10.2:/root/rntp.md5 /root/
Verify md5 checksum (before that change location in the rntp.md5 file):
md5sum -c rntp.md5
/root/rntp.qcow2: OK
/root/rntp.xml: OK
Copying an image to a physical device:
The diskimage will need to be in raw format.
qemu-img convert -O raw rntp.qcow2 rntp.raw
Then you just dd it onto the hard drive.
dd if=rntp.raw of=/dev/agrp-c01n01_vg0/vm01-rntp_0
Or, let qemu-img directly write onto the drive in one command:
qemu-img convert -O raw rntp.qcow2 /dev/agrp-c01n01_vg0/vm01-rntp_0
lvcreate -L 16106127360b -n vm01-rntp_0 agrp-c01n01_vg0
virsh dumpxml rntp > /root/rntp.xml
Calculate md5 checksum (md5 sums only verifies/works with the file content rather than the file name):
md5sum /var/lib/libvirt/images/rntp.qcow2 > rntp.md5
md5sum /root/rntp.xml >> rntp.md5
Copy qcow2 image to the destination node:
scp root@10.10.10.2:/var/lib/libvirt/images/rntp.qcow2 /var/lib/libvirt/images/
scp root@10.10.10.2:/root/rntp.xml /etc/libvirt/qemu/
scp root@10.10.10.2:/root/rntp.md5 /root/
Verify md5 checksum (before that change location in the rntp.md5 file):
md5sum -c rntp.md5
/root/rntp.qcow2: OK
/root/rntp.xml: OK
Copying an image to a physical device:
The diskimage will need to be in raw format.
qemu-img convert -O raw rntp.qcow2 rntp.raw
Then you just dd it onto the hard drive.
dd if=rntp.raw of=/dev/agrp-c01n01_vg0/vm01-rntp_0
Or, let qemu-img directly write onto the drive in one command:
qemu-img convert -O raw rntp.qcow2 /dev/agrp-c01n01_vg0/vm01-rntp_0
Adapting the configuration file
Old situation:
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/var/lib/libvirt/images/rntp.qcow2'/>
<target dev='vda' bus='virtio'/>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</disk>
New situation:
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/agrp-c01n01_vg0/vm01-rntp_0'/>
<target dev='vda' bus='virtio'/><alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</disk>
After this step, you should be able to start your virtual machine again. If the machine boots successfully, you can remove the old disk file (I suggest to stop machine on the previous location and then test new VM for a week and only after that delete old image file).
If you move virtual machine from one machine to the other (both are not members of the same cluster) - use virsh define vm01-rntp.xml to create machine on the new location and then stop VM on the old location (virsh shutdown vm01-rntp) and disable VM autostart (rm /etc/libvirt/qemu/autostart/rntp.xml)
PS if you want to move virtual machine from CentOS 6 (libvirt 0.10.2) to CentOS 7 (libvirt 3.2.0) - xml file will not fit. Instead of using xml file - take any xml-dump file of virtual machine existing on CentOS 7 and replace needed xml attributes (<uuid> / <name> / <memory unit= / <currentMemory unit= / <vcpu placement= / <os> / <disk / <interface ).
No comments:
Post a Comment