解决Ubuntu宿主机下面安装Vmware时候vmmon和vmnet模块缺失导致的报错

场景

Ubuntu 20操作系统下面安装Vmware执行开始运行,启动虚拟机发现报错

类似于下面这样的

Could not open /dev/vmmon: ?????????.
Please make sure that the kernel module `vmmon' is loaded.

手动启动Vmware模块,发现有两个模块启动失败

$ 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

执行命令安装缺失的模块

$ sudo vmware-modconfig --console --install-all
# 发现输出当中包含错误信息如下
/tmp/modconfig-DPn7nL/vmmon-only/./include/vm_asm_x86.h:67:44: error: expression in static assertion is not constant
   67 |    ASSERT_ON_COMPILE(sizeof(Selector) == 2 &&                                \
      |                      ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   68 |                      ((__builtin_constant_p(expr) && ((expr) >> 16) == 0) || \
      |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   69 |                       sizeof(expr) <= 2))
      |                       ~~~~~~~~~~~~~~~~~~    
.....
Unable to install all modules.  See log for details.

解决方案

查看VMware版本

通过安装包信息查看

Ubuntu系统下面获取安装包的时候会下载一个*.bundle文件,该文件的文件名称就包含了版本信息,比如VMware-Workstation-Full-16.2.3-19376536.x86_64.bundle的版本就是16.2.3

如果Vmware还能正常打开,可以查看Help下面的About信息查看

vmware

安装缺失模块

需要手动去编译缺失的vmmonvmnet模块

依赖一个git开源仓库,获取仓库

$ git clone https://github.com/mkubecek/vmware-host-modules

查看分支信息

$ cd vmware-host-modules
$ git branch -a
 remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/player
  remotes/origin/player-12.5.2
  ......
  remotes/origin/player-15.5.6
  remotes/origin/player-15.5.7
  remotes/origin/workstation-14.1.3
  remotes/origin/workstation-14.1.4
  ......
  remotes/origin/workstation-16.2.1
  remotes/origin/workstation-16.2.3

依据之前获取的Vmware版本信息指定分支,以workstation-*player-*指定workstationplayer版本

$ git checkout workstation-16.2.3

开始编译和安装

$ sudo make
$ sudo make install

查看本机内核版本

$ cat /proc/version
Linux version 5.15.0-43-generic (buildd@lcy02-amd64-026) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #46~20.04.1-Ubuntu SMP Thu Jul 14 15:20:17 UTC 2022
# 或者
$ uname -r
5.15.0-43-generic

可以知道目前内核版本是5.15.0-43-generic

所以执行完成之后生成的模块会安装到/lib/modules/5.15.0-43-generic/misc

$ ll /lib/modules/5.15.0-43-generic/misc
总用量 252K
-rwxr-xr-x 1 root root 157K 八月    4 10:05 vmmon.ko
-rwxr-xr-x 1 root root  92K 八月    4 10:05 vmnet.ko

最后重新加载所有vmware模块服务

$ sudo /etc/init.d/vmware start
Starting VMware services:
   Virtual machine monitor                                             done
   Virtual machine communication interface                             done
   VM communication interface socket family                            done
   Virtual ethernet                                                    done
   VMware Authentication Daemon                                        done
   Shared Memory Available                                             done

内核版本升级导致的问题

当编译vmmonvmnet模块安装之后,后面如果有内核版本升级的话需要重新编译安装

之前的内核版本是5.15.0-41-generic,后来apt upgrade升级了一下发现VMware又不行了才发现有这个问题

执行重新安装发现报错

$ sudo make install 
Version mismatch: module vmmon-only/vmmon.ko 5.15.0-41-generic, kernel 5.15.0-43-generic
Version mismatch: module vmnet-only/vmnet.ko 5.15.0-41-generic, kernel 5.15.0-43-generic
make: *** [Makefile:35:install] 错误 1

所以需要删除之前编译好的文件,重新开始编译和安装

$ sudo make clean
$ sudo make 
$ sudo make install

最后重新加载所有vmware模块服务

参考阅读

vmware模块报错讨论区

你可能感兴趣的:(解决Ubuntu宿主机下面安装Vmware时候vmmon和vmnet模块缺失导致的报错)