Would you check if my understanding of immutable images is correct?

This is for discussing general topics about how to use VirtualBox.
Post Reply
Rhythmdvl
Posts: 12
Joined: 15. Oct 2015, 22:22

Would you check if my understanding of immutable images is correct?

Post by Rhythmdvl »

I am using VirtualBox 6.1.18. If it matters, it would be a Linux guest.

My goal is to create and set up a new guest as I want it (e.g. run updates, change user settings, install programs), and then lock it into that state so that any file, system or other changes are completely discarded at shutdown. The next time I load the machine, I want it to be exactly as it was after I finished setting it up.

To do this, I’d create a new guest with a dynamic vdi just as I normally would, including installing the OS, running updates, installing programs, changing user settings, etc.

Then I’d shut down the guest, open Virtual Media Manager, select the guest’s vdi entry and change the attributes>type drop-down to “immutable.”

From that point on, no matter what I (or a malicious website or new program) does to the guest, those changes will be discarded at shutdown — the guest will remain identical to what it was the moment I changed its vdi entry to immutable. Even if I browse with minimal protections, not even a cookie will remain (not that I would; this is just an example).

When I want to install updates, I would load a fresh instance of the guest, install the updates (or make other changes), then immediately take a snapshot in VM Manager. Any changes made after that snapshot will be discarded

When I next start the guest, VBox will automatically combine the original vdi plus the snapshots I’ve taken, starting with the most recent one.

I do not need to shut down the guest before taking the snapshot. It’s simply called an “online snapshot” and there is no functional difference (to me and what I’m trying to do). All changes made during the same session after taking that snapshot will be discarded.

If the above is correct, I’m a little unclear about a couple things.

How do I clean up snapshots? I’m likely to end up with a lot of them, especially in the early days when I make lots of small changes (e.g. changing a NoScript trust setting).

My thought is that I would:
  • Shut down the guest
  • Use Media Manager to change the guest’s vdi back to ‘normal’
  • Start the guest, which will load all changes recorded in the snapshots and write them to the vdi (bolding because I’m not sure if this is true)
  • Shut down the guest
  • Use Media Manager to change the guest’s vdi back to ‘immutable’
  • Use VBox Manager to delete snapshots starting from youngest to oldest. Doing it this way means Manager won’t have to write differences between each snapshot, making the deletion process much quicker.
  • Restart the guest. It will reflect all updates, etc. from all the snapshots, but because the vdi’s state is back to ‘immutable’, all future changes will be discarded.
Is the above correct and the ‘right’ way of doing this? Or should I treat the collection of snapshots like I would for a regular guest?

Lastly, am I correct that having access to a shared folder (one that other guests and the host can see) is irrelevant — that none of the above affects this shared folder in any way? If I load a file from the shared folder and save back to the shared folder, there is no risk of loss of data or access. The only loss would be if saved a version to the guest.


Thanks~
fth0
Volunteer
Posts: 5677
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Would you check if my understanding of immutable images is correct?

Post by fth0 »

Actually, there is a mistake in your description, and understanding this will make life easier for you:

While the VM with the immutable image is running, the changes are written to a (writable) differencing image. When the VM is powered down, this differencing image is not deleted. When you power up the VM the next time, then this differencing image is deleted beforehand.

The advantage of this behavior shows when you want to update the immutable image: You run the VM as usual, make the wanted updates and power down the VM. Then you can simply create a snapshot while the VM is powered down, which changes the (writable) differencing image to read-only. From then on, the original immutable image and this read-only differencing image (snapshot) behave together like the original immutable image. Changes are written to a third (writable) differencing image ...

You can imagine the original immutable image and the other snapshot images as points in time (like the Windows Restore Points). In the VirtualBox Manager, you can select any of those snapshots and Delete it, which will merge the contents of the corresponding image with one of its neighbors. Note that the original immutable image is simply a first snapshot, which can likewise be deleted and merged together with the first differencing image. The order of deletion doesn't really matter, but I usually prefer starting with the oldest. For example, in a snapshot chain A-B-C-w (w being the writable differencing image), if you want to keep C, you can start by deleting A, giving (AB)-C-w, then deleting (AB), giving (ABC)-w. Alternatively, deleting B first gives A-(BC)-w, then deleting A gives (ABC)-w.

The behavior of immutable images and differencing images is described inside the VirtualBox User Manual, see 5.4. Special Image Write Modes and 5.5. Differencing Images.
Post Reply