Useful and lesser-known features of VirtualBox

Under the Hood

Article from Issue 220/2019
Author(s):

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.

Figure 1: You can quickly switch between the displays using the Snapshots and Configuration buttons.

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).

Figure 2: The Information tab lets you view snapshot settings.

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).

Figure 3: An attempt was made to reduce the size of the hard disk by dragging the slider to the left. VirtualBox prevents this and indicates the problem with a red warning triangle.

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.

Figure 4: You can configure VirtualBox to let you mount a virtual hard disk on another virtual machine.

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

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Networking with VirtualBox

    Tour the VirtualBox virtualization tool, a free and easy environment for virtual versions of Linux, Unix, and Windows.

  • Virtual Box

    Many popular virtualization tools are either too expensive or too complicated. If you’re looking for another option, try the no-cost and user-friendly VirtualBox.

  • phpVirtualBox

    Putting all virtualization tasks on a separate server saves significant resources on the client. phpVirtualBox makes it possible to create, configure, manage, and use remote VMs in a browser window.

  • Virtualization Tools

    Running server systems in virtual environments is a popular approach, but the technology offers benefits to desktop users. In this article, we investigate some virtual desktop alternatives.

  • QEMU and Qemu Manager

    Carry a virtual Linux machine with you wherever you go.

comments powered by Disqus
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.

Learn More

News