VirtualBox kernel driver not installed (missing gcc-12)
อัปเดต: 5 กุมภาพันธ์ 2024
ปัญหาที่คุณเผชิญคือ: คุณใช้ระบบ Debian-based อาจเป็น Ubuntu หรือ flavor ต่างๆ คุณเพิ่งรัน system-wide update ซึ่งรวม VirtualBox version ใหม่ คุณใช้ upstream VirtualBox repository หลัง apply update คุณไม่สามารถรัน VM ได้
คุณได้ error: Kernel driver not installed (rc=-1908) The VirtualBox Linux kernel driver is either not loaded or not set up correctly. Please try setting it up again by executing '/sbin/vboxconfig' as root. นี่คือมัน ไปรายละเอียดและแก้ปัญหานี้กัน
ปัญหาในรายละเอียด
Full error message ดังนี้:
Kernel driver not installed (rc=-1908).
The VirtualBox Linux kernel driver is either not loaded or not set up correctly. Please try setting it up again by executing
'/sbin/vboxconfig'
as root.
If your system has EFI Secure Boot enabled you may also 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.
where: suplibOsInit what: 3 VERR_VM_DRIVER_NOT_INSTALLED (-1908) - The support driver is not installed. On linux, open returned ENOENT.

เพื่อความเป็นธรรม error message นี้ค่อนข้าง misleading เพราะรวม Secure Boot stuff ซึ่ง most likely totally not relevant บวก last part ของ error message ใช้ syntax และ grammar ต่างจาก part แรก มา systematic กัน และทำทีละขั้นตอน
หากรัน sudo /sbin/vboxconfig บน command line จะเห็น:
[sudo] password for igor:
vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.
vboxdrv.sh: failed: Look at /var/log/vbox-setup.log to find out what went wrong.
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.
ใน /var/log/vbox-setup.log มีดังนี้:
Building the main VirtualBox module.
Error building the module:
make V=1 CONFIG_MODULE_SIG= CONFIG_MODULE_SIG_ALL= -C /lib/modules/6.5.0-14-generic/build M=/tmp/vbox.0 SRCROOT=/tmp/vbox.0 -j20 modules
make[1]: warning: -j20 forced in submake: resetting jobserver mode.
warning: the compiler differs from the one used to build the kernel
The kernel was built by: x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
You are using:
make -f ./scripts/Makefile.build obj=/tmp/vbox.0 need-builtin=1 need-modorder=1
# cmd_mod /tmp/vbox.0/vboxdrv.mod
printf '%s
' linux/SUPDrv-linux.o SUPDrv.o SUPDrvGip.o SUPDrvSem.o SUPDrvTracer.o SUPLibAll.o
...
/tmp/vbox.0/linux/SUPDrv-linux.c ; ./tools/objtool/objtool --hacks=jump_label --hacks=noinstr --hacks=skylake --retpoline --rethunk --sls --stackval --static-call --uaccess --prefix=16 --module /tmp/vbox.0/linux/SUPDrv-linux.o
/bin/sh: 1: gcc-12: not found
make[2]: *** [scripts/Makefile.build:251: /tmp/vbox.0/linux/SUPDrv-linux.o] Error 127
make[1]: *** [Makefile:2037: /tmp/vbox.0] Error 2
make: *** [/tmp/vbox.0/Makefile-footer.gmk:133: vboxdrv] Error 2
ผม truncate log สุดใจ เพราะมี compilation stuff เยอะมากที่ไม่ relevant การอ่าน make compilation logs อาจยากนิดหน่อย แต่คุณอยากดูท้าย log และค้นหา line ที่อ่านว่า 'Error' หรือ 'not found'
แน่นอน ใน log ของเรามี:
/bin/sh: 1: gcc-12: not found
ไม่ว่าจะเป็นเหตุผลอะไร ระบบไม่มี gcc-12 compiler ที่จำเป็นสำหรับ build VirtualBox kernel modules เพื่อให้ทราบ หนึ่งใน Kubuntu 22.04 ของผมมี และอีกตัวไม่มี นั่นคือ ผมไม่อยากเข้าไปในล้านเหตุผลที่คุณอาจไม่มีแพ็กเกจนี้ ไอเดียหลักคือเราจะหาว่าเกิดอะไรผิดและแก้ไข
วิธีแก้ไข
Fix จริงๆ ค่อนข้าง underwhelming เราต้องติดตั้ง gcc-12 package
sudo apt install gcc-12
เมื่อคำสั่งนี้เสร็จ ให้รันอีกครั้ง:
sudo /sbin/vboxconfig
คำสั่งควรเสร็จสมบูรณ์ และคุณสามารถกลับไปใช้ VirtualBox ได้
ข้อสรุป
Issue นี้มาจาก combination ของหลาย factors Ubuntu kernel ใหม่ VirtualBox version ใหม่ compiler และ driver incompatible และอื่นๆ น่ารำคาญมาก หากเจอ error -1908 สิ่งที่ดีที่สุดคือทำงานอย่างเป็นระบบ รัน configuration command manual ใน terminal window ติดตาม trace และ verbose error log จนกว่าจะหา culprit
ผลพบว่า สาเหตุล่าสุดของ error ชนิดนี้คือ missing gcc-12 compiler package เมื่อติดตั้งแล้ว VirtualBox drivers จะ compile สำเร็จ หลังจากนั้น คุณควรสามารถใช้ virtualization software และ launch VM ได้โดยไม่มีปัญหา หวังว่าคู่มือเล็กๆ นี้จะช่วยให้คุณคืน productivity ได้ ดูแลตัวเองนะ fellas
ขอแสดงความนับถือ