Tuesday, April 15, 2008

Parallels Desktop Config Recovery

Do not run OS X Disk Utility's Erase Free Space feature while Parallels Desktop is running. I did that today, and my Parallels VM config file disappeared. Details follow.

Erasing free space is accomplished in a rather interesting way. Disk Utility creates one really huge file to fill up the remaining space on your hard drive, then proceeds to write over that space with 0's as many times as you choose (1-pass, 7-pass, or 35-pass). Thus, at the peak of the process, your system will indicate that your hard drive is full and suggest that you clear space (the free space alert has no awareness of Disk Utilities activities and treats the new large file like any other file). The technique involved is actually a pretty creative way of letting the operating system unconsciously collect all the free space without having to explicitly write a new routine for collecting free space. After all, allocating space for a file is just a matter of finding enough free space for said file.

Anyhow, I had Parallels running while this process was going on and I had forgotten that Parallels requires a certain amount of free space to operate. When the remaining free space dropped below the required amount (in my case 512MB, though it may vary depending on your VM configuration), the VM alerted me and presented two options: clear enough space and continue operating, or shutdown the VM. I chose the latter since I wasn't actually using right then. And that was the final blow...

When I went to restart Parallels later, I was prompted with the screen to install a new VM. WTF Parallels? What happened to the VM I already had installed and have been using for months? After some investigating, I discovered that the config file for my VM was empty. That's right, empty. The file remained, but its contents had disappeared. Not sure why, but it was disappointing to say the least.

The fact that I am a Mac user should suggest that my tolerance for Windows XP installs is rather low, so clearly I didn't want to reinstall the VM... if only I had somebody else's config file...

At this point, I had no idea what the structure of a Parallels VM config file was, but I figured that investigating that would be far quicker than an XP install. Fortunately Arjun also uses Parallels, so he sent over his config file, and I broke out the mad doctor goggles and dove in.

Turns out the VM config file is a simple properties file with [] section headers exactly like a my.cnf MySQL server/client config file. Furthermore, there are very few properties in there that really matter in terms of the VM running or not, the rest just deal with how it runs. Here they are:
App Version = 3.0.5582
Disk 0:0 image = winxp.hdd
The first could be problematic because the config file is going to need to list an App Version compatible with the version of Parallels you have installed. For example, if you upgraded to Parallels version 3.x.y from version 2.x.y, the installer reformatted your existing VMs to work with version 3.x.y. If you have version 2.x.y of Parallels, but your config file indicates version 3.x.y, I'd suspect you'd run into some problems...

The other important property there is just a reference to the name of the Parallels .hdd disk image. Since Arjun has the same version of Parallels as me, all I had to change was the name of the disk image.

The only remaining changes were smaller, but I suspect would have caused problems if I hadn't changed them too. Namely, in the [Shared folders] section, there can be references to shared folders, in which case you'll need to change the location to match your file structure. I had the following, but yours may be different.
Folder0 path = /Users/Ryan
Folder1 path = /Users/Ryan/Documents
Also, if you remove shared folder mappings, make sure to adjust this property accordingly:
Shared folders count = 2
After making those changes, I fired up Parallels and was back up and running just like before! Overall, it was a remarkably painless process to recover the VM config file if you happen to have lost it. At the very least, those few changes will get your VM back up and running, and then you can use the config GUIs to restore your specific preferences.

As a disclaimer for comments, no, I did not GLOG or RTFM for this, so if it's out there already somewhere, sorry for the duplication. In all, it was probably faster to try than it would have been to find the answer online anyway.


Anonymous said...

I see this happened a while ago, but do you know the name and location of that file? I have a similar situation, and would like to restore the file using my time machine backup.


TCR said...

I made the same mistake--thanks for the diagnosis and solution! The config file is "Microsoft Windows XP.pvs"