Immutable virtual machines with virtualbox

From time to time I need to use some Windows-only program.

And from time to time, those programs are also relatively old.

Normally I would first try the application under WINE. If it does not work, last time I even tried the newest version of ReactOS.

The last and normally infallible approach is starting a virtual machine with Windows.

It always feels like an abuse of resources.

For running a program, I need to "throw away" 50 GB of spaces, consume 2 GB of RAM and so on.

Yes, the hardware might be getting cheaper and cheaper, but systems are not getting faster and faster. Also, people advocating the new hardware prices are not paying or upgrading my machine, so excuse me if I’m trying to use my resources in a better way.

I have an old Windows XP Professional SP3 iso (wow, only 600MB) and installed the system in VirtualBox.

As Windows XP is an OS from 2000, system requirements are completely different. 512 MB of ram and a 10GB disk are much more than enough for the operating system.

Actually, the freshly installed copy used less than 2 GB of space and used less than 128MB of ram. Nothing compared to what Windows 10 needs today.

I could even complete the registration, even after 5 years the system has been discontinued.

But the point of this article is not about retro-computing.

The first issue was how to secure the operating system, as the application required an internet connection, even if I would use it only for a couple of minutes.

A feature I did not know about VirtualBox, is that it’s possible to create a immutable drives.

The process works on any guest system.

For the operating system, nothing changes. It can read and write on the virtual disk as before. After shutting down the system, VirtualBox will restore the previous state of the disk.

Thus, even if the system gets infected, or more generally if I manage to screw the virtual machine or do not need to store/change its status, I do not need to "manually" create and restore snapshots.

The first step is to detach the disk from the virtual machine, this is done from the "Settings", "Storage" properties. In the upper left corner, it is possible to notice that the disk is not marked as immutable.

normal disk
Figure 1. VirtualBox - storage view with a normal disk

From the "Virtual Media Manager", select the disk, and change the "Type" from the dropbox the value from "Normal" to "Immutable". Apply the changes and close the window.

media manager
Figure 2. VirtualBox - media manager

Now add a new disk to the virtual machine, when asked, "Choose an existing disk", and select the desired virtual disk.

VirtualBox - add disk

add disk

From the "Storage" properties, the disk should be labeled as immutable.

immutable disk
Figure 3. VirtualBox - storage view with immutable disk

Similarly, remove the disk, change the property, and readd the disk, these changes can be reverted.

It is important to detach and reattach the disk, otherwise what is described in the GUI might not be the actual settings, causing confusion.

Behind the scenes, Virtualbox uses a snapshot of the virtual disk.

As the virtual machine gets reset after every shutdown, if you have any data to save, save it in the shared drive, otherwise, it will be wiped.

It is possible to edit the disk properties from the "Virtual Media Manager" while it is attached. The properties of the disk where are shown consistently in the VirtualBox interface, but the disk will not change from "immutable" to "normal", as the virtual machine will be attached to the snapshot that was created when the disk was set to immutable.

Long story short, to avoid any type of surprises:

  1. Detached the virtual disk

  2. Make the virtual disk immutable (or normal if it was immutable) from the Virtual Media Manager.

  3. Reattach the virtual disk.

If you’ve got an inconsistent state (disk is normal, but changes do not persist a shutdown)

  1. Detached the virtual disk

  2. remove unused disk snapshots from "Virtual Media Manager"

  3. Reattach the virtual disk.