Box

VirtualBox提示’/sbin/vboxconfig’

最近使用ubuntu22.04安装最新版VirtualBox启动虚拟机时,出现如下报错

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. 

报错提示我们使用root权限执行/sbin/vboxconfig ` sudo -i #root权限 /sbin/vboxconfig`

执行完上述操作之后,提示我们查看日志/var/log/vbox-setup.log,我一开始执行/sbin/vboxconfig的时候并没有使用root权限,所以会每一次执行就会产生一些log文件,于是我们依次查看vbox-setup.log.1-4

(base) lz@lz:/var/log$ ls
alternatives.log  boot.log.4     faillog            syslog
apport.log        bootstrap.log  fontconfig.log     ubuntu-advantage.log
apport.log.1      btmp           gdm3               ufw.log
apport.log.2.gz   cups           gpu-manager.log    unattended-upgrades
apport.log.3.gz   dist-upgrade   hp                 vbox-setup.log
apport.log.4.gz   dmesg          installer          vbox-setup.log.1
apt               dmesg.0        journal            vbox-setup.log.2
auth.log          dmesg.1.gz     kern.log           vbox-setup.log.3
boot.log          dmesg.2.gz     lastlog            vbox-setup.log.4
boot.log.1        dmesg.3.gz     openvpn            wpslog
boot.log.2        dmesg.4.gz     private            wtmp
boot.log.3        dpkg.log       speech-dispatcher
# 在vbox-setup.log.2中我们发现比较关键的一个是gcc12没有找到
(省略报错全部内容)
/bin/sh: 1: gcc-12: not found
make[2]: *** [scripts/Makefile.build:251:/tmp/vbox.0/SUPDrv.o] 错误 127
make[1]: *** [Makefile:2037:/tmp/vbox.0] 错误 2
make: *** [/tmp/vbox.0/Makefile-footer.gmk:133:vboxdrv] 错误 2
由于我系统之前安装的是GCC11,于是我将系统自带的gcc11卸载,并且安装gcc12

sudo apt-get purge gcc
sudo apt-get install gcc-12

再次使用root权限执行/sbin/vboxconfig
查看log.3
Building the main VirtualBox module.

没什么异常启动virtual box即可!