Tag Archives: VirtualBox

Moving a Virtual Machine Image in VirtualBox 4.0.10

I have a testing environment for our deployable application MSI here.  It’s a licence of Windows XP running in a virtual machine courtesy of VirtualBox (I’m a big, BIG fanboy of free virtualisation).  In essence, it’s a fully updated Windows XP environment with all the prerequisites loaded, ready for the MSI to be installed for the very first time. Whenever I want to convince myself that the MSI will install into a “new” XP environment, I can try it out.  Once I’m satisfied, I can rewind back to a snapshot of a pristine environment.  All Registry, GAC, User and/or application configuration mess disappears. Isolation testing when I can see before and after changes to an Operating system that hasn’t seen our application before has already delivered gold several times.

I’ve come to depend on this isolation testing approach so much that it’s time I got serious about backing up the virtual machine image. Now, I installed VirtualBox without thinking about backups initially.  I’ve learned that by default, my virtual machine data is being written to my user “Documents and Settings” directory.  It’d be a lot more convenient for my to have them under my D drive which is already set up for no-hassle backups of the development environment.

In my naivety, I thought it would be as simple as just copying the virtual machine directory from “Documents and Settings” through to my D drive. Doesn’t work. The virtual hard-drive image file is marked with a UUID that very tightly couples it to its virtual machine.  I can’t even just change the file name without VirtualBox complaining long and hard that this is NOT the hard drive image it’s looking for.

After some frustration trying to get VirtualBox to use copied drives, virtual machines and snapshots, I gave up and consulted google.  I tried (and tried) to follow the instructions here, but they failed me miserably.  I really should have looked at the timestamp on this post. I finally read the entire, long comment history which lead me to gold.  Things are much easier than they were back then, and I’ve just spent the morning jumping through rings of fire whilst whacking an angry bear with a foam bat, when I could have lazily told VirtualBox to just “Make it so, No. 2”.

The first thing I need to do is to export the currently selected virtual machine image via the menu item “Export Appliance…” thusly:

Screenshot showin the exporting a VirtualBox image

Exporting a VirtualBox image

Then, I remove the image from VirtualBox (leaving the file structure intact, just in case it all goes pear-shaped) thusly:

Screenshot of the removing a VirtualBox Image

Removing a VirtualBox Image

Now, because I want all my VirtualBox shenanigans backed up, I change the default folder for new virtual images thusly:

Screenshot of setting the Default Machine Folder in VirtualBox

Setting the Default Machine Folder in VirtualBox

I next import the saved virtual machine export, being guided by the import wizard (not shown):

Screenshot of importing a virtual machine in VirtualBox

Importing a virtual machine in VirtualBox

And whallah, one moved virtual machine environment, sans the heartbreak required circa 2008:

Screenshot of the VirtualBox Image in its new home

VirtualBox Image in its new home

Finally, a word of warning:  The export will roll all your snapshots into one “current” one.  If you’re in love with a deeply nested set of snapshots (like say, Windows straight of the install CD, then another with all the updates laid down, etc), they will be gone in your moved image.


P*ssing in my WordPress Sandpit

For a while there, I had a sandpit environment for my parent’s webpage. The sandpit was a XAMPP install, running in a virtual Ubuntu machine via VirtualBox.  I eventually got around to an upgrade of VirtualBox, and the old snapshots wouldn’t play ball with the upgraded environment. So, the task I set myself tonight was to recreate the sandpit from the live WordPress install out at my ISP.  Turns out it wasn’t that simple to achieve.

First, I’ve been lazy with my Ubuntu kernel installs, and I’d forgotten which kernel I installed my latest VirtualBox with.  The first thing I did tonight was to purge all my unused kernels, and start with a fresh install of VirtualBox in the last kernel standing. To get get my monitors and desktop playing at full capacity, I needed the guest additions installed. Once I had a blank virtual OS with guest additions, I took my first snapshot (what a lifesaver when things stuff up, and tonight was full of reversions to previous snapshots).

Next, I laid down XAMPP, Freemind and Dropbox for locahost web-hosting, notes to self on all things web-page related, and easy file transfer across environments respectively, resulting in my 2nd snapshot.

Once that was done I needed the following in order (remember me saying I was backtracking alot?  The approach below isn’t exactly how the night went):

  1. dropped the entire WordPress directory zip file from my ISP into a new subdirectory of opt/lampp/htdocs
  2. Built a MySQL database and user to match what I’d set up at the ISP
  3. Imported the content of the live ISP database to the sandbox localhost database
  4. Modified the wp-config.php file to look at localhost instead of the ISP MySQL URL
  5. Switch off networking on the virtual machine briefly
  6. Step into the sandbox MySQL database, and modify relevant fields in the wp_options table so the sandbox environment wouldn’t go out to the live site and f**k it all up on me (the URL fields are the culprits)
  7. Switch networking back on within the sandbox, and whallah. Working copy from the live system that plays nicely.

And now I have a 3rd and final snapshot that I can try various shopping-carts out on before committing to a particular flavour.

I’ve learned tonight that the WordPress file backup and its matching MySQL backup go hand-in-hand for replicating the web-site across environments. I’ve also learned that the current backups sitting out at my ISP saved my bacon once I realised that the wp-admin screen in the sandbox was going out to the live site, and causing me to lock myself out of the live system, which suddenly thought its URL was based on a localhost address. DO NOT allow the sandbox to talk to the wider network until it’s happy to serve everything up locally Linds. JUST F**KING DON”T!

Might pour myself a stiff drink before I crash. Shaky nerves and all that jazz.