内核 4.12,virtualbox VM 无法正常工作

内核 4.12,virtualbox VM 无法正常工作

我得到了错误

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

我应该以 root 身份运行modprobe vboxdrv

尝试过,但没有成功。(说模块费用不存在。)正如网上提到的,我也尝试过:

apt-get update
sudo apt install --reinstall virtualbox-dkms

这也不起作用:

------------------------------
Deleting module version: 5.1.6
completely from the DKMS tree.
------------------------------
Done.
Unpacking virtualbox-dkms (5.1.6-dfsg-2) over (5.1.6-dfsg-2) ...
Setting up virtualbox-dkms (5.1.6-dfsg-2) ...
Building only for 4.12.0-041200-generic
Building initial module for 4.12.0-041200-generic
ERROR (dkms apport): kernel package linux-headers-4.12.0-041200-generic is not supported
Error! Bad return status for module build on kernel: 4.12.0-041200-generic (x86_64)
Consult /var/lib/dkms/virtualbox/5.1.6/build/make.log for more information.

答案1

这适用于 Ubuntu 16.04,x86_64 内核 4.12(4.12.0-041200-generic)

  • 切换到 Virtualbox 源目录

cd /usr/share/virtualbox/src

  • 获取此补丁并将其放在 /usr/share/virtualbox/src 中

sudo wget http://paste.siduction.org/20170629003423

  • 应用补丁

sudo patch -Np0 < 20170629003423

  • 通过执行来运行 vboxconfig

/sbin/vboxconfig

玩得开心!

来源:https://forum.siduction.org/index.php?topic=6769.0加上我自己的经验

答案2

由@koleygr 链接,修补melmarker 链接的似乎可以工作。我可以在运行 4.12 的 Gentoo Linux 上进行编译,但我不确定是否可以在 Ubuntu 上进行编译。

修补:

diff -ruN vboxhost.orig/vboxdrv/linux/SUPDrv-linux.c vboxhost/vboxdrv/linux/SUPDrv-linux.c
--- vboxhost.orig/vboxdrv/linux/SUPDrv-linux.c  2016-08-22 00:00:00.000000000 +0200
+++ vboxhost/vboxdrv/linux/SUPDrv-linux.c   2017-05-31 19:00:22.887324690 +0200
@@ -1397,7 +1397,7 @@
 SUPR0DECL(uint32_t) SUPR0GetKernelFeatures(void)
 {
     uint32_t fFlags = 0;
-#ifdef CONFIG_PAX_KERNEXEC
+#if defined(CONFIG_PAX_KERNEXEC) || LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
     fFlags |= SUPKERNELFEATURES_GDT_READ_ONLY;
 #endif
 #if defined(VBOX_STRICT) || defined(VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV)
diff -ruN vboxhost.orig/vboxdrv/r0drv/linux/alloc-r0drv-linux.c vboxhost/vboxdrv/r0drv/linux/alloc-r0drv-linux.c
--- vboxhost.orig/vboxdrv/r0drv/linux/alloc-r0drv-linux.c   2016-08-22 00:00:00.000000000 +0200
+++ vboxhost/vboxdrv/r0drv/linux/alloc-r0drv-linux.c    2017-05-31 19:03:32.465413475 +0200
@@ -35,7 +35,10 @@
 #include <iprt/assert.h>
 #include <iprt/err.h>
 #include "r0drv/alloc-r0drv.h"
-
+#include <linux/kmemleak.h>
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
+#include <asm/set_memory.h>
+#endif

 #if (defined(RT_ARCH_AMD64) || defined(DOXYGEN_RUNNING)) && !defined(RTMEMALLOC_EXEC_HEAP)
 # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23)
diff -ruN vboxhost.orig/vboxdrv/r0drv/linux/memobj-r0drv-linux.c vboxhost/vboxdrv/r0drv/linux/memobj-r0drv-linux.c
--- vboxhost.orig/vboxdrv/r0drv/linux/memobj-r0drv-linux.c  2017-02-02 16:54:00.000000000 +0100
+++ vboxhost/vboxdrv/r0drv/linux/memobj-r0drv-linux.c   2017-05-31 19:23:05.187059423 +0200
@@ -899,6 +899,9 @@
     unsigned long   pfn;
     struct page    *pPage;
     pte_t          *pEntry;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
+    p4d_t           p4d;
+#endif
     union
     {
         pgd_t       Global;
@@ -917,9 +920,18 @@
     u.Global = *pgd_offset(current->active_mm, ulAddr);
     if (RT_UNLIKELY(pgd_none(u.Global)))
         return NULL;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
+    p4d = *p4d_offset(&u.Global, ulAddr);
+    if (RT_UNLIKELY(p4d_none(p4d) || p4d_large(p4d) || !p4d_present(p4d)))
+        return NULL;
+#endif

 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
+    u.Upper = *pud_offset(&p4d, ulAddr);
+#else
     u.Upper = *pud_offset(&u.Global, ulAddr);
+#endif
     if (RT_UNLIKELY(pud_none(u.Upper)))
         return NULL;
 # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
@@ -1463,13 +1475,23 @@
 {
     int rc = -ENOMEM;
     pgd_t *pgd;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
+    p4d_t *p4d;
+#endif

     spin_lock(&mm->page_table_lock);

     pgd = pgd_offset(mm, ulAddr);
     if (!pgd_none(*pgd) && !pgd_bad(*pgd))
     {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
+        p4d = p4d_offset(*pgd, ulAddr);
+        if (p4d_none(*p4d))
+            goto exit;
+        pmd_t *pmd = pmd_offset(p4d, ulAddr);
+#else
         pmd_t *pmd = pmd_offset(pgd, ulAddr);
+#endif
         if (!pmd_none(*pmd))
         {
             pte_t *ptep = pte_offset_map(pmd, ulAddr);
@@ -1487,6 +1509,9 @@
         }
     }

+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
+exit:
+#endif
     spin_unlock(&mm->page_table_lock);
     return rc;
 }

相关内容