如何签署内核模块 Ubuntu 18.04

aty*_*ty0 45 virtualbox ubuntu linux-kernel

我是使用 Ubuntu 的新手。我正在尝试安装 Genymotion,以便我可以访问 android 模拟器。为了使用 Genymotion,我需要有 VirtualBox。我安装了 VirtualBox,但似乎我需要签署一个内核模块......我真的不知道该怎么做。这是我运行后收到的错误消息/sbin/vboxconfig

vboxdrv.sh: Stopping VirtualBox services.
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.  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.
Run Code Online (Sandbox Code Playgroud)

我试过用谷歌搜索这个,但似乎无法找到一个清晰简洁的答案和顺序步骤。同样,我对 linux 还是很陌生,所以欢迎任何帮助。在此先感谢所有回复的人。

bal*_*ast 58

为了在不禁用 UEFI 安全启动的情况下使 VirtualBox 正常工作,您需要执行以下操作:

  1. 创建个人公共/私有 RSA 密钥对以对内核模块进行签名。正如下面链接中所建议的,我选择将密钥/对存储在 /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 
Run Code Online (Sandbox Code Playgroud)
  1. 使用 mokutil,一种导入或删除机器所有者密钥 (MOK) 的工具,导入公钥,然后在机器重新启动时注册它。此步骤中的密码是临时使用密码,您只需记住几分钟。
    mokutil --import /root/module-signing/MOK.der
    input password:
    input password again:
Run Code Online (Sandbox Code Playgroud)
  1. 重新启动机器。当引导加载程序启动时,您应该会看到一个屏幕,要求您按下按钮以进入 MOK 管理器 EFI 实用程序。请注意,此步骤中任何外部外部键盘都不起作用。在第一个菜单中选择 Enroll MOK,然后继续,然后选择 Yes 进行密钥登记,并重新输入在步骤 2 中建立的密码。然后选择 OK 继续系统引导。

  2. 未来的内核更新将需要再次对更新的内核进行签名,因此将签名命令放在一个脚本中是有意义的,该脚本可以在以后根据需要运行。下面给出了一个示例脚本 /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
Run Code Online (Sandbox Code Playgroud)
  1. 添加执行权限,并以 root 身份从 /root/module-signing/ 目录运行上面的脚本。
    sudo -i
    cd /root/module-signing
    chmod 700 /root/module-signing/sign-vbox-modules
    ./sign-vbox-modules
Run Code Online (Sandbox Code Playgroud)
  1. 加载 vboxdrv 模块并启动 VirtualBox。
    modprobe vboxdrv 
Run Code Online (Sandbox Code Playgroud)

大部分信息来自以下链接,可以参考https://stegard.net/2016/10/virtualbox-secure-boot-ubuntu-fail/获取更多信息。

  • 没有与 Fedora 30 一起工作,有几个小时,我想我可能必须进行全新安装......如果你不知道你在做什么(像我一样),请谨慎行事! (4认同)

Adr*_*dez 20

我知道这个问题很老,但是因为没有公认的答案,而且这些答案都没有为我解决这个问题,所以我写下我今天是如何解决这个问题的:

运行此命令时,出现此错误:

$ sudo modprobe vboxdrv
modprobe: ERROR: could not insert 'vboxdrv': Required key not available
Run Code Online (Sandbox Code Playgroud)

问题是模块没有签名,因此没有加载内核。如果您的计算机激活了 SecureBoot 模式,就会发生这种情况,这在现代设备中很常见。

这就是为什么我在虚拟框中打开任何机器时出现此错误的原因

未安装内核驱动程序 (rc=-1908)

执行以下步骤对驱动程序进行签名,并将其作为内核模块加载,在 Ubuntu 系统和 Debian 9 上:

  1. 安装mkutil包就可以做签名了。

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install mokutil
    
    Run Code Online (Sandbox Code Playgroud)
  2. 生成签名文件:

    openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -days 36500 -subj "/CN=VirtualBox/"
    
    Run Code Online (Sandbox Code Playgroud)
  3. 然后将其添加到内核中:

    sudo /usr/src/linux-headers-$(uname -r)/scripts/sign-file sha256 ./MOK.priv ./MOK.der $(modinfo -n vboxdrv)
    
    Run Code Online (Sandbox Code Playgroud)
  4. 将其注册为安全启动。

    重要的!这将要求您输入密码,输入您想要的密码,下次重新启动时您只需使用一次。

    sudo mokutil --import MOK.der
    
    Run Code Online (Sandbox Code Playgroud)
  5. 最后,重新启动计算机。将出现蓝屏并等待键盘,按要求您中断启动的键。

    在此处输入图片说明

当您在蓝屏内时,选择

注册 MOK -> 继续 -> 它将要求您输入密码

之前输入过的,输入后会提示操作成功完成。

现在您的操作系统将启动,您现在可以毫无问题地使用 VirtualBox :)

希望这可以帮助某人。


小智 5

我有这个问题。禁用安全启动:https : //wiki.ubuntu.com/UEFI/SecureBoot/DKMS


小智 5

我在 Ubuntu 20.04 上遇到了同样的问题,但不明白为什么。我尝试了上述所有选项,但它们对我来说并不完全有效。签名包似乎有点复杂和不必要,所以我不太确定我是否做得对,但我最终设法弄清楚并解决了问题。

我意识到只有在执行内核/dist 升级后才会出现此问题。如果您在系统上手动编译任何程序,然后升级内核或操作系统,则会遇到同样的问题。

解决方案是安装virtualbox-dkms包。如果您查看 Synaptic Package Manager 上的安装包,您会发现负载。(我有virtualbox-6.1

如果您不确定,只需运行以下命令:

sudo apt install --reinstall virtualbox-dkms
Run Code Online (Sandbox Code Playgroud)

如果不是 DKMS,它将首先要求卸载当前版本,并要求键入-y进行确认。(注意:这不会删除您的虚拟机)