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:

Error I get after the reboot

Is there anything I can do?

  • 1
    Restore from your backup. May 17 '16 at 10:38
  • You might be able to save at least something if you: resize to original size, then run kpartx -a on the file, which will create loop device and read partitions. Then you might be able to save some partitions,
    – Martian
    May 19 '16 at 9:05

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.

  1. Try to recover the file.
    • In one attempt try using extundelete.
    • In second attempt simply resizing to its original size.
    • In third and next attempts I have not idea what else you could try, but you can still ask...

For each of those:

  1. Copy the disk.raw file! Always work on a copy.[1]
  2. Run kpartx -a on the file, which will create loop device and create DM devices for partitions.
  3. Run lsblk, blkid and update the question with output so at least the layout is known. You first 50GB are "safe", but hard to say what data that is...
  4. Now you might be able to save some partitions/logical volumes, and some files from incomplete ones after running fsck.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.