One reason virtual machine cloning is slow
Failure phenomenon
The R&D department purchased a new server, copied the virtual machine disk image on the old server through scp, and then cloned the virtual machine with the virt-clone command, and found that the cloning speed was very slow, which took more than ten minutes, cloned on the old server It only takes two or three minutes. The file size of this virtual machine disk image is 120GB.
cause of issue
After investigation, it is found that the actual space occupied by the virtual machine image on the new machine is 120GB, while the one on the old machine is 5.5GB. The qemu-img convert
image format conversion is called every time when cloning on the new machine. This process is very slow.
Solution
Use qemu-img convert
the copied image for a format conversion and replace it with the converted image file. The command is as follows:
# qemu-img convert -f qcow2 -O qcow2 /data/template.qcow2 /data/new-template.qcow2
# mv /data/new-template.qcow2 /data/template.qcow2
# virt-clone -o template -n new-host -f /data/new-host.qcow2
Troubleshooting process
View disk IO
Install the rpm package sysstat, run the iostat -d 2
command during cloning, and find that the disk write speed is very low. But when copying an ISO disc image file to this disk, the speed is more than 150 MB per second, indicating that the disk IO is no problem.
View CPU and memory usage
I used the top command during cloning and found that there are a lot of memory buff/cached, and the qemu-img process consumes a lot of CPU. ps -ef | grep qemu-img
You can see the process details and check that the process is virt-clone
started through the PPID of the process .
Compare information about disk mirroring
By running ls -lh /data/template.qcow2
and du -sh /data/template.qcow2
commands on the new and old machines, it is found du -sh
that the actual occupied space of the files displayed on the new and old machines is 120GB and 5.5GB respectively. qemu-img info /data/template.qcow2
You can also check the disk size actually used by the mirror.
Cause Analysis
When using scp to copy the image file, the empty space in the qcow2 file is also written to the disk as the actual content, which causes the actual size of the disk file to become very large, and it is very slow during cloning.