KVM repair qcow2 image
- Shutdown VM.
- Make a backup copy of the image.
- Check image:
qemu-img check vmflow.qcow2
... 157 errors were found on the image. Data may be corrupted, or further writes to the image may corrupt it. 413368 leaked clusters were found on the image. This means waste of disk space, but no harm to data. 250 internal errors have occurred during the check. Image end offset: 27091599360
- Try repairing image:
qemu-img check -r all vmflow.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
- Check again, if you're lucky you might try to boot the VM in rescue mode and repair the fileystem there.
- If not, try to mount the image with nbd and fix it (eg. with testdisk):
modprobe nbd max_part=16 qemu-nbd -c /dev/nbd0 image.qcow2 partprobe /dev/nbd0 mount /dev/nbd0p1 /mnt/image
- Or with guestfish:
yum install libguestfs-tools guestfish --rw -a vmflow.qcow2 Welcome to guestfish, the guest filesystem shell for editing virtual machine filesystems and disk images. Type: 'help' for help on commands 'man' to read the manual 'quit' to quit the shell > run > list-filesystems /dev/sda1: ext4 > mount /dev/sda1 /
kvm_repair_qcow2.txt · Last modified: 2021/10/09 15:14 by 127.0.0.1