Feature image for the article about how to install VirtualBox guest additions in Ubuntu 20.04

Install VirtualBox guest additions in Ubuntu 20.04

Bummed that you can’t change the screen resolution in your freshly installed Ubuntu virtual machine? An easy fix exists for this: You just need to install the VirtualBox guest additions in your Ubuntu virtual machine. Besides automatically adjusting the screen resolution, you also get support for a bi-directional clipboard and shared folders. This article explains how to install the VirtualBox guest additions in an Ubuntu virtual machine.

Background

If you ever installed Ubuntu in a VirtualBox virtual machine, you probably noticed that you can’t change the screen resolution. For example after resizing the virtual machine window or going into full-screen mode. The reason for this is that the Ubuntu installer does not install the so called VirtualBox guest additions.

The VirtualBox guest additions consist of a set of drivers and kernel modules for the operating system, when installed as a VirtualBox virtual machine. They offer quality of life type improvements for working with your virtual machine:

  • Improved display driver that automatically adjusts the screen resolution, when resizing the window of the virtual machine.
  • Bi-directional clipboard for copy-pasting text between the host and the guest operating system.
  • Shared folders for exchanging files between the host and the guest operating system.

Because of these added benefits, I highly recommend installing the VirtualBox guest additions right after you finished installing Ubuntu in a VirtualBox virtual machine. This tutorial walks you through the steps of how to install the VirtualBox guest additions in an Ubuntu virtual machine.

What do you need

In this article, I’ll explain step-by-step how to install the VirtualBox guest additions for an Ubuntu virtual machine. This assumes that you already installed Ubuntu as a virtual machine in VirtualBox. The presented instructions work for any type of Ubuntu flavor or derivative, for example Xubuntu, Linux Mint and Pop!_OS.

At the time of this writing, Ubuntu 20.04 is the latest long term support (LTS) release. In preparation for this article, I created a VirtualBox virtual machine based on Ubuntu Desktop 20.04. In case you don’t yet have a Ubuntu virtual machine, the following article explains how to install Ubuntu Desktop 20.04 LTS step-by-step:

Update your operating system

Before installing anything on your Ubuntu system, you should always update the operating system first. Why? Because package dependencies might have changed since your last update. This could lead to potential installation issues when installing new software.

To update the currently installed packages on your Ubuntu system, start the virtual machine and run the following two commands from the terminal:

  • sudo apt update
  • sudo apt upgrade

Install the dependencies for building kernel modules

The VirtualBox guest additions for Linux consist of a bunch of Linux kernel modules. When installing the VirtualBox guest additions, these kernel modules are automatically built, specifically for the kernel version currently running in Ubuntu. Building kernel modules requires certain software packages. Therefore we need to first install these, prior to installing the VirtualBox guest additions in Ubuntu.

With your Ubuntu virtual machine running, open the terminal and run the following commands. This installs the required software packages for building kernel modules:

  • sudo apt install build-essential dkms linux-headers-$(uname -r)

Install the VirtualBox guest additions

The Guest Additions CD image holds the installer for the VirtualBox guest additions. This CD image ships with VirtualBox. So there is no need to separately download this CD image. As a first step in installing the VirtualBox guest additions, you need to attach the Guest Additions CD image to your Ubuntu virtual machine. You achieve this by selecting Devices → Insert Guest Additions CD Image from the menu of your Ubuntu virtual machine:

Screenshot of the Ubuntu virtual machine in VirtualBox that shows how to insert the guest additions CD image.

The next step depends on whether or not your desktop environment is configured to detect and prompt to execute the autorun script on a CD.

Install the VirtualBox guest additions using the CD autorun script

If your desktop environment supports the execution of the autorun script on a CD, a dialog appears. It asks you if you want to automatically run software contained on the CD. Go ahead an confirm that you want to run the software on the CD:

Screenshot of the autorun dialog that shows up after inserting the guest additions CD image. It highlights that you can click on the run button to start the installation of the VirtualBox guest additions in the Ubuntu VM.

The installer requires super user privileges, so you’ll be asked to enter your administrative password. Basically the same password as if you were to run something as sudo from the terminal. Next, the installer opens a terminal window, where you can follow the installation progress. Once done, you just need to restart your Ubuntu virtual machine, to activate the newly built and installed kernel modules.

Terminal screenshot that shows the progress of the install of the VirtualbBx guest additions in the Ubuntu virtual machine.

Install the VirtualBox guest additional manually

If your desktop environment does not support auto-running software on a CD, we can start the autorun script manually from the terminal. First we need to find out where Ubuntu mounted the Guest Additions CD image. Open a terminal and run this command:

  • lsblk | grep "rom"
Terminal screenshot that shows the output of the lsblk | grep "rom" command. It is used to determine the mountpoint of the VirtualBox guest additions CD image.

In the command output, you can find the directory through which we can access the contents of the Guest Additions CD image. Now that you know the mount point, change to this directory and manually start the autorun script by running the command:

  • ./autorun.sh
Terminal screenshot that explains how to manually start the install process for the VirtualBox guest additions in the Ubuntu virtual machine.

This starts the exact same installation process as described in the previous section. If this doesn’t work for some reason, you can alternatively run the installer directly using command:

  • sudo ./VBoxLinuxAdditions.run

Checking the VirtualBox guest additions

How do you know if the installation for the VirtualBox guest additions was successful for your Ubuntu virtual machine? It installed an improved display driver that allows automatic screen resolution adjustment. Consequently that you can test this, by simply resizing the window of your Ubuntu virtual machine. Then check if the screen resolution properly changed.

Instead of resizing the virtual machine window, I switched it to full screen. Afterwards, I checked the screen resolution in the Gnome Settings application:

Screenshot of the Gnome settings application that shows the current screen resolution. It is used to verify that the installation of the VirtualBox guest additions in Ubuntu was successful.

The screen resolution of 1920 x 1080 resembles what I expect for my monitor. As a result I can conclude that the VirtualBox guest additions installation was successful on my Ubuntu virtual machine.

Enable the bi-directional clipboard

In addition to an improved display driver, the VirtualBox guest additions offer a bi-directional clipboard. This allows you to copy-paste text between the host operating system and your Ubuntu virtual machine. You just need to enable this feature. From the menu of your Ubuntu virtual machine, select DevicesShared ClipboardBidirectional:

Ubuntu VirtualBox virtual machine screenshot that shows how to enable the bi-directional screenshot.

From now on both your host operating system and your guest operating system can access text on the clipboard.

Enable shared folders

A feature I use myself quite often, is the VirtualBox shared folders. With the help of the VirtualBox shared folders, you can select a directory on your host operating system. Your Ubuntu virtual machine then automatically mounts this directory. Effectively, this means that you can exchange files between your host operating system and your Ubuntu virtual machine, through this selected directory.

Getting shared folders to work, is a bit trickier. For this reason, I dedicated an entire article towards the topic of how to mount a shared folder in VirtualBox. In this section, I’ll summarize how to setup a shared folder.

The first thing to do is add your user to the group vboxsf. Otherwise you user does not have permissions to access the shared folder. Inside your Ubuntu virtual machine, open a terminal and run this command:

  • sudo usermod -a -G vboxsf $USER

Next reboot your Ubuntu virtual machine, to activate these user and group changes.

Open the shared folders settings by selecting DevicesShared FoldersShared Folders Settings from the Ubuntu virtual machine menu. Continue by adding a shared folder on this settings dialog and make sure to enable the Auto-mount option. I typically select my user’s Desktop folder as the directory to share:

Screenshot of the Ubuntu virtual machine settings that highlights how to add and configure a shared folder.

After adding a shared folder, open the file manager on your Ubuntu virtual machine. You’ll notice that you can immediately access the shared folder. It’s name is sf_<directory name>. In my case sf_Desktop:

Screenshot of the Nautilus file manager that shows the automatically mounted VirtualBox shared folder.

Wrap up

The VirtualBox guest additions make working with your Ubuntu virtual machine more pleasant. Its most prominent features are:

  • An improved display driver that supports automatic screen resolution changes.
  • A bi-directional clipboard for copy-pasting text between the host and the guest operating system.
  • One or more shared folders to exchange files between the host and guest operating system.

Your Ubuntu virtual machine does not offer the VirtualBox guest additions by default. Therefore, it is recommended to install the VirtualBox guest additions, after you completed a fresh installation of Ubuntu in your virtual machine.

This article showed you step-by-step how to install the VirtualBox guest additions in an Ubuntu virtual machine. As whip-cream on top, you also learned how to enable the bi-directional clipboard and setup shared folders.

PragmaticLinux

Long term Linux enthusiast, open source software developer and technical writer.

View all posts by PragmaticLinux →