Skip to content

Instantly share code, notes, and snippets.

@jeffersfp
Last active March 26, 2024 06:20
Show Gist options
  • Save jeffersfp/9ee1fe859f4e480267e23a58b4b36c93 to your computer and use it in GitHub Desktop.
Save jeffersfp/9ee1fe859f4e480267e23a58b4b36c93 to your computer and use it in GitHub Desktop.
Sign VirtualBox Kernel Module Files - Ubuntu

Sign VirtualBox Kernel Modules - Ubuntu

Follow the steps below if you have EFI Secure Boot enabled and need to sign VirtuaBox Kernel Modules.

  1. Install the virtualbox package
sudo apt install virtualbox
  1. Create a personal public/private RSA key pair which will be used to sign kernel modules
openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -days 36500 -subj "/CN=YOUR_NAME/"

Save your MOK in a safe place and don't forget to update the commands/scripts to reflect the new path where your key & cert files are located.

  1. Use the MOK utility (Machine Owner Key) to import the public key to the system keyring
mokutil --import MOK.der
  1. Reboot the machine and enroll the MOK

  2. Use the signing utility shippped with the kernel to sign all the VirtualBox modules using the private MOK

#!/bin/bash

SIGNTOOL="/usr/src/linux-headers-$(uname -r)/scripts/sign-file"

for modfile in $(dirname $(modinfo -n vboxdrv))/*.ko; do
  echo "Signing $modfile"
  $SIGNTOOL sha256 MOK.priv MOK.der "$modfile"
done
  1. Reload the vbox module and fire the VM up
sudo modprobe vboxdrv

Reference: https://stegard.net/2016/10/virtualbox-secure-boot-ubuntu-fail/

@SMCC94
Copy link

SMCC94 commented Jun 27, 2023

Thanks! This worked for me on Ubuntu 22.04 with the standard UEFI that comes on HP laptops, although I had to add in a 'sudo' just before $SIGNTOOL in the final command

@1Codealot
Copy link

1Codealot commented Oct 17, 2023

For some reason on my debian machine i get Failed to enroll new keys (after doing mokutil --import MOK.der)

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