Corrupted VDI header

Discussions related to using VirtualBox on Linux hosts.
Post Reply
dms
Posts: 3
Joined: 23. Dec 2021, 15:07

Corrupted VDI header

Post by dms »

I have a Freebsd (11.2) VM running on a Freebsd Host using Vbox (5.2.44_3) which has been running fine for a couple of years.

Recently I filled the virtual disks of the guest VM as per my usual method (dd command to fill a file with 0's) and then shutdown the VM down and compacted the disks.

Since then twice in the last two weeks my daily pause-the-machine take a zfs snapshot and then restart-the-machine backup system has failed to restart the VM with the error. Notably this does not happen every time. The first time this happened I went back to a zfs snapshot from a few days prior and the VM restarted fine, only to give the same error some 8 days later.

VMSetError: /wrkdirs/usr/ports/emulators/virtualbox-ose/work/VirtualBox-5.2.44/src/VBox/Storage/VDI.cpp(861) int vdiImageReadHeader(PVDIIMAGEDESC); rc=VERR_VD_VDI_INVALID_HEADER
VMSetError: VDI: invalid header in 'vdiname.vdi'

vboxmanage internalcommands dumphdinfo vdiname.vdi

Header: Version=00010001 Type=4 Flags=0 Size=22548750336
Header: cbBlock=1048576 cbBlockExtra=0 cBlocks=21505 cBlocksAllocated=18002
Header: offBlocks=1048576 offData=2097152
Header: Geometry: C/H/S=1024/255/63 cbSector=512
Header: uuidCreation={c790d775-55d0-4275-895a-17867c214945}
Header: uuidModification={9a34b038-b88f-4aaa-80fd-24261a011c03}
Header: uuidParent={4845edac-bf3a-4a3d-a2f7-d64ee353b742}
Header: uuidParentModification={024d7403-dc3d-4f3a-b9f7-d1184e437ffa}
Image: fFlags=00020000 offStartBlocks=1048576 offStartData=2097152
Image: uBlockMask=000FFFFF cbTotalBlockData=1048576 uShiftOffset2Index=20 offStartBlockData=0
!! WARNING: 6053 blocks actually allocated (cBlocksAllocated=18002) !!

I've tried the "vboxmanage internalcommands repairhd" which did nothing.
I've also tried the transfer of the first 512 bytes from a clean backup to the damaged file and this does not generate a working vdi.

Any suggestions on recovery or what is going on? I assume the vdi has become corrupted since the compaction procedere but it is odd that it does not fail immediately.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Corrupted VDI header

Post by mpack »

Topic moved to "Linux Hosts".

Try the repair function in CloneVDI. You officially need to run it on a Windows host, though others have successfully used it under Wine on Linux hosts.
dms
Posts: 3
Joined: 23. Dec 2021, 15:07

Re: Corrupted VDI header

Post by dms »

I've tried CloneVDI 4.01 but it's a differencing VDI and repair is not supported.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Corrupted VDI header

Post by mpack »

You corrupted a snapshot? In that case it's gone. Snapshots are not repairable - that's one on a long list of reasons why experienced users avoid them.

Since I assume you don't have a backup, the best I can suggest is that you use CloneVDI to clone the most recent snapshot it will agree to clone. That will give you a stand-alone merged VDI. Now build a snapshot free VM around that clone VDI.

p.s. I suggest you don't try that "transfer of the first 512 bytes from a clean backup" trick again. That is only one step in a chain of tricks to be used by someone who knows what he's doing. I.e. it would be following by hacking the header to get it perfectly describing the VDI again, otherwise you still have a corrupted header as far as the software is concerned. Plus the educated guesses needed to fix the header description don't work for snapshots anyway.
dms
Posts: 3
Joined: 23. Dec 2021, 15:07

Re: Corrupted VDI header

Post by dms »

Thank you for the confirmation the snapshots are not repairable and I'm stuck.

I do have backups from before the header corruption from the ZFS snapshots I referred to. It's not very convenient to go back that far albeit it the machine in question is a standby so no data will be lost (if I restore a version before anything happens to the main machine).

So I'll chalk this down to experience, albeit stopping the machine to get a ZFS snapshot and then restarting it is a world less convenient than pausing it, ZFS snapshotting it and resuming.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Corrupted VDI header

Post by scottgus1 »

I'll just add in one thought regarding the "pause the VM for a backup" concept: It is not good.

The backup is of a paused OS. The paused OS does not know it was paused, so it cannot close files, start a volume shadow copy, set up open databases for backup, etc. The backup contains an OS that has for all intents and purposes been powered off unexpectedly. You'd have to deal with the corrupted data of such a powered-off OS.

The best backup of a running OS, physical or virtual, is done by 3rd-party backup software that is compatible with the OS and services/databases being backed up. Then the VM OS can properly prepare itself and its services for backup.

Back up the VM on the host while it is shut down. Your ZFS snapshots might be OK here. Then if the VM needs to be backed up while it is running, leave the VM running, run the 3rd-party backup software, and save the backup image off the VM into a host shared folder on a different physical disk. Then if the
Post Reply