2018年12月20日 星期四

在 Gentoo 啟動 Vmware Workstation Server

首先使用  stefantalpalaru 的 gentoo-overlay/app-emulation/ 安裝 vmware-workstation-15.0.2.10952284-r2。USE flag 主要為 "server -bundled-libs"。

產生憑證

要產生憑證,參考 Create Self-Signed Certificates
建立 openssl.cnf
[req]
default_bits            = 2048
default_keyfile         = rui.key
distinguished_name      = req_distinguished_name
#Don't encrypt the key
encrypt_key             = no
prompt                  = no
string_mask             = nombstr

[ req_distinguished_name ]
countryName             = US
stateOrProvinceName     = California
localityName            = Palo Alto
0.organizationName      = VMware, Inc.
emailAddress            = ssl-certificates@vmware.com
commonName              = localhost.localdomain
然後執行指令
openssl req -nodes -new -x509 -keyout rui.key -out rui.crt -days 3650 -config openssl.cnf
再將 rui.crt 和 rui.key 複製到 /etc/vmware/ssl/ 的目錄下。

其實在 trace 安裝的程式檔後,發現不用這麼麻煩,在安裝的 /etc/init.d/vmware-workstation-server 中,即有檢查和產生憑證的指令
# Check if certificates exist.  If not, we need to generate them, ala sshd.
if [ ! -e /etc/vmware/ssl/rui.key -o ! -e /etc/vmware/ssl/rui.crt ]; then
    checkpath -d -m 0600 /etc/vmware/ssl
    openssl req -x509 -days 365 -newkey rsa:2048 -keyout /etc/vmware/ssl/rui.key -out /etc/vmware/ssl/rui.crt -config /etc/vmware/ssl/hostd.ssl.config
    checkpath -f -m 0600 /etc/vmware/ssl/rui.key /etc/vmware/ssl/rui.crt
fi

建立 service

參考 /etc/init.d/vmware-workstation-server,建立 /lib/systemd/system/vmware-workstation-server.service
[Unit]
Description=VMware Workstation Server
Wants=vmware-authentication.service
Wants=vmware.target

[Service]
Type=simple
PIDFile=/var/run/vmware/vmware-hostd.PID
#ExecStartPre=/opt/vmware/sbin/vmware-authdlauncher
ExecStart=/opt/vmware/bin/vmware-hostd -a -d /etc/vmware/hostd/config.xml

Restart=on-abort

[Install]
WantedBy=multi-user.target
在 terminal 中,以 root 的身分執行 vmware,會出現下列錯誤 
/opt/vmware/lib/vmware/bin/configure-hostd.sh: line 15: rc-service: command not found

rc-service 的指令,那是 OpenRC 的指令,查詢 service 的 status。後來在 CentOS 7 安裝,參考安裝後的程式,確認其功能,若是啟動則傳回 on,否則為 off。

修改 /opt/vmware/lib/vmware/bin/configure-hostd.sh,把 rc-service 的指令改成 systemctl。
#!/bin/bash

action="$1"

case $action in
  add)
    #rc-update -q add vmware-workstation-server default
    #rc-service vmware-workstation-server start
    systemctl -q enable vmware-workstation-server
    systemctl -q start vmware-workstation-server
    ;;
  remove)
    #rc-update -q del vmware-workstation-server default
    #rc-service vmware-workstation-server stop
    systemctl -q disable vmware-workstation-server
    systemctl -q stop vmware-workstation-server
    ;;
  status)
    # rc-service -q vmware-workstation-server status
    systemctl -q is-active vmware-workstation-server && echo on || echo off
    ;;
  *)
    exit 1
    ;;
esac
另外,可能出現下列錯誤,設定環境變數 export VMWARE_USE_SHIPPED_GTK=force,可解決問題
/opt/vmware/lib/vmware/lib/libstdc++.so.6/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /usr/lib64/libproxy.so.1)
Failed to load module: /usr/lib/gio/modules/libgiolibproxy.so
後來,將 app-emulation/vmware-workstation 的 use flag 的 bundled-libs 拿掉,就不再出現上述錯誤。

在 /opt/vmware/bin 少了 vmware-vim-cmd,自行解壓 VM*.bundle,然後從 vmware-workstation-server 下 copy 過來。執行後,出現下列錯誤。
$ vmware-vim-cmd
filename:       /lib/modules/4.14.83-gentoo/misc/vmmon.ko
supported:      external
license:        GPL v2
description:    VMware Virtual Machine Monitor.
author:         VMware, Inc.
depends:        
retpoline:      Y
name:           vmmon
vermagic:       4.14.83-gentoo SMP mod_unload 
[AppLoader] Cannot get library dependencies. (4c)

[AppLoader] Fallback to use all shipped libraries.
[AppLoader] Cannot get library dependencies. (4c)

[AppLoader] Fallback to use all shipped libraries.
[AppLoader] Fail to launch with shipped libraries.
Fail to load executable. Exiting.
錯誤資訊在 /tmp/vmware-ajax 下,內容如下
$ cat vmware-apploader-9054.log
2019-01-28T11:04:53.416+08:00| appLoader| I125: Log for appLoader pid=9054 version=15.0.2 build=build-10952284 option=Release
2019-01-28T11:04:53.416+08:00| appLoader| I125: The process is 64-bit.
2019-01-28T11:04:53.416+08:00| appLoader| I125: Host codepage=UTF-8 encoding=UTF-8
2019-01-28T11:04:53.416+08:00| appLoader| I125: Host is Linux 4.14.83-gentoo Gentoo Base System release 2.6
2019-01-28T11:04:53.416+08:00| appLoader| W115: Unable to get output of command "/usr/bin/lsb_release -sd 2>/dev/null"
2019-01-28T11:04:53.416+08:00| appLoader| I125: Invocation: "/opt/vmware/lib/vmware/bin/vmware-vim-cmd"
2019-01-28T11:04:53.416+08:00| appLoader| I125: Calling: "/opt/vmware/lib/vmware/bin/vmware-vim-cmd"
2019-01-28T11:04:53.416+08:00| appLoader| I125: VMDEVEL not set.
2019-01-28T11:04:53.416+08:00| appLoader| I125: Using configuration file: /etc/vmware/config
2019-01-28T11:04:53.416+08:00| appLoader| I125: Use library directory: /opt/vmware/lib/vmware
2019-01-28T11:04:53.416+08:00| appLoader| I125: Setup root library: /opt/vmware/lib/vmware/bin/vmware-vim-cmd
2019-01-28T11:04:53.417+08:00| appLoader| I125: Try libraries from cached path.
2019-01-28T11:04:53.417+08:00| appLoader| E110: ldd(1) failed with errno 24: Too many open files (3,-1)
2019-01-28T11:04:53.417+08:00| appLoader| E110: ldd(1) failed with errno 24: Too many open files (4,-1)
2019-01-28T11:04:53.417+08:00| appLoader| I120: Fallback to use all shipped libraries.
2019-01-28T11:04:53.417+08:00| appLoader| E110: Fail to launch with shipped libraries.
2019-01-28T11:04:53.417+08:00| appLoader| W115: Unable to load dependencies for /opt/vmware/lib/vmware/bin/vmware-vim-cmd
2019-01-28T11:04:53.417+08:00| appLoader| W115: Unable to execute /opt/vmware/lib/vmware/bin/vmware-vim-cmd
上述 log 有兩個錯誤,第一個是缺少 lsb-release 指令,只要 emerge -av sys-apps/lsb-release 安裝即可。

另外一個是是
SSetup root library: /opt/vmware/lib/vmware/bin/vmware-vim-cmd

與 CentOS 下正常運作的結果比較,應該是
Setup root library: /usr/lib/vmware/lib/libvmware-vim-cmd.so/libvmware-vim-cmd.so
而 libvmware-vim-cmd.so 是一個指到 libvmware-hostd.so 的 link
# ls -l /usr/lib/vmware/lib/libvmware-vim-cmd.so/libvmware-vim-cmd.so 
lrwxrwxrwx. 1 root root 57  1月 27 15:21 /usr/lib/vmware/lib/libvmware-vim-cmd.so/libvmware-vim-cmd.so -> /usr/lib/vmware/lib/libvmware-hostd.so/libvmware-hostd.so

其實,/opt/vmware/lib/vmware/bin 下的執行檔,大多是指到 appLoader 的symbolic link,如 vmware,vmware-hostd 等。然而,像執行 /opt/vmware/bin/vmware-hostd 時,都可以正確的Setup root library,唯獨 vmware-vim-cmd 不行,真是詭異。

最後確認,只要建立正確的 symbolic link 即可。只是在嘗試的過程中,建立的 link 是錯的,就一直失敗。
# ln -sf /opt/vmware/lib/vmware/lib/libvmware-hostd.so/libvmware-hostd.so libvmware-vim-cmd.so/libvmware-vim-cmd.so

後來發現很早以前,自己就曾整理過相關資料了,Enable Vmware Workstation Server

systemctl stop vmware-workstation-server.target 時,自動開機的 VM 會自動關閉。不過VM 必須安裝 vmware tool。
# systemctl status vmware-hostd.service
 vmware-hostd.service - VMware Workstation Server
   Loaded: loaded (/lib/systemd/system/vmware-hostd.service; static; vendor preset: disabled)
   Active: deactivating (stop) since Tue 2019-01-29 12:51:41 CST; 18s ago
  Process: 30743 ExecStartPre=/bin/sh /opt/vmware/lib/vmware/bin/check-certificates.sh (code=exited, status=0/SUCCESS)
 Main PID: 30774 (vmware-hostd); Control PID: 31034 (sh)
    Tasks: 37 (limit: 4915)
   Memory: 3.0G
   CGroup: /system.slice/vmware-hostd.service
           ├─30774 /opt/vmware/lib/vmware/bin/vmware-hostd -a /etc/vmware/hostd/config.xml
           ├─30837 /opt/vmware/lib/vmware/bin/vmware-vmx -s sched.group= -# product=1;name=VMware Workstation;version=15.0.2;buildnumber=10>
           ├─31034 /bin/sh /opt/vmware/lib/vmware/bin/shutdown-autostart-vm.sh
           └─31052 /opt/vmware/lib/vmware/bin/vmware-vim-cmd -U root hostsvc/autostartmanager/autostop

 1月 29 12:51:41 aj-i7 sh[31034]: filename:       /lib/modules/4.14.83-gentoo/misc/vmmon.ko
 1月 29 12:51:41 aj-i7 sh[31034]: supported:      external
 1月 29 12:51:41 aj-i7 sh[31034]: license:        GPL v2
 1月 29 12:51:41 aj-i7 sh[31034]: description:    VMware Virtual Machine Monitor.
 1月 29 12:51:41 aj-i7 sh[31034]: author:         VMware, Inc.
 1月 29 12:51:41 aj-i7 sh[31034]: depends:
 1月 29 12:51:41 aj-i7 sh[31034]: retpoline:      Y
 1月 29 12:51:41 aj-i7 sh[31034]: name:           vmmon
 1月 29 12:51:41 aj-i7 sh[31034]: vermagic:       4.14.83-gentoo SMP mod_unload
 1月 29 12:51:42 aj-i7 /opt/vmware/lib/vmware/bin/vmware-hostd[30774]: Accepted password for user root from ::1

安裝完之後,/etc/vmware/netmap.conf 有網路的設定,不然 VM 會沒網路
# This file is automatically generated.
# Hand-editing this file is not recommended.
network0.name = "Bridged"
network0.device = "vmnet0"
network1.name = "HostOnly"
network1.device = "vmnet1"
network2.name = "NAT"
network2.device = "vmnet8"

還有要執行
emerge --config app-emulation/vmware-workstation
但很奇怪,執行之後,netmap.conf 的內容會不見

沒有留言:

張貼留言

網誌存檔