How to Repair a Corrupted VirtualBox XML File

VirtualBox is definitely high up on our list of favorite Open Source Software tools. Besides being free, powerful and easy to use, VirtualBox is an excellent virtualization solution for older hardware. We recently installed VirtualBox on an older Dell laptop with only a 1.7GHz Pentium M processor and no dedicated graphics chipset. We had previously maxed the RAM out to 2G so, we had a fairly decent amount of memory to allocate to our Guest Operating Systems. Memory and disk space are rapidly consumed by virtualization software so, we recommend running VirtualBox on a system with 2g of RAM or more, and a hard disk with at least 10G of space to spare. Of course, the first thing we did was see how far we could push our laptop, with VirtualBox running applications inside of a Guest OS, while throwing our normal workload at the Ubuntu 10.04 Host OS, and the answer was,¬†pretty far… until we inevitably broke it. That’s what we like to do here, break stuff…

We managed to crash the whole system, which led to some data loss and a corrupted VirtualBox XML file, which is necessary for running the Guest operating systems. Fortunately, the fix is quick, painless and requires no software reinstallation, other than possibly corrupted Guest Snapshots, which is one of the greatest reasons for using virtualization software in the first place. If the last Snapshot becomes corrupted, one can simply restore to a previous state without reinstalling the entire Guest OS. If you managed to crash your system like we did, and upon starting up a VirtualBox Guest OS, you received an error message similar to this one:

Then, you’re probably in luck! We found the cause of this error message on our system was simply a corrupted XML file, which only took us about a minute to repair. This error state was caused by our system locking up and preventing VirtualBox from finishing writing out to it’s configuration file. You can see from the screenshot above that the first part of the error message states:

Premature end of data in tag VirtualBox line 2.

Simply stated, this means that the opening <VirtualBox> tag on line 2 of the file does not have a corresponding closing </VirtualBox> tag at the end of the file. We can discern this by the second part of the error message:

Location:’/…/…xml’, line 714 (2), column 1.

The quickest way to find out if this is what caused your error state is, locate your VirtualBox XML file for your Guest OS, which can generally be found under your home directory here:

~/.VirtualBox/Machines/Name-of-Your-Guest-OS-Directory/Name-of-Your-Guest-OS.xml file

Open this file up in a text editor and go to the last line of the file. If you don’t see a closing </VirtualBox> tag, your file is corrupted. Start by adding this tag to the end of the XML file and work your way back from there. On our system, only the last three closing tags were missing and part of a closing tag was incomplete.

You can either look through the file for <Opening Tags> that don’t have a required </Closing Tag> or, use an XML validation service like W3C’s, found here: http://www.w3schools.com/xml/xml_validator.asp

After a few rounds of Copy -> Paste -> Validate, we had successfully repaired our corrupted XML file, fired up our Guest OS machine again and began working on new ways of breaking it. Come back soon for an in-depth tutorial on upgrading an existing VirtualBox installation, tuning it for maximum performance and importing previous Guest OS installations.

About these ads

One thought on “How to Repair a Corrupted VirtualBox XML File

  1. I had killed my ubuntu session when my VirtualBox with Windows XP was running. After trying a few things I checked the Home/.VirtualBox/VirtualBox.xml and it had a length of zero, I deleted it and recreated by copying and renaming VirtualBox.xml-prev, everything worked and I couldn’t at a glance find any differences from the previous.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s