How to: Install VirtualBox 7.1 on Ubuntu 24.04

Preparation

none

Tested with

Tested on: Kubuntu 24.04, VirtualBox 7.1
Last Update: 2024-10-15

Environment

  • UEFI Notebook
  • Secure Boot enabled (you can check that with “mokutil –sb-state”)

Steps

We will install the packages by adding the official repository and installing the packages from there.

1. Adding repository

# adding repo
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/oracle_vbox_2016.gpg] https://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list

# installing the GPG key for this repo
# keep in mind that apt-key add is deprecated
curl -fsSL https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo gpg --dearmor -o /usr/share/keyrings/oracle_vbox_2016.gpg

# update the packages list
sudo apt update

2. Installing packages

# install virtualbox
sudo apt install virtualbox-7.1

# your terminal will inform you about "Configuring Secure Boot":

Your system has UEFI Secure Boot enabled.                                                                             
UEFI Secure Boot requires additional configuration to work with third-party drivers.                                  

The system will assist you in configuring UEFI Secure Boot. To permit the use of third-party drivers, a new Machine-Owner Key (MOK) has been generated. This key now needs to be enrolled in your system's firmware.

To ensure that this change is being made by you as an authorized user, and not by an attacker, you must choose a password now and then confirm the change after reboot using the same password, in both the "Enroll MOK" and "Change Secure Boot state" menus that will be presented to you when this system reboots.                                      

If you proceed but do not confirm the password upon reboot, Ubuntu will still be able to boot on your system but any hardware that requires third-party drivers to work correctly may not be usable.

# You will be asked for a password. keep in mind that this password has to be between 8 and 16 characters. We need this password once for the next reboot.

# add yourself to the group vboxusers
sudo gpasswd -a $(whoami) vboxusers

# reboot now

3. Installing Secure Boot Key

During reboot you will be asked by UEFI BIOS to enroll the VirtualBox key:

  • Perform MOK management: Enroll MOK
  • Enroll MOK: Continue
  • Enroll the key? Yes
  • Password: <your chosen password from above>
  • Perform MOK management: Reboot

4. Installing Extension Pack

Get your extension pack (in exactly the same version which you have just installed) from https://www.virtualbox.org/wiki/Downloads, and install it. In my case I installed VirtualBox 7.1.4 and was able to install the extension pack 7.1.2 successfully. I believe it is just a typo, because it shows to install Guest Additions 7.1.4 if you install in inside the VM after inserting the Guest Additions CD image.

Troubleshooting

  • If you encounter a message “Can’t enumerate USB devices”, then your user is probably not in the vboxusers group. Check manually with cat /etc/group.
  • If you encounter a message “Error: could not insert vboxdrv: key was rejected by service” or “VERR_VM_DRIVER not installed”, then your machine is not able to perform “sudo modprobe vboxdrv”, because there was an error inserting the MOK key.
  • Do not try to install VirtualBox directly from the builtin Ubuntu default repositories. I’ve have a hard time trying that; and it lead only to errors.
  • Do not try to install the extension pack via sudo apt install virtualbox-ext-pack, since this is coming from the Ubuntu repo and does not fit to our installation.

Removal

If something went wrong, or you still have a former installation on your machine, you can can rid of it.

# how to remove all vbox packages incl. config files
sudo apt purge virtualbox*

# how to show all MOK keys in your system
# watch out for "Secure Boot Module Signature key"
mokutil --list-enrolled

Credits