喵星之旅-屯粮的松鼠-VMware Workstation在Kernel 7.0上模块编译失败修复

现象

Ubuntu 24.04.2 LTS 升级内核到 7.0.0-31-generic 后,VMware Workstation Pro 17.6.4 起不来了:

1
2
3
4
5
6
7
$ sudo /etc/init.d/vmware start
Starting VMware services:
Virtual machine monitor failed
Virtual machine communication interface done
VM communication interface socket family done
Virtual ethernet failed
VMware Authentication Daemon done

5 个服务挂了 2 个:vmmon 和 vmnet 模块没编译出来。

排查

先把常见的坑排干净:

检查项 结果
Secure Boot 已关闭
linux-headers 已安装
gcc 版本 与内核编译一致
/lib/modules/ 下 .ko 不存在

结论:不是加载失败,是压根没编译成功。

抓取编译错误

手动跑一遍编译:

1
2
3
mkdir -p /tmp/vmtest && cd /tmp/vmtest
tar -xf /usr/lib/vmware/modules/source/vmmon.tar
cd vmmon-only && make

第一条报错:

1
linux/driver.c:21:10: fatal error: driver-config.h: 没有那个文件或目录

头文件明明在源码树里,却找不到——说明 -I 路径没传给编译器。

根因一:EXTRA_CFLAGS 被废弃

看 Makefile:

1
2
INCLUDE := -I$(SRCROOT)/include -I$(SRCROOT)/include/x86 -I$(SRCROOT)/common -I$(SRCROOT)/linux
EXTRA_CFLAGS := $(CC_OPTS) $(INCLUDE)

这些 -I 通过 EXTRA_CFLAGS 传给内核构建系统。但 kernel 7.0 的 kbuild 里:

1
2
$ grep -rn "EXTRA_CFLAGS" /usr/src/linux-headers-7.0.0-31-generic/scripts/
# 无任何结果

EXTRA_CFLAGS 在 7.0 被彻底移除了。

修复——补一行桥接:

1
2
EXTRA_CFLAGS := $(CC_OPTS) $(INCLUDE)
ccflags-y := $(EXTRA_CFLAGS) # ← 新增

vmmon-only/Makefile.kernel 和 vmnet-only/Makefile.kernel 都要改。

根因二与三:API 改名

加完 ccflags-y 后,立刻暴露出真正的内核 API 不兼容。

1. del_timer_sync → timer_delete_sync

1
2
// kernel 7.0 只有新名字
extern int timer_delete_sync(struct timer_list *timer);

受影响两处,用版本宏兼容:

1
2
3
4
5
#if LINUX_VERSION_CODE >= KERNEL_VERSION(7, 0, 0)
timer_delete_sync(&tscTimer);
#else
del_timer_sync(&tscTimer);
#endif

2. rdmsrl_safe → rdmsrq_safe

GCC 直接提示了新名字。同样用版本宏处理。

安装

编译通过后,手工打包安装:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 1. 安装 .ko
sudo install -D -t /lib/modules/$(uname -r)/misc/ vmmon-only/vmmon.ko vmnet-only/vmnet.ko

# 2. 去调试符号
sudo strip --strip-debug /lib/modules/$(uname -r)/misc/vmmon.ko /lib/modules/$(uname -r)/misc/vmnet.ko

# 3. 更新依赖
sudo depmod -a

# 4. 覆盖 VMware 自带源码(关键!)
sudo cp vmmon.tar vmnet.tar /usr/lib/vmware/modules/source/

# 5. 走 VMware 安装流程
sudo vmware-modconfig --console --install-all

# 6. 启动验证
sudo /etc/init.d/vmware start
lsmod | grep -E 'vmmon|vmnet'

踩坑

  1. 第 4 步绝对不能省。 只装 .ko 不覆盖源码,下次 VMware 重建会拿旧源码重新编译,问题复现。

  2. 不要被”内核太新 VMware 太老”带偏。 实际改动只有 3 个 API 改名 + 1 个构建变量废弃。错误信息拿到手再下结论。

  3. git archive 不打工作区改动。 要么提交后再打包,要么用 tar 手工打包。

  4. 每次内核小版本升级都要重编。 vermagic 锁定了具体内核版本。

改动清单

文件 改动
vmmon-only/Makefile.kernel 新增 ccflags-y := $(EXTRA_CFLAGS)
vmnet-only/Makefile.kernel 新增 ccflags-y := $(EXTRA_CFLAGS)
vmmon-only/linux/driver.c del_timer_sync → timer_delete_sync(≥ 7.0)
vmmon-only/linux/hostif.c del_timer_sync → timer_delete_sync(≥ 7.0)
vmmon-only/linux/hostif.c rdmsrl_safe → rdmsrq_safe(≥ 7.0)

参考

... 阅读 ...
文章目录
  1. 现象
  2. 排查
  3. 抓取编译错误
  4. 根因一:EXTRA_CFLAGS 被废弃
  5. 根因二与三:API 改名
    1. 1. del_timer_sync → timer_delete_sync
    2. 2. rdmsrl_safe → rdmsrq_safe
  6. 安装
  7. 踩坑
  8. 改动清单
  9. 参考

评论

加载中...
|