在Centos 8中签署虚拟盒模块(vboxdrv、vboxnetflt、vboxnetadp、vboxpci)

39

最近我开始使用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中签署这些内核模块?


16
有没有来自精英群体的人,将这个问题标记为“此问题不符合Stack Overflow指南”的人,能在下面告诉我们为什么这样做?对我来说,这是一个完美的SO问题,我很高兴我找到了它,因为它帮助了我。请问管理员是否愿意在这里留下解释的注释? - Tomáš Pospíšek
4
我同意你的观点,我花了几个小时才找到这个答案并在论坛上分享,希望有人能告诉我们为什么他们这样做。谢谢。 - Younes LAB
1
在我看来,这个问题应该移到SuperUser,因为它与编程无关。 - pietrodito
@TomášPospíšek 我不确定,但我注意到仍有一个非常相似的Ubuntu问题未解决。虽然那个问题是11年前提出的,但SO的政策可能已经改变了。 - Isikyus
1
同意,@TomášPospíšek。你的回答解救了我,而且我已经花了好几个小时来寻找解决方案。这个MOD不应该符合Stack Overflow的指南。感谢你们两个! - NerdyDeeds
3个回答

67

经过一些研究,我找到了解决方法。

解决方案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- 重新启动您的系统,会出现一个蓝色屏幕,请选择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- 添加执行权限并运行脚本

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

6- 启动VirtualBox

modprobe vboxdrv

了解更多信息请查看此链接(面向Ubuntu用户) https://stegard.net/2016/10/virtualbox-secure-boot-ubuntu-fail/


2
最后一步: update-initramfs -u -k all && reboot - Dunaevsky Maxim
$ sudo cd /root/signed-modules sudo: cd: 没有那个命令 $ sudo /root/signed-modules sudo: /root/signed-modules: 没有那个命令我按照您的建议输入命令后出现了错误。 - lovalim
@lovalim 你可以使用 sudo -i 以 root 用户身份登录,然后执行 cd ... - Ajeet Shah
1
也许上面的命令“find /usr/src -name signfile”应该改成“find /usr/src -name sign-file”? - Gerald Schade
1
我发现我必须使用一个不同的MOK密钥,即系统提供的位于/var/lib/shim-signed/mok/MOK.der的那个,因此我需要使用命令mokutil --import /var/lib/shim-signed/mok/MOK.der并修改脚本以使用该路径下的.der和.priv文件。否则,/sbin/vboxconfig会失败,因为它试图使用自己的密钥(在/usr/lib/virtualbox/vboxdrv.sh中定义的位置),而不是上述指令中创建的密钥。或者你可以修改该脚本,但是如果你更新Virtualbox,你将回到原点。 - RedScourge
显示剩余5条评论

16

我按照@Younes LAB提供的solution进行操作,但是为了使其正常工作,我需要更改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。


2
这在我的Ubuntu 20.04.2上起作用了。谢谢! - Juan Wilde
2
这个解决方案完美地运行,无需禁用安全启动。 - testing_22
这一步对我也是必需的。Debian Buster,VirtualBox 6.1。 - Frank

-3

我从VirtualBox 6.0升级到6.1,vboxconfig运行时没有出现错误(也不需要签署内核模块)。


2
抱歉,这对我来说不起作用。 - Alex8752
同意。在Xubuntu上运行VirtualBox 6.1。似乎我需要签署一些东西。 - Mike Bell

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接