2015年12月16日 星期三

[Virtualbox][Archlinux] Upgrade vboxdrv.ko after upgrade Linux kernel


  1. search “virtualbox-modules gentoo” on google
  2. Go to “Git repository browser”


    Find out the source code of virtualbox-modules

  3. Download vbox-kernel-module-src-5.0.10.tar.xz from vbox-kernel-module-src
  4. Method 1: pacman -S linux-headers
    Method 2: find out the kernel version
    uname -a
    Ex: my kernel version is 4.10.13.
    Download from internet.

    This is how to compiler kernel code
    Decompress the tarball to build.
    tar xvf linux-4.10.13.tar.gz /lib/modules/4.10.13-1-ARCH/build
    tar to above folder is very import, otherwise ko won't able to insert cause verimage.

    include/generated/autoconf.h is generated in the make prepare step.
    If you are trying to build a kernel module, you will also need the make scripts step:
    cd /lib/modules/4.10.13-1-ARCH/build/linux-4.10.13

    gunzip < /proc/config.gz > .config
    make oldconfig
    make prepare
    make scripts


    tar xvf vbox-kernel-module-src-5.0.10.tar.xz
    type "make" will produce vboxdrv.ko

  5. After reboot will auto mount the kernel module.
    pacman -S virtualbox-host-dkms
    echo vboxdrv >> /etc/modules-load.d/virtualbox.conf
    echo vboxnetflt >> /etc/modules-load.d/virtualbox.conf

Other Work:

Reference:

Q:

=== Building 'vboxdrv' module ===
make[1]: Entering directory '/usr/src/vboxhost-5.2.12_OSE/vboxdrv'
make V= CONFIG_MODULE_SIG= -C /lib/modules/4.16.10-1-ARCH/build SUBDIRS=/usr/src/vboxhost-5.2.12_OSE/vboxdrv SRCROOT=/usr/src/vboxhost-5.2.12_OSE/vboxdrv -j4 modules
make[2]: Entering directory '/usr/lib/modules/4.16.10-1-ARCH/build'
/usr/src/vboxhost-5.2.12_OSE/vboxdrv/Makefile.include.header:141: *** Error: unable to find the headers of the Linux kernel to build against. Specify KERN_VER=<version> (currently 4.16.10-ARCH) and run Make again.  Stop.
make[2]: *** [Makefile:1561: _module_/usr/src/vboxhost-5.2.12_OSE/vboxdrv] Error 2

A:
Patch Makefile

--- Makefile 2017-11-29 00:57:47.000000000 +0800
+++ /tmp/Makefile 2018-05-31 22:08:40.502607341 +0800
@@ -43,10 +43,11 @@
 # convenience Makefile without KBUILD_EXTMOD
 
 KBUILD_VERBOSE =
+KERN_VER := $(shell uname -r)
 
 all:
  @echo "=== Building 'vboxdrv' module ==="
- @$(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxdrv
+ @$(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) KERN_VER=$(KERN_VER)  -C vboxdrv
  @cp vboxdrv/vboxdrv.ko .
  @echo
  @if [ -d vboxnetflt ]; then \
@@ -54,7 +55,7 @@
          cp vboxdrv/Module.symvers vboxnetflt; \
      fi; \
      echo "=== Building 'vboxnetflt' module ==="; \
-     $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxnetflt || exit 1; \
+     $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE)  KERN_VER=$(KERN_VER) -C vboxnetflt || exit 1; \
      cp vboxnetflt/vboxnetflt.ko .; \
      echo; \
  fi
@@ -63,7 +64,7 @@
          cp vboxdrv/Module.symvers vboxnetadp; \
      fi; \
      echo "=== Building 'vboxnetadp' module ==="; \
-     $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxnetadp || exit 1; \
+     $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE)  KERN_VER=$(KERN_VER) -C vboxnetadp || exit 1; \
      cp vboxnetadp/vboxnetadp.ko .; \
      echo; \
  fi
@@ -72,21 +73,21 @@
          cp vboxdrv/Module.symvers vboxpci; \
      fi; \
      echo "=== Building 'vboxpci' module ==="; \
-     $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxpci || exit 1; \
+     $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE)  KERN_VER=$(KERN_VER) -C vboxpci || exit 1; \
      cp vboxpci/vboxpci.ko .; \
      echo; \
  fi
 
 install:
- @$(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxdrv install
+ @$(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE)  KERN_VER=$(KERN_VER) -C vboxdrv install
  @if [ -d vboxnetflt ]; then \
-     $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxnetflt install; \
+     $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE)  KERN_VER=$(KERN_VER) -C vboxnetflt install; \
  fi
  @if [ -d vboxnetadp ]; then \
-     $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxnetadp install; \
+     $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE)  KERN_VER=$(KERN_VER) -C vboxnetadp install; \
  fi
  @if [ -d vboxpci ]; then \
-     $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxpci install; \
+     $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE)  KERN_VER=$(KERN_VER) -C vboxpci install; \
  fi
 
 clean:
@@ -103,7 +104,7 @@
  rm -f vboxdrv.ko vboxnetflt.ko vboxnetadp.ko vboxpci.ko
 
 check:
- @$(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxdrv check
+ @$(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE)  KERN_VER=$(KERN_VER) -C vboxdrv check
 
 unload:
  @for module in vboxpci vboxnetadp vboxnetflt vboxdrv; do \


0 意見:

張貼留言