HOW TO: Create Disposable VMs in VirtualBox, GNOME Boxes and KVM/QEMU/Virt-Manager

In this tutorial we’re going to take a look at how easy it is to create disposable VMs in VirtualBox, GNOME Boxes and KVM/QEMU/Virt-Manager.

In case you don’t know how to use any of the tools discussed in this tutorial, we got you covered:

 

WHAT ARE DISPOSABLE VMs?

Simply put, a disposable VM is a virtual machine that reset itself to a default state on every shut down. This means that you can install anything on it, edit core OS files ( and mess up ), possible get a virus etc. Once you shut down the VM, everything will be deleted and the VM will reset to its default state.

Similar (!) to what QubesOS offers and Amensia in TailsOS.

 

BEFORE WE GET STARTED

You can apply the process described in this tutorial on your existing VMs. However, I would suggest you create a brand new VM, which will serve as a “template” VM for all your disposable VMs.

Depending on your usecase, configure this template VM just the way you want it to be and uninstall/install the required software.

When you’re done tweaking the template VM, completely shut it down and to keep everything orginized, you might want to rename it ( i.e WindowsTVM ).

Now clone the template VM and, to continue keeping everything organized, rename it as well ( i.e WindowsDVM ).

The disposable VMs, will reset themselves only on shutdown. Rebooting/restarting the VM won’t reset it.

Once in a while, you should delete your disposable VM, update the template VM and create a new disposable VM from the up to date template VM.

NOTE: everything said above applies to all the tools. Naming the template and disposable VMs is optional. VM names doesen’t matter either. It’s up to you how you organize your VMs.

 

HOW TO CREATE A DISPOSABLE VM IN VirtualBox

1. Create a new VM which will serve as a Templete VM. Tweak the VM to your liking based on your usecase.

2. Shut down the template VM and Clone it. You don’t have to rename the clone, you can leave it as default name.

Choose to generate a new MAC Address and choose to create a full clone not a linked clone.

3. Delete the clone in VirtualBox. Only remove it from the list to unregister it. DO NOT delete the files too.

4. Open up the terminal, and cd into path to where the cloned VM is located. You will need the virtual disk image ( .vdi ).

5. Make the virtual disk image immutable by running vboxmanage modifymedium clone-name.vdi --type immutable .

NOTE: Immutable images only remember write accesses temporarily while the virtual machine is running.

All changes are lost when the virtual machine is powered on the next time.

6. Back in VirtualBox, create a new VM. Name it accordingly and go through the normal process.

The only difference is that you won’t create a new virtual hard disk, but choose to use an existing virtual hard drive file. The one that you’ve just made immutable.

7. Once the disposable VM is created, don’t forget to adjust the settings and set the CPU, video memory so on and so forth.

 

HOW TO CREATE A DISPOSABLE VM IN GNOME Boxes

1. Create a new VM which will serve as a Templete VM. Tweak the VM to your liking based on your usecase.

2. Shut down the template VM and Clone it. Rename the clone.

3. Right-click on the clone and go to Properties > System and choose Edit XML

4. In the XML scroll down untill you see the <devices> section. In that section you should have <disk type="file" device="disk">.

Just place <transient/> underneath that line and click Apply.

NOTE: when you’ll apply the changes, you’ll notice that the <transient/> will vanish. This is due to a bug. Changes were saved.

5.That’s all you have to do in order for your VM to reset everytime you shut it off.

 

HOW TO CREATE A DISPOSABLE VM IN KVM/QEMU/Virt-Manager

1. Create a new VM which will serve as a Templete VM. Tweak the VM to your liking based on your usecase.

2. Shut down the template VM and Clone it. Rename the clone.

3. In Virt-Manager, go to Edit>Preferences and make sure Enable XML editing is enabled.

4. Open the cloned VM, go to Show virtual hardware details > VirtIO Disk 1 > XML tab and place <transient/> underneath <disk type="file" device="disk">. Click Apply.

NOTE: when you’ll apply the changes, you’ll notice that the <transient/> will vanish. This is due to a bug. Changes were saved.

5.That’s all you have to do in order for your VM to reset everytime you shut it off.