Virtual Machines are an incredible resource in modern-day software development. This bird does all his development in VMs. Being contractors and servicing many disparate clients, VMs allow us to keep copies of various clients’ development environments, ready to run at a moment’s notice. No de-installing / re-installing, searching for the correct version of Visual Studio, etc. And nothing done during development can affect one’s everyday host environment. Testing an application on several different “clean installs” of Windows would be hugely resource and time intensive without VMs.
We use VMWare’s Workstation and Fusion Pro products. There are others out there, and Oracle’s VirtualBox is a very capable free alternative. VMs allow us to do Windows development on Linux and Mac OSX–our preferred operating systems.
To get the most out of virtual machines, there are a few tips that will save heaps of time (while the tips below relate directly to VMWare, all the concepts apply to VirtualBox as well):
- Understand the Terminology: Host versus Guest
The first thing to do is understand the difference between your “host” OS and “guest” OS. The “host” is your workstation and your usual OS, and the “guest” is whatever OS your running inside the VM.
- Use Clones
Clones are likely the most under-used feature of VMWare and VirtualBox. Cloning is making a copy of the VM under a different name. There are two major types of clones:
A complete, full-size copy that is totally independent of the original VM image.
A smaller copy that is dependent upon the VM base image from which it was cloned. Linked Clones are extremely useful for working between two or more different hosts. Linked clones are a fraction of the size of the VM (“base image”) from which they were cloned, and they contain only the changes made since the clone operation. Once a linked clone is created, treat the base image as read-only and open the linked clone when starting the VM.
- Increase Performance with Linked Clones
To get the best performance possible, create a Linked Clone and store it on a separate drive/controller from the base image. This spreads the workload over two different disk controllers, increasing throughput.
- Increase Portability with Linked Clones
When working on two different hosts, say one’s laptop and one’s desktop or one’s “work” workstation and one’s “home” workstation, create a linked clone and store the base image on a read-only volume on each host. Then all you need to do is carry the “clone image” back and forth between workstations. The clone image contains all the changes made, and it is able to run off either copy of the base image. No need to transport the base image which doesn’t change. Often a base image is 30GB in size while the clone image 3GB or less. Of course, it all depends on the number of changes and amount of work done on the clone, but the point is the 30GB+ base image never changes and doesn’t need to travel with you between workstations.
- Snapshot after Cloning
Snapshots save an image of the state and content of the VM at a point in time. They are very useful as rollback points. One may rollback to a snapshot at any time, completely restoring the state and content of the VM to what it looked like at that point in time. After creating any clone, it is beneficial to create a “baseline” snapshot. Indeed a snapshot is critical to the linked clone process because the linked clone images need a savepoint to refer to in the base image. When creating a linked clone in Windows VMWare, one can choose which snapshot to base the clone on. I’ll expand on this topic in a subsequent post.
- Use Shared Drives
Share drives are another underutilized feature of VMs. It is possible to create drive mappings in the guest that refer to directories on the host. Anything saved to a shared drive gets saved directly to the host system instead of inside the VM. Of course it is possible to drag-and-drop from the host into the VM, and out of the VM onto the host, but Shared Drives allow applications to save to the host disk as well.
- Mind the Linked Clone Size
Because the liked clones record every disk-related action done during a VM session, they can grow quickly. One can use disk-cleanup to manage this, or the best way is to periodically create another full-clone from the linked clone. The full-clone process cleans-up the disk and shrinks the VM as much as possible into a new VM file. Then you repeat the linked clone process.
- Clone Frequently
Making frequent full-clones keeps the VM to a manageable size. Without making frequent clones, one will end up with a huge VM file that doesn’t perform well.
- Use Snapshots
As mentioned above, Snapshots are a great way to return to a know state or point in time. Snapshots may be made while the VM is running or powered down. Powering down the VM prior to taking a Snapshot is preferable primarily because it can be difficult to start a VM with a “running” snapshot on a different host and CPU.
- Disk Clean-up and Defragment
Frequent disk clean-up and defragmeting (of the VM disk) can recover large amounts of disk space otherwise occupied by the VM file. Defragmenting the VM disk increases the VM’s performance.
- Power-Down before Snapshots and Transport
Always power-down the VM before transferring it to another host machine to avoid trouble caused by running up the “running” state of the VM on the destination host’s different CPU.
All of these tips apply to VirtualBox as well, although VirtualBox is somewhat more difficult to manage. It doesn’t accommodate host changes as well as VMware does, although most problems can be overcome with some editing of config files.
We hope these tips will encourage you to take advantage of all the benefits offered by virtual machines. Let us know if you have any favourite tips…