I can’t believe that I’ve managed it! I recently managed to corrupt one of the virtual hard drive images on a Virtual Box image. Everytime I started the image up, it complained of problems with the Headers in the VDI file. It appears that the image file (not the guest HDD partition) had become corrupted.
This created a complete disaster for me. Unfortunately, I had been following my mantra of “Backups are for whimps” and I had potentially lost a load of work. I did have a back-up of the file going back over a month, but that was too far in the past for me. Seeing as I was convinced it was a problem with the headers in the VDI file, and that the guest partition in the file was intact, I was sure that I could correct it.
So, having spoken to a VMWare Guru at work (thanks Chris!) who convinced me he had performed a similar trick on a VMWare image, I set about correcting the image.
Firstly, I went digging. Google throws up a few instances of this problem, but most people saying it is not possible to repair the file. Fortunately, I came across this forum post which details the format of the VDI file.
Secondly, and importantly, I took a copy of the corrupted file for safe-keeping.
Thirdly, I restored my month old backup, and opened it and the corrupted file in a hex-editor. Comparing the reference material on the forum post, I noticed a few small differences, but mostly it seemed to line up after a few dozen bytes.
So, comparing the reference data, and the restored backup, I worked on the corrupted file to aline the data to what looked correct.
I saved the file, and opened up Virtual Box.
Huzzah! It worked. Restarting the VM worked well – there was a quite blip of the Linux guest complaining about an EXT4 block.
So, now it’s time for me to take another backup and then to run fsck on the guest partition!