Useful and lesser-known features of VirtualBox
Under the Hood
The VirtualBox virtual machine tool is a familiar sight on Linux systems, but many users don't access the full range of its powers. This article highlights some advanced features of VirtualBox that could save you some time and effort.
VirtualBox is a powerful virtualization tool that supports a variety of Windows and Linux guest systems. Most users control VirtualBox via the VirtualBox Manager. In this graphical user interface, you can set up a virtual machine with just a few mouse clicks. However, many VirtualBox users don't realize that the VirtualBox Manager also has some interesting advanced functions hidden in the depths of its settings menus and dialogs.
Be Friendly
Snapshots freeze the current state of a virtual machine and save it. You can then restore this state any time later with just a mouse click. Snapshots are especially useful for Windows guests: Before an update is due, you create a new snapshot to which can you return with just two mouse clicks in case of a failed update. Anyone who has ever had a function update blow up in their face under Windows will quickly appreciate this help.
To create a new snapshot, click the small black triangle in the top right corner of the VirtualBox Manager, next to the VM Tools icon, and select Snapshots (Figure 1). You will now see a list of all snapshots that have already been taken. At first, you will only see the Current state entry.
To freeze this state, click Create. In the dialog that appears, give the snapshot a name. The name should briefly summarize why you took the snapshot, such as Windows 10 post install. If necessary, you can add a detailed description in the large input field.
After pressing OK, VirtualBox creates the new snapshot. In a snapshot, VirtualBox not only remembers the state of the virtual machine but also its configuration. If you click on Properties, the Information tab reveals the settings (Figure 2).
After you create the snapshot, the virtual machine can start normally. If you want to create another snapshot, simply click on Create again. In the list, VirtualBox indents the snapshots, as shown in Figure 2, which means you can see the snapshot sequence at a glance.
VirtualBox also lets you quickly create snapshots in the running machine by calling Machine | Create snapshot or pressing the host key and T at the same time. By default, the host key corresponds to the right Ctrl key. If necessary, you can change this in File | Settings in the Input area of the Virtual Machine tab next to Host key combination.
When creating a snapshot, VirtualBox freezes the disk image in the background. VirtualBox remembers all the subsequent modifications and newly created files in a differential image. This special hard disk image contains all the changes to the original hard disk image. Thanks to this, VirtualBox does not have to copy the entire image, which in turn saves disk space.
Since VirtualBox remembers all your snapshots, intensive use of the function results in a nested hierarchy, as shown in Figure 2. The Windows drivers were installed in the Driver installed snapshot. Afterwards, the user loaded Photoshop and created another snapshot.
Then the user went back to the Driver installed snapshot, where the Affinity Designer program was installed and a suitable snapshot was again created. In the Photoshop snapshot, only Photoshop is installed, but not Affinity Designer. According to the same principle, different variants of a virtual machine can be created elegantly and in a space-saving way.
If you want to return to a previous state, simply select it from the list and click Restore. The other snapshots are not lost – you can therefore jump back and forth between the snapshots at any time. The VirtualBox Manager on the left side of the screen indicates the state in which the virtual machine will launch in the brackets next to the virtual machine name.
If you have changed a state, VirtualBox asks if you want to save your changes in the virtual machine to a new snapshot before restoring. If you reject the offer, you will lose the changes accumulated since the last snapshot.
To remove a snapshot, select it from the list and click the Delete button. The Clone option lets you quickly duplicate a snapshot. To edit the virtual machine configuration again, click the triangle next to VM Tools and select Configuration.
Expanding the Disk
If a virtual hard disk becomes too small, you can expand it with a few mouse clicks. To do this, stop the virtual machine if necessary and then select in VirtualBox Manager File | Virtual Media Manager. In the Drives tab, select the image you want to expand and display the Properties (Figure 3).
The slider below Size, tells VirtualBox to resize the disk image. Confirm your change with Save. However, the procedure only works with image files in VDI and VHD format, which must also be created dynamically.
In addition, VirtualBox only lets you expand a virtual disk – you can't make it smaller, even if the disk image is not completely filled with data. Also, the operating system on the virtual machine is not yet aware of the change. You'll need to use the disk tools on the guest system to extend the partitions on the current guest to match.
Similarities
By default, VirtualBox ensures that each disk image can only be used by precisely one active virtual machine. Sometimes, however, several guests running in parallel have to access the documents on a virtual hard disk. To allow several guests to access a disk image, a few mouse clicks are required: First, shut down the virtual machines that need to access the disk image.
Then go to File | Virtual Media Manager and select the desired image in the Drives tab. Open the Properties, in the Attributes tab, set the Type to Multiple connections, and confirm by pressing Save (bottom-right corner of the window).
VirtualBox may now notify you that it needs to share the image. Allow this by pressing Share. As soon as the Type is set to Multi-attach, the image file can be mounted on several virtual machines as usual using VM Tools (Figure 4). If you have mounted the disk image on a virtual machine previously, you need to mount it there again.
If two virtual machines access a disk image at the same time, you could end up with corrupted data. To prevent this, VirtualBox intercepts all modification attempts and stores them in the background in a differential image. Since each virtual machine receives its own differential image, the guest systems no longer get in each other's way. As a side effect, the original hard disk image remains in its original state.
However, you also need to back up the differential images. To find their locations, go to File | Virtual Media Manager and search for the disk image in the Drives tab of the VirtualBox Manager, and then click the small triangle in front of the name. VirtualBox now unfolds all the differential images, each with a cryptic identifier. As soon as you click on an image, the Attribute tab below Location shows its storage location.
By using the differential images, the virtual machines only ever see their own changes. For example, if the virtual machine modifies a letter with Fedora, Windows does not notice the change on another virtual machine. Multiple Connect hard disk images are therefore not suitable for collaboration on a single document. For collaboration, you need to switch to shared folders. (See also the "Keeping Folders Tidy" box.)
Keeping Folders Tidy
You can use VirtualBox Manager to change the directory where VirtualBox stores all the virtual machines. Go to the File | Settings menu and access in the Default path for VMs option below General. In the future, all new virtual machines will end up in the folder at the path you define; VirtualBox will retain the existing virtual machines. You can quickly jump to the directory of the currently selected virtual machine via Machine | Show in file manager.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.