I decreased my KVM disk image by accident from 100G to 50G using:
sudo qemu-img resize disk.raw 50G
I wanted to increase the disk from 100G to 250G. Now the VM is not booting :( And get this message:
Is there anything I can do?
I decreased my KVM disk image by accident from 100G to 50G using:
sudo qemu-img resize disk.raw 50G
I wanted to increase the disk from 100G to 250G. Now the VM is not booting :( And get this message:
Is there anything I can do?
You cut the poor filesystem in half. If you used LVM based image it would be much easier, as it keeps history of changes to volumes and it is relatively easy to recover from resize operation. It is very unlikely to ever boot again. But you might be able to save at least something. It depends how valuable the data there were.
So if you have not done anything/much since that, and your image was not sparsely allocated, and the filesystem on the host was not very fragmented, there is a chance it was allocated in one chunk. I am not aware of a simple way to find where that chunks would be, but in case of ext4 FS on the host there is likely something in the journal. May be extundelete tool could help.
In any case you should ensure nothing writes to the filesystem where the image resided. You should ideally work using a live CD like SystemRescueCD. Do not install anything on the affected filesystem.
Ideally backup the whole disk where the image used to live. If something goes wrong, or if you get a better answer, then you can restart.
For each of those:
kpartx -a
on the file, which will create loop device and create DM devices for partitions.Now you see how important backups are...
[1]: Tip: Copying the whole disk would take ages. If you are using LVM, you could copy the image of the disk to a logical volume, create a snapshot and work on the snapshot, so the original image is not touched. Though snapshots are slower to write, you are not going to write a lot to the snapshot. Your goal is to rescue data out of the image.