乐趣区

关于ubuntu:解决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 信息查看

装置缺失模块

须要手动去编译缺失的 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模块报错讨论区

退出移动版