Testing your software on different system configurations and versions of operating systems is a good way to improve quality of your application. But how to do this in practice?
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. Each OS will update differently. You will need to install required applications as many times as many operating systems you will install.
In addition, this becomes 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 up with.
As a developer you will probably need to work sometimes with different systems to test something, debug something or check something. For this purposes, I recommend you to use VirtualBox. I won’t describe how to create your first Virtual Machine (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 of them.
In short:
- Learn how to use snapshots, use them a lot.
- Think in advance (this article is good way to start).
- Learn how to use clones.
Snapshots
What are snapshots? Snapshot is a saved 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. This can be very useful.
After snapshot is taken, any changes in VM are recorded as difference to last snapshot. The result is that no data are duplicated after taking a snapshot. This is an important feature to keep in mind.
Snapshots are composed into a tree. Each snapshots has parent snapshot set, except for the first snapshot 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 for snapshots:
- 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. It’s important not to lost track of changes made by a snapshot.
Thinking in advance
This is closely related with the previous section. Try to think of all supplementary software or configuration you will need in future while working with your virtual machine. If you install it in some base snapshot, you won’t need to install it multiple times again, which is both annoying, time consuming and space consuming.
By supplementary software, I mean all useful applications where you don’t need to track their version. It might be 7-zip, Java, PDF viewer, text editor, Total Commander, or even IDEs.
If you forgot to install into the common snapshot some software you will need, you have two options:
- Install it separately on all derived snapshots (which will make you swear).
- Remove all derived snapshots and correct your base snapshot, than recover deleted snapshots by manually making changes again (will will make you swear even more, and maybe destroy things in reach).
Therefore think twice before branching snapshots.
Best practices for thinking in advance:
- Install all supplementary software at base snapshot.
- Consider using Ninite. It will install most common applications for you, and 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. Therefore full-cloning will take up as much space as the 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, a 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 for Clones:
Prefer linked clones to full clones (it will save you hard drive space).
- Understand differences between clone types
- Prefer linked clones to full clones (it will save you HDD space).
Example
Putting all the advice together, I will show you an example how to manage virtual machines:
In this example, 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 VMs installed yet.
Creating base virtual machine
- Create new virtual machine called “Windows XP Sandbox”.
- Install operating system to the machine.
- Log in for the first time and do not install any updates.
- Activate operating system.
- Configure UAC (turn off most probably).
- Configure desktop icons.
- Configure task bar (you might want to turn on Quick Launch).
- Configure your mouse and keyboard (you might want to turn off mouse acceleration).
- I recommend you to turn off system restore at this point.
- Turn on Shared Clipboard and Bidirectional Drag’n'Drop. Even though Guest Additions are required for this features to work, the configuration will be stored in snapshot and you won’t have to think about enabling this features later.
- Also configure Shared folders ASAP.
- Clean up hard drive from temporary files.
- Unmount all mounted CD/DVD images.
- Turn off the machine and take first snapshot of the machine called “Raw Install”.
- Run machine and install the VirtualBox Guest Additions. Still do not install any updates. Restart and adjust resolution, than turn off VM.
- Clean up hard drive from temporary files.
- You might want to place shortcuts to shared folders to your desktop.
- Unmount all mounted CD/DVD images.
- Take second snapshot called “with Guest Additions”.
- Run machine, install all available system updates and clean up hard drive.
- I also recommend turning automatic updates off. Otherwise they will be bugging you every time you start VM after some time it has been inactive.
- Unmount all mounted CD/DVD images.
- Turn VM off and take third snapshot called “Updated Install”.
- Run machine, install supplementary software (eg. using Ninite), clean up hard drive and turn off.
- 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:
- Create linked clone of the base virtual machine created in previous section and name it “Windows XP Office [version]”.
- Run machine and install given Office version and turn off.
- Finally, take snapshot called “with Office [version]”.
Conclusion
I hope you found this article helpful and you got the idea. Management of your virtual machines should be now easier and less frustrating.
Some final notes:
- 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.