Updated: January 22, 2021
One of the cool things about VirtualBox is that it lets you create snapshots of your virtual machines. You work, you save a state, you make changes, and then you conveniently revert back to the saved state. You can branch any way you like, create snapshots with the virtual machines running or stopped, and the functionality provides you with a lot of flexibility - and determinism - as you can consistently re-test known system states over and over.
The uncool thing about snapshots is that they take quite a bit of space. I noticed that one of my virtual machines, with an expected footprint of only about 11 GB was actually taking 46 GB of disk space. And as you can imagine, there were snapshots - a total of seven different saved machine states. This ain't bad, but what if you no longer need the snapshots and want to compact them, i.e. flatten them, i.e. merge everything down and trim down on disk usage? Let's explore this further.
How do you merge snapshots in VirtualBox?
This is actually a non-trivial question. There isn't a magic button that can just layer all the different snapshots quickly. What you can do is, manually delete snapshots under the current one - one by one. This will make VirtualBox merge the changes, a process that can take quite some time.
Luckily, there's a faster alternative - cloning. We talked about cloning several times in the past - mostly for the purpose of virtual machine resizing. If you have created a virtual machine with a disk that has become too small for purpose, you can resize the disks - but this ONLY works if there are no snapshots. In that tutorial, I showed you how to clone a machine (and collapse snapshots), and then resize the disk. Essentially, that's all we need for the job. But for the sake of clarity, let me demonstrate step by step.
Virtual machine cloning
If you select any which virtual machine in your list inside the VirtualBox Manager, you will see the Clone button in the menu above the right pane. Click the button and follow the wizard. There are quite a few details, but the important ones are as follows. First, select the Clone type. You want a Full Clone. Second, select which snapshots you want to preserve. We need: Current machine state. Now, if you go for the second option (Everything), this will not give us any disk space saving benefits.
You can also clone network addresses, disk names and hardware UUID - this can be extremely useful, because then you won't really need to worry about any potential conflicts whereby a seemingly identical operating system sees "different" hardware. You will be making an identical clone.
Press the Clone button and let the magic happen. The process will take some time - it depends on the size of your virtual machine, the disk usage, and your system resources. But overall, the process will take about as much as it takes to collapse a single snapshot, so if your virtual machine has multiple snapshots, you automatically gain time.
Once the process is complete, you can use your cloned machine right away. I tried multiple variations, including a suspended virtual machine, and it worked perfectly fine. The clone resumed right where the original system was, including open windows and applications. All of it. The only difference was that the snapshots were gone, and once I deleted the original machine, I had gained back a significant chunk of disk space.
Conclusion
There you go. Same same but different. While this article does not differ significantly from the tutorial I provided you on disk resizing, it does focus on the cloning part only. You have two ways you can go about managing your snapshots - and disk space - with VirtualBox machines, but the full cloning process is faster than manually deleting individual snapshots. However, the latter method does allows you to retain some of the snapshots, or alternatively, only collapse specific ones. For instance, you could collapse the oldest snapshots, but keep the last three.
Well, hopefully, you will find this guide useful. VirtualBox has tons of nice features, and it's really a handy tool for the entrepreneuring nerd. Snapshots are highly practical, but they do tend to lead to increased disk space usage. Considerably so. If you're ever short of GB on your platter or wafer, you can selectively clone virtual machines or delete specific snapshots to get some of that fine digital equity back. We're done.
Cheers.