Before attaching a disk image to a virtual machine (VM), ensure that the disk image does not have problems, such as corruption or high fragmentation. To do so, you can use the qemu-img check command.
Before you begin
- Any virtual machines (VMs) that use the disk image must be shut down.
About this task
If needed, you can also use qemu-img check to attempt repairing the disk image.
Procedure
-
Use the
qemu-img check command on the image you want to test. For example:
# qemu-img check <test-name.qcow2>
No errors were found on the image.
327434/327680 = 99.92% allocated, 0.00% fragmented, 0.00% compressed clusters
Image end offset: 21478375424
If the check finds problems on the disk image, the output of the command looks similar to the following:
167 errors were found on the image.
Data may be corrupted, or further writes to the image may corrupt it.
453368 leaked clusters were found on the image.
This means waste of disk space, but no harm to data.
259 internal errors have occurred during the check.
Image end offset: 21478375424
-
To attempt repairing the detected issues, use the
qemu-img check command with the -r all option. Note, however, that this might fix only some of the problems.
Warning
Repairing the disk image can cause data corruption or other issues. Back up the disk image before attempting the repair.
# qemu-img check -r all <test-name.qcow2>
[...]
122 errors were found on the image.
Data may be corrupted, or further writes to the image may corrupt it.
250 internal errors have occurred during the check.
Image end offset: 27071414272
This output indicates the number of problems found on the disk image after the repair.
-
If further disk image repairs are required, you can use various
libguestfs tools in the guestfish shell.