签署虚拟框模块(vboxdrv、vboxnetflt、vboxnetadp、vboxpci)Centos 8

Sign virtual box modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) Centos 8

我最近开始使用Centos 8,安装了VirtualBox来管理我的虚拟机, 我遇到的问题是我的 VirtualBox 无法启动任何 VM,它告诉我以 root 身份执行此脚本 /sbin/vboxconfig,当我 运行 此脚本时出现以下消息:

vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: You must sign these kernel modules before using VirtualBox:
  vboxdrv vboxnetflt vboxnetadp vboxpci
See the documenatation for your Linux distribution..
vboxdrv.sh: Building VirtualBox kernel modules.
vboxdrv.sh: failed: modprobe vboxdrv failed. Please use 'dmesg' to find out why.

There were problems setting up VirtualBox.  To re-start the set-up process, run
  /sbin/vboxconfig
as root.  If your system is using EFI Secure Boot you may need to sign the
kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) before you can load
them. Please see your Linux system's documentation for more information.

请注意,我的安全启动已启用。 我的问题是如何在 Centos 8 中签署这些内核模块?

经过一番研究,我找到了解决方案。

解决方案 1:禁用安全启动。

解决方案 2:

1- 安装 mokutil

sudo dnf update
sudo dnf install mokutil

2- 在新文件夹下创建 RSA 密钥。

sudo -i
mkdir /root/signed-modules
cd /root/signed-modules
openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -days 36500 -subj "/CN=VirtualBox/"
chmod 600 MOK.priv

3-此命令会要求您添加密码,下次重启后您需要此密码。

sudo mokutil --import MOK.der

4- 重启系统,出现蓝屏,select Enroll MOK --> Continue --> 输入之前的密码,系统将启动。

5- 将之前的命令放在脚本中 运行 稍后(系统更新后)

cd /root/signed-modules
vi sign-virtual-box

将以下命令添加到此脚本中:

#!/bin/bash

for modfile in $(dirname $(modinfo -n vboxdrv))/*.ko; do
  echo "Signing $modfile"
  /usr/src/kernels/$(uname -r)/scripts/sign-file sha256 \
                                /root/signed-modules/MOK.priv \
                                /root/signed-modules/MOK.der "$modfile"
done

如果上面的方法失败,请使用下面的方法找到 signfile 并相应地编辑脚本。

find /usr/src -name sign-file

5- 添加 exec 权限和 运行 脚本

chmod 700 sign-virtual-box
./sign-virtual-box 

6- 启动 VirtualBOx

modprobe vboxdrv

有关详细信息,请参阅此 link(针对 ubuntu 用户) https://stegard.net/2016/10/virtualbox-secure-boot-ubuntu-fail/

我从 virtualbox 6.0 升级到 6.1 和 vboxconfig 运行 没有错误(或需要签署内核模块)。

我遵循 given by @Younes LAB 但我需要更改 sign-virtual-box 脚本中的 sign-file 路径才能正常工作:

#!/bin/bash

for modfile in $(dirname $(modinfo -n vboxdrv))/*.ko; do
  echo "Signing $modfile"
  /usr/src/linux-headers-$(uname -r)/scripts/sign-file sha256 \
                                /root/signed-modules/MOK.priv \
                                /root/signed-modules/MOK.der "$modfile"
done

我正在使用 Ubuntu 20.04.2 LTS 和 VirtualBox 6.1