Skip to content

Instantly share code, notes, and snippets.

@Elliria
Created March 24, 2026 19:08
Show Gist options
  • Select an option

  • Save Elliria/c914d0f4e2216070e704cc1c5724436e to your computer and use it in GitHub Desktop.

Select an option

Save Elliria/c914d0f4e2216070e704cc1c5724436e to your computer and use it in GitHub Desktop.

VirtualBox Use

About

This document provides an example of creating a virtual machine in VirtualBox, cloning it, using the clone for tests, and deleting the clone. Note that cloning it is entirely optional, but can be handy for testing out software without constantly having to create virtual machines from scratch. Power-users can also use snapshots to achieve the same goal, but since those are a bit tricker to use than clones, I'm not including steps for those here.

Before you begin

When naming a new virtual machine, the name matters to the extent that VirtualBox pays attention to it, watches it for known keywords, and adjusts the VM's settings if a known keyword is detected. If, for example, you give a new VM the Ubuntu name, VirtualBox will automatically change the default Windows entries to Ubuntu entries. Alternatively, if you give a new VM the Foo name, the default Windows entries will be used and you'd need to adjust those entries manually if you wanted to use other settings.

Create a virtual machine

  1. Create the virtual machine:
    1. Download an .iso file from a Linux distribution onto your host computer (for example: from Ubuntu).
    2. Put the file that you downloaded into your default machine folder (if you don't know or remember where that is, click the File menu in VirtualBox, choose Preferences... from the context menu, and look in the Default Machine Folder text box.
    3. Click the New icon in the toolbar or click New... in the Machine menu.
    4. Type a name for your virtual machine into the VM Name textbox (for example: Ubuntu 24.04).
    5. Use the VM Folder drop-down menu to choose a folder to store your virtual machines in.
    6. Use the ISO Image drop-down menu to browse to your ISO file.
    7. Remove the check from the Proceed with Unattended Installation checkbox.
    8. Click the expansion arrow to the left of the Specify virtual hard disk entry.
    9. Verify that the Disk Slider setting is at least 25.00 GB or move the slider higher.
    10. Click the Finish button.
  2. Configure the virtual machine:
    1. Right-click your virtual machine in the left panel and choose Settings from the context-menu.
    2. Scroll down to the System section in the right pane.
    3. Move the Base Memory slider in the Motherboard tab to 8192 MB.
    4. Move the Number of Processors slider in the Processor tab to 2.
    5. Scroll down to the Display section in the right pane.
    6. Move the Video Memory slider to 128 MB.
    7. Put a check-mark in the Features checkbox for 3D Acceleration.
    8. Click the OK button.
  3. Install the operating system in the Virtual Machine:
    1. Double-click your virtual machine in the left panel to run it.
    2. Install the operating system the same way you would if you had booted your computer from a USB stick.
    3. Close the Mouse Integration...* panel on the right side of VirtualBox when it opens up.
    4. When the installation is finished and you're prompted to remove the installation medium and press the Enter key, just press the Enter key.
    5. Sign in to the operating system.
    6. Grab all the available updates.
    7. Shut down the operating system normally.

Clone the virtual machine

  1. Right-click your virtual machine in the left pane and choose Clone... from the context menu.
  2. Verify that the Full clone radio-button is selected and select it if it's not.
  3. Click the Finish button.
  • Note that when I clone Ubuntu 24.04, the clones takes up 7.2 GB of space.

Use the clone

  1. Double-click your clone in the left pane to run it.
  2. Log in to the operating system.
  3. Do your tests.
  4. Log out of the operating system normally.

Delete the clone

  1. Right-click your clone in the left pane.
  2. Choose Remove... from the context menu.
  3. Put a check-mark in the Delete the virtual machine files and virtual hard disks checkbox.
  4. Click the Remove button.
@chrislee35

Copy link
Copy Markdown

It's probably better to use the snapshot features than making a clone. It's well designed for this type of testing.

If you have the ssh set up in the VM, you can use vboxmanage to automate the restore to snapshot, then ssh into the box, pull the code snapshot, then use vboxmanage to type commands into an open terminal.

I recommend turning off unattended-upgr as it could lock your dpkg database.

sudo systemctl disable unattended-upgrades
sudo systemctl stop unattended-upgrades

Automation script

$ vboxmanage snapshot ubuntu24 list
   Name: Snapshot 1 (UUID: 7d9fa9d0-dc36-4897-ac68-bbdaab5eb9ab) *
   Description: neovim, pip, git, venv installed
$ vboxmanage snapshot ubuntu24 restore "Snapshot 1"
Restoring snapshot 'Snapshot 1' (7d9fa9d0-dc36-4897-ac68-bbdaab5eb9ab)
$ vboxmanage startvm ubuntu24
Waiting for VM "ubuntu24" to power on...
VM "ubuntu24" has been successfully started.
$ ssh u24 "sudo systemctl restart systemd-timesyncd"
$ PR=1076
$ ssh u24 "rm -rf autokey && mkdir autokey && cd autokey && git clone https://github.com/autokey/autokey.git autokey_pr$PR && cd autokey_pr$PR && sudo apt install -y \$(cat debian/build_requirements.txt apt-requirements.txt) && cd autokey-gnome-extension && make && gnome-extensions install autokey-gnome-extension@autokey.zip && cd .. && sudo cp config/10-autokey.rules /etc/udev/rules.d/ && sudo reboot"

use ssh to do the rest of the install via ssh and when you're ready to launch the gui:

# windows key
$ vboxmanage controlvm ubuntu24 keyboardputscancode e0 5b e0 db
# "terminal"
$ vboxmanage controlvm ubuntu24 keyboardputstring terminal
# enter
$ vboxmanage controlvm ubuntu24 keyboardputscancode 1c 9c
$ vboxmanage controlvm ubuntu24 keyboardputstring "autokey"
$ vboxmanage controlvm ubuntu24 keyboardputscancode 1c 9c

@Elliria

Elliria commented Aug 14, 2026

Copy link
Copy Markdown
Author

Thank you for your suggestion and for the detailed information!

I have a few reasons (in no particular order below) for my preference for a clone over a snapshot since this particular Gist is for people new to VirtualBox:

  • A snapshot isn't a copy of the full original. It's an image of the state of the original and it can't exist on its own without the original. In fact, I have trouble trying to wrap my head around where the original is actually kept when a snapshot is created since snapshots are far smaller than clones, yet, if all but one state/snapshot of a machine are deleted, the remaining state becomes the default state for that machine. I'm guessing that the Current State entry in the snapshot window is always the original with the chosen state bolted onto it.
  • A clone is a full and identical duplicate of the original that stands on its own and shows up in the left pane of VirtualBox as a machine, which is very straightforward.
  • The snapshot interface in VirtualBox is more confusing to use than the clone interface. As a result, it's possible to permanently lose a snapshot by accident by choosing the wrong one.
  • If you create a snapshot of a virtual machine while it's running, a log-in will not be required when opening that snapshot(!). This can be avoided by only taking snapshots of closed machines, but it is a vulnerability to take into account. Clones are not vulnerable in that way since you can only create a clone when no virtual machines are running.
  • Deleting all clones is straightforward. Select one in the left pane and delete it like you would any virtual machine. Deleting all snapshots can be confusing for a new user, because you always have the current state and X number of snapshots. When you get down to two, although the right-click menu only offers the Delete... option on the named snapshot, it's not made clear to the user, that the Current State entry will remain if that named snapshot is deleted. This can lead to clutter and confusion for new users who don't know what can or can't be removed or what should be selected in the snapshot pane.

That said, your information above will remain here for any of the more advanced users who'd like to use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment