You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS7用devtoolset-8安装VirtualBox Guest Additions报stack-protector错误

注:本问题我已找到解决方案,与Stack Overflow上其他同类问题差异较大,发布此内容旨在帮助遇到相同问题的用户,也方便后续我自己回溯。

环境说明

  • 宿主机系统:macOS Catalina 10.15.7
  • 虚拟化软件:VirtualBox 6.1.26
  • 虚拟机系统:CentOS 7
  • 虚拟机内核版本:
$ uname -r
3.10.0-1160.36.2.el7.x86_64

问题描述

插入VirtualBox Guest Additions光盘后按自动运行提示安装增强功能,中途安装终止,提示如下:

This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.

排查过程

已确认提前安装了gcc、make、perl、kernel-devel、kernel-headers所有依赖包,查看/var/log/vboxadd-setup.log日志,内容如下:

Building the main Guest Additions 6.1.26 module for kernel 3.10.0-1160.36.2.el7.x86_64.
Error building the module.  Build output follows.
make V=1 CONFIG_MODULE_SIG= CONFIG_MODULE_SIG_ALL= -C /lib/modules/3.10.0-1160.36.2.el7.x86_64/build M=/tmp/vbox.0 SRCROOT=/tmp/vbox.0 -j4 modules
arch/x86/Makefile:96: stack-protector enabled but compiler support broken
arch/x86/Makefile:166: *** CONFIG_RETPOLINE=y, but not supported by the compiler. Compiler update recommended..  Stop.
make: *** [vboxguest] Error 2
modprobe vboxguest failed

现有公开解决方案均指向两个原因:依赖包缺失、GCC版本低于7.3(CONFIG_RETPOLINE=y最低支持版本),但实际检查GCC版本符合要求:

$ gcc --version
gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)

高版本GCC通过Yum的devtoolset包安装,已安装的devtoolset相关包如下:

$ sudo yum list installed|grep devtoolset
...
devtoolset-8-gcc.x86_64                     8.3.1-3.2-el7             @centos-sclo-rh
devtoolset-8-gcc-c++.x86_64                 8.3.1-3.2-el7             @centos-sclo-rh
devtoolset-8-gcc-gdb-plugin.x86_64          8.3.1-3.2-el7             @centos-sclo-rh
...
devtoolset-8-make.x86_64                    1:4.2.1-4.el7             @centos-sclo-rh
...

未安装其他版本GCC:

$ sudo yum list installed|grep gcc
devtoolset-8-gcc.x86_64                     8.3.1-3.2-el7             @centos-sclo-rh
devtoolset-8-gcc-c++.x86_64                 8.3.1-3.2-el7             @centos-sclo-rh
devtoolset-8-gcc-gdb-plugin.x86_64          8.3.1-3.2-el7             @centos-sclo-rh
libgcc.x86_64                               4.8.5-44.el7              @anaconda

已在~/.bashrc中添加source scl_source enable devtoolset-8配置,登录时自动启用devtoolset。

问题根因

VirtualBox Guest Additions的安装脚本默认以sudo权限执行,~/.bashrc的配置仅对当前普通用户的交互式shell生效,sudo执行安装脚本时不会加载当前用户的bashrc配置,因此系统调用的还是默认的旧版本gcc(libgcc对应的4.8.5版本,无retpoline支持),导致编译报错。

解决方案

  1. 切换到root用户,手动加载devtoolset环境后执行安装脚本:
# 切换到root用户
sudo su
# 加载devtoolset-8环境
source scl_source enable devtoolset-8
# 进入Guest Additions光盘挂载目录,通常为/run/media/[用户名]/VBox_GAs_6.1.26,根据实际路径调整
cd /run/media/$(logname)/VBox_GAs_6.1.26
# 执行安装脚本
./VBoxLinuxAdditions.run
  1. 安装完成后重启虚拟机,验证增强功能是否正常生效即可。

内容的提问来源于stack exchange,提问作者Nick Williams

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.07 03:39:03