# VMWare Module 重新編譯問題


## 背景

VMWare 使用自己的核心模組：

* `vmmon` (Virtual Machine Monitor)：它負責虛擬機的 CPU 執行、記憶體管理以及與硬體虛擬化技術（如 Intel VT-x 或 AMD-V）的溝通。如果這個模組沒掛載，你的虛擬機連開機（Power On）都辦不到。
* `vmnet` (Virtual Network)：負責虛擬網路。包含你常用的 Bridged、NAT、Host-only 等網路模式。如果這個沒過，虛擬機能開機但會完全斷網

這兩個模組在 Linux 核心更新的時候，都需要重新編譯。

### Unable to install all modules. See log /tmp/vmware/vmware …

每次 Linux 更新 Kernel 時，常常會遇到 VMware modules 跟新的 Kernel 版本不相容的問題，解決方法就是手動 clone VMware modules repo 並自己編譯安裝 VMware module。

但次 repo 都不一樣，最初的「黃金標準」是 `mkubecek/vmware-host-modules`，幾乎所有人都是 fork 他的，如果原作者沒空更新，其他大神（如 nan0desu 或 bytium）就會跳出來發布自己的修補版。

```bash
$ vmware-installer -l # 先查看安裝的版本
Product Name         Product Version     
==================== ====================
vmware-player        17.5.1.23298084

$ cd /usr/lib/vmware/modules/source
$ git clone https://github.com/mkubecek/vmware-host-modules
$ cd vmware-host-modules
$ git checkout workstation-17.5.1 # 切換到對應的版本分支
$ make
$ tar -cf vmnet.tar vmnet-only # 打包安裝的模組
$ tar -cf vmmon.tar vmmon-only
$ mv vmnet.tar /usr/lib/vmware/modules/source/ # 把打包模組移到對應的位置
$ mv vmmon.tar /usr/lib/vmware/modules/source/
$ vmware-modconfig --console --install-all # 安裝模組
```

解法來源 — [Unable to install all modules.See log /tmp/vmware/vmware-{Host}-vmware-14067.log for details.(Exit code1)](https://superuser.com/questions/1713277/unable-to-install-all-modules-see-log-tmp-vmware-vmware-host-vmware-14067-log)

### “Cannot open /dev/vmmon: No such file or directory” error when powering on a VM

假如電腦使用 UEFI 並且有開啟 Secure boot，電腦會不能隨意的開啟 kernel module，所以就算安裝好 VMware module，還是沒辦法開啟，

這時候就要使用 MOK key， 機器擁有者金鑰(MOK) 設備用於下列作業： 更新 UEFI 安全啟動金鑰資料庫。 匯入用來簽署第三方或自訂核心模組的金鑰，以便在 UEFI 安全啟動模式下載入這些金鑰。

```bash
# 先用 OpenSSL 產生金鑰
$ openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -days 36500 -subj "/CN=VMware/"

# 對 vmmon and vmnet 模組簽署
$ sudo /usr/src/linux-headers-$(uname -r)/scripts/sign-file sha256 ./MOK.priv ./MOK.der $(modinfo -n vmmon)
$ sudo /usr/src/linux-headers-$(uname -r)/scripts/sign-file sha256 ./MOK.priv ./MOK.der $(modinfo -n vmnet)

# 將金鑰匯入到 MOK list
$ sudo mokutil --import MOK.der
```

再來重開機, UEFI BIOS 會自動跳到註冊 MOK 的地方，在對產生的金註冊並重新開機。

解法來源 — [“Cannot open /dev/vmmon: No such file or directory” error when powering on a VM](https://knowledge.broadcom.com/external/article/315309/cannot-open-devvmmon-no-such-file-or-dir.html)

