Managing Your Virtual Machines in VirtualBox

As developer testing your software on different system configurations and versions of operating systems is a good way to improve quality of your application. But how would you do it?

Installing multiple operating systems on your computer might solve the issue but you won’t like it. It will cut your hard drive into multiple partitions and eat free space from the partition used by your primary system. Also managing such setup is not easy. Easy OS will update differently. You will need to install required applications as many times as many operating systems you will install.

In addition this will become more difficult if your software depends on another product. Which of course has also different versions and does not offer portable deployment. What than?

Fortunately Virtual Machines has been invented. However managing them in efficient way might be very tricky.

This article will describe my current setup of virtual machines in VirtualBox and best practices which I have came with. 

As a developer you will probably need to work sometimes with different systems to test something, debug something or check something. Than I would recommend you to use VirtualBox. I won’t describe how to create your first VM as I expect you are already familiar with it. This article is for those, who are now struggling with their VMs and ask how not to make mess in them.

In a short:

  1. Learn how to use snapshots, use them a lot.
  2. Think in advance (this article is good way to start).
  3. Learn how to use clones.

Snapshots

What are snapshots? It’s persisted state of your virtual machine to which you can revert any time. It’s like restore points in Windows but on a very base level – on VM level. You can take snapshot from powered off system as well as from running or paused system. Basically it will save current HDD state, RAM, processor state, etc. of your virtual machine. That is very handy.

After snapshot is taken, any changes in VM are recorded as difference to last snapshot. The result is no data are duplicated after taking snapshot. Thats an important feature to have in mind.

Snapshots are composed into a tree. Each snapshots has parent snapshot set except for the first one which is the root of the tree. What it means? When you install/configure/do something in your Virtual Machine and take snapshot of that it will be present in all derived snapshots. That is another important feature worth mentioning.

Best Practices

  • Again, use snapshots a lot.
  • Prefer snapshots of powered off system to paused or running system. Even though it’s inconvenient to setup it will save you some hard drive space.
  • Fill in descriptive snapshot names and description. Really do. It’s important not to lost track of changes made by snapshot.

Thinking in advance

This is closely related with the previous paragraph. Try to think of all supplementary software or configuration you will need in future while working with your virtual machine. Having it installed in some base snapshot you won’t need to install it multiple times which is both annoying and time consuming and space consuming.

By supplementary software I mean all handy applications where you don’t need to track their version. It might be 7zip, Java, PDF viewer, text editor, total commander even though some IDE.

If you forgot to install some software you will need in common snapshot you would have two options:

  1. Install it separately on all derived snapshots (which will make you swearing).
  2. Remove all derived snapshots and correct your base snapshot, than recover deleted snapshots by manually making changes again (will will make you even more swearing and maybe destroying close-by things).

Therefore think twice before branching snapshots.

Best Practices

  • Install all supplementary software at base snapshot.
  • I would recommend using Ninite. It will install most common applications itself, you won’t need to go through every single installer. It will save you a lot of time.

Clones

Cloning your virtual machine will result in a copy of selected virtual machine at current state or selected snapshot. There are two types of clones, primarily the latter is similar to snapshots:

  • Full Clone
  • Linked Clone

Full Clone will copy all the virtual machine data and make a new machine based on this copy. There fore full-cloning will take up that much space as base virtual machine takes. All virtual machine files are duplicated.

Linked Clone will create a new virtual machine, but virtual hard drive won’t be copied. Instead new hard drive will be made and will link to the base virtual machine hard drive in given snapshot. Linked clones are therefore space-efficient. It’s like making snapshots but with new virtual machine being created.

Best Practices

  • Understand differences between clone types.
  • Prefer linked clones to full clones (it will save you hard drive space).

Example

Putting all advices together I will show you some example how to manage virtual machines:

In this case let’s assume we need to test an Office Add-In which would be compatible with all versions since Office 2003. That counts 6 versions (2003, 2007, 2010 32-bit, 2010 64-bit, 2013 32-bit and 2013 64-bit). We do not have any VM installed.

Creating Base Virtual Machine

  1. Create new virtual machine called “Windows XP Sandbox”.
  2. Install operating system to the machine.
  3. Log in for the first time and do not install any updates.
  4. Configure your desktop icons and task bar (you might want to turn on Quick Launch).
  5. Configure your mouse and keyboard (you might want to turn off mouse acceleration).
  6. I recommend you to turn off system restore at this point.
  7. Clean up hard drive from temporary files.
  8. Turn off the machine and take first snapshot of the machine called “Raw Install”.
  9. Run machine and install Guest Additions. Still do not install any updates. Restart and adjust resolution, than turn off VM.
  10. Clean up hard drive from temporary files.
  11. Take second snapshot called “with Guest Additions”.
  12. Run machine, install all available system updates, clean up hard drive and turn off.
  13. Take third snapshot called “Updated Install”.
  14. Run machine, install supplementary software (eg. using Ninite), clean up hard drive and turn off.
  15. Take fourth snapshot called “with Apps”. I recommend to include installed apps into snapshot’s description.

This machine represents “virgin” installation of operating system with supplementary software. You might reuse it any time later. I think you have the idea.

Installing Office VMs

For each Office version do:

  1. Create linked clone of the base virtual machine created in previous section and name it “Windows XP Office <version>”.
  2. Run machine and install given Office version and turn off.
  3. Finally of course take snapshot called “with Office <version>”.

Conclusion

I hope you found this article helpful and you got the idea. I believe management of your virtual machines will be now easier and less frustrating. Finally a few notes which I did not know where to put them:

  • Yes, you will need one base virtual machine for each OS you want to play with.
  • I’m not sure if installation of your IDE should be included in base snapshots or not. IDE is space consuming and you won’t need it in most of the cases.
  • If you use shared folders, share them in base snapshots as this information is also stored in snapshots.

Comments are closed.