vboxdrv.sh: 失败:modprobe vboxdrv 失败。请使用 'dmesg' 查找原因。

我在我的Ubuntu笔记本上运行VirtualBox时遇到问题。我的笔记本是双启动的,同时运行(Windows 10 - 我想是这样,已经好几年没用了)和Ubuntu 16.0.4 LTS。

我在笔记本的BIOS设置中启用了安全启动。

我知道这里有类似的问题帖子,具体如下:

我按照那两个问题的答案部分给出的所有指示进行了操作,但问题仍未解决。

下面是当我尝试运行virtualbox时的控制台输出:

me@YOURBOX:~$ virtualbox
WARNING: The vboxdrv kernel module is not loaded. Either there is no module
         available for the current kernel (4.4.0-47-generic) or it failed to
         load. Please recompile the kernel module and install it by

           sudo /sbin/vboxconfig

         You will not be able to start VMs until this problem is fixed.

这是我按照建议运行/sbin/vboxconfig时的控制台输出:
me@YOURBOX:~$ sudo /sbin/vboxconfig  
vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.
vboxdrv.sh: Starting VirtualBox services.
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.

这是dmesg输出的末尾部分:
[   44.319682] audit: type=1400 audit(1491313982.374:11): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/bin/evince-previewer" pid=705 comm="apparmor_parser"
[   45.041433] cgroup: new mount options do not match the existing superblock, will be ignored
[   59.682936] IPv6: ADDRCONF(NETDEV_UP): wlp3s0: link is not ready
[   59.697820] IPv6: ADDRCONF(NETDEV_UP): wlp3s0: link is not ready
[   59.702008] IPv6: ADDRCONF(NETDEV_UP): enp2s0f0: link is not ready
[   60.267000] IPv6: ADDRCONF(NETDEV_UP): enp2s0f0: link is not ready
[   62.473044] IPv6: ADDRCONF(NETDEV_UP): wlp3s0: link is not ready
[   70.681706] audit_printk_skb: 60 callbacks suppressed
[   70.681709] audit: type=1400 audit(1491314008.734:32): apparmor="STATUS" operation="profile_load" profile="unconfined" name="docker-default" pid=2009 comm="apparmor_parser"
[   70.850936] aufs 4.x-rcN-20160111
[   75.407218] bridge: automatic filtering via arp/ip/ip6tables has been deprecated. Update your scripts to load br_netfilter if you need this.
[   75.408555] Bridge firewalling registered
[   75.427172] nf_conntrack version 0.5.0 (16384 buckets, 65536 max)
[   75.848416] ip_tables: (C) 2000-2006 Netfilter Core Team
[   76.703232] Initializing XFRM netlink socket
[   77.060003] IPv6: ADDRCONF(NETDEV_UP): docker0: link is not ready
[   80.101042] aufs au_opts_verify:1597:dockerd[1402]: dirperm1 breaks the protection by the permission bits on the lower branch
[  113.895236] wlp3s0: authenticate with 84:16:f9:77:e1:54
[  113.910483] wlp3s0: send auth to 84:16:f9:77:e1:54 (try 1/3)
[  113.912712] wlp3s0: authenticated
[  113.915101] wlp3s0: associate with 84:16:f9:77:e1:54 (try 1/3)
[  113.919397] wlp3s0: RX AssocResp from 84:16:f9:77:e1:54 (capab=0x1411 status=0 aid=1)
[  113.919516] wlp3s0: associated
[  113.919559] IPv6: ADDRCONF(NETDEV_CHANGE): wlp3s0: link becomes ready

现在,我不会撒谎 - 对于dmesg刚刚喷出的东西,我完全不知道是什么意思 - 就我所知,日志输出中没有错误信息 - 这使情况变得更加恼人。

有没有人曾经在启用了BIOS的安全启动的Ubuntu 16.04 LTS笔记本电脑上安装过VirtualBox 5.x?- 如果有的话,解决方案是什么???!

很多人都有这个问题 - 即使回溯几年前也是如此。很奇怪的是似乎没有人能够找到解决方法 - ???


2我的笔记本电脑的BIOS设置中启用了安全引导。这可能是你遇到问题的原因之一。我记得以前听说安全引导会破坏VirtualBox。 - You'reAGitForNotUsingGit
另一个类似的问题:https://askubuntu.com/questions/760671/could-not-load-vboxdrv-after-upgrade-to-ubuntu-16-04-and-i-want-to-keep-secur - Dan Dascalescu
2个回答

VirtualBox + Secure Boot + Ubuntu = 失败
问题在于所有内核模块必须由UEFI系统信任的密钥签名,否则加载将失败。Ubuntu不会为第三方vbox*内核模块签名,而是在安装virtualbox软件包时给用户选择是否禁用Secure Boot。我可以这样做,但每次启动机器时都会看到一个烦人的“以非安全模式启动”消息,而且我安装的双启动Windows 10也无法正常工作。
Ubuntu 16.04在Dell Latitude E7440上使用BIOS A18,并带有双启动Windows 10安装。
感谢我用来解决这个问题的主要信息来源,该信息特别适用于Fedora/Redhat: http://gorka.eguileor.com/vbox-vmware-in-secureboot-linux-2016-update/ 还有一个相关的Ask Ubuntu问题: Could not load 'vboxdrv' after upgrade to Ubuntu 16.04 (and I want to keep secure boot) 使其在Ubuntu/Debian上工作的步骤
1. 安装virtualbox软件包。如果安装检测到Secure Boot已启用,您将遇到上述问题,并有选择禁用Secure Boot的选项。选择“否”。
2. 创建一个用于签名内核模块的个人公钥/私钥RSA密钥对。我选择使用root帐户和目录/root/module-signing/来存储与签名内核模块相关的所有内容。
$ sudo -i # mkdir /root/module-signing # cd /root/module-signing # openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -days 36500 -subj "/CN=YOUR_NAME/" [...] # chmod 600 MOK.priv
3. 使用MOK(“机器所有者密钥”)实用程序导入公钥,以便系统可以信任它。这是一个两步过程,首先导入密钥,然后在下次启动机器时必须进行注册。一个简单的密码就足够了,因为它只是临时使用。
# mokutil --import /root/module-signing/MOK.der 输入密码: 再次输入密码:
4. 重新启动机器。当引导加载程序启动时,MOK管理器EFI实用程序应自动启动。它将要求输入第3步中提供的密码的部分。选择“Enroll MOK”,然后您应该看到在第3步中导入的密钥。完成注册步骤,然后继续启动。Linux内核将记录加载的密钥,您应该能够使用以下命令看到您自己的密钥: dmesg|grep 'EFI: Loaded cert'
5. 使用与内核构建文件一起提供的签名实用程序,使用在第2步生成的私有MOK密钥签名所有VirtualBox模块。我将其放在一个小脚本/root/module-signing/sign-vbox-modules中,以便在常规更新的一部分安装新内核时可以轻松运行:
#!/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/module-signing/MOK.priv \ /root/module-signing/MOK.der "$modfile" done 然后: # chmod 700 /root/module-signing/sign-vbox-modules
6. 以root身份运行第5步的脚本。每次安装新内核更新后都需要运行签名脚本,因为这会导致第三方VirtualBox模块的重建。仅在新内核启动后使用该脚本,因为
注意:以上答案完全来自于Øyvind Stegard的博客文章VirtualBox + Secure Boot + Ubuntu = fail

1我遇到了一个错误:vboxdrv.sh: 失败:modprobe vboxnetflt 失败。请使用 'dmesg' 查找原因。dmesg: [70567.246789] vboxdrv: 发现 2 个处理器核心 [70567.267310] vboxdrv: TSC 模式为不变,临时频率为 2166734189 Hz [70567.267315] vboxdrv: 成功加载版本 5.0.40_Ubuntu(接口 0x00240000) - marshy101
非常好的回答,感谢提供脚本!我想补充一点,如果在执行 vagrant up 时仍然出现 VboxManage hostonlyif create 失败的情况,可以通过卸载 vagrant 和 virtualbox,然后重新安装来解决。假设您已经签署了密钥。祝好! - Anthony Harley
Ubuntu 18已经修复了这个问题吗?还是因为安全原因永远不会被修复? - Dan Dascalescu
@DanDascalescu 我不知道 - 我个人讨厌UEFI,总是以MBR模式安装...... - You'reAGitForNotUsingGit
7关于18.04+的说明:建议使用以下grep命令:dmesg|grep 'EFI:',而不是dmesg|grep 'EFI: Loaded cert' - gkephorus
4完全不知道和理解这是做什么的,但是它起作用了。 - naneri
1以防萬一有人需要:我在沒有UEFI或安全模式的情況下遇到了這個問題。在我的情況下,18.04.x上的virtualbox-dkms安裝出現了問題。我的解決方法是:apt purge virtualbox-dkms && apt install virtualbox-dkms && modprobe vboxdrv - gorlok
1如果您将VirtualBox从5.2升级到6.0,请不要忘记再次完成第6步和第7步。 - voleger
再次回到这个问题。我记得在系统上有关于这个脚本的事情,并且在虚拟机加载出现问题时运行它。但是我总是忘记第7步,所以我建议将该命令放在第6步脚本的末尾。这绝对是下次节省时间的好办法。 - voleger
1它适用于Ubuntu 18和VirtualBox 6。 - Tuna
上述解决方案对我有用(Ubuntu 18.04启用了安全引导),但是当我尝试注册MOK时遇到了困难,它拒绝接受密码。我发现:
  • 密码最多只能有5个字符
  • 有人注意到MOK管理器可能使用azerty键盘 所以我建议使用"12345"作为密码,这对我有效。
- g.adam

上面的答案可能很好用,但如果你想更简单一点的话:
我通过进入BIOS并选择 > 高级(f7)> 引导 > 向下滚动到“安全引导” > 将“Windows EUFI模式”更改为“其他操作系统”,成功解决了这个问题。
我的虚拟机现在运行得非常完美。

3你不想做这件事的原因是什么? - Taegost
由于一些电力波动或其他原因,我的BIOS被重置了,所以我需要这样做。现在我不再遇到上述错误了。 - jamadagni