Micro-ISV Insights BlogLooking for the Swift To-Do List Blog?

What we learned during our Micro-ISV startup journey
A blog for mISVs, startup maniacs, and everyone in the software business.

Managing Virtual Machines Efficiently in VirtualBox

email

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:

  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? 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:

  1. Install it separately on all derived snapshots (which will make you swear).
  2. 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:

  1. Install all supplementary software at base snapshot.
  2. 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).

  1. Understand differences between clone types
  2. 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

  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. Activate operating system.
  5. Configure UAC (turn off most probably).
  6. Configure desktop icons.
  7. Configure task bar (you might want to turn on Quick Launch).
  8. Configure your mouse and keyboard (you might want to turn off mouse acceleration).
  9. I recommend you to turn off system restore at this point.
  10. 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.
  11. Also configure Shared folders ASAP.
  12. Clean up hard drive from temporary files.
  13. Unmount all mounted CD/DVD images.
  14. Turn off the machine and take first snapshot of the machine called “Raw Install”.
  15. Run machine and install the VirtualBox Guest Additions. Still do not install any updates. Restart and adjust resolution, than turn off VM.
  16. Clean up hard drive from temporary files.
  17. You might want to place shortcuts to shared folders to your desktop.
  18. Unmount all mounted CD/DVD images.
  19. Take second snapshot called “with Guest Additions”.
  20. Run machine, install all available system updates and clean up hard drive.
  21. 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.
  22. Unmount all mounted CD/DVD images.
  23. Turn VM off and take third snapshot called “Updated Install”.
  24. Run machine, install supplementary software (eg. using Ninite), clean up hard drive and turn off.
  25. 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:

  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, 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.

Related Posts:

stdl

Swift To-Do List 11

The ultimate to-do list and notes software for Windows.

  • http://www.liviubalan.com/ Liviu Balan

    Nice tutorial! If you want to learn more about Snapshot and Clone in VirtualBox you can checkout VirtualBox Snapshot and Clone (video tutorial)

  • TAMIKO BLACKFORD

    Savvy article – I was fascinated by the information ! Does someone know
    where my assistant might get ahold of a template CO DoR DR 5714 copy to
    edit ?

  • Xavier Dupont

    So, I install the applications, get “with Apps”, then wait for a few months and there are new system update. If I update the “updated” snapshot, I will still have to update manually the “with Apps” snapshots, right ? What’s the use of keeping a “updated” snapshot ? It it only to be able to make new fully updated snapshot easily ?

    • http://www.weborama.cz mancze

      This is kinda elderly article and as I read it now I would put some things differently. Nevertheless I still use it time over time as a base guideline not to forget some common things when setting up VM.

      There are many cases how one is using virtual machines. For me it’s testing my applications on different systems. Otherwise I do not actively work with VM. So all article is about my use case. I don’t know what is the best way to deal with updates in VMs. I just found what is suitable for me.

      Regarding “Updated Intall” snapshot: Yes, you are certailny correct that it won’t be up-to-date in a nearly future. From this point of view it is wrongly picked name. It’s a way I tended to deal with system updates. As I start VM only occasionally and do not use it regulary I do not care about the any updates. I just want to start VM, test something and that’s it. I do not want to see dozens of notifications about updates being available. Windows actually starts them downloading on the background by default which is undesired.

      On the otherside I want the VM OS being relatively stable. Without any after-birth bugs which are common. Therefore I update VM once after installing OS and that’s it. No more updates after. Hence the “Updated Install”.

      I do not install latest versions of applications into this snapshot because sometimes it is useful to start VM without any software installed. Also one must not forget that even applications get updates. I tend to ignore them too.