Ubuntu16.04 下共享Windows目錄,用虛擬機自帶包安裝VMwareTools失敗解決辦法

VMWare workstation自帶工具包“VMware Tools/”中的腳本:VMwareTools/vmware-tools-distrib/vmware-install.pl,安裝VMwareTools失敗,由於版本不匹配報錯如下:

make[1]: Entering directory '/usr/src/linux-headers-4.15.0-45-generic'

Makefile:975: "Cannot use CONFIG_STACK_VALIDATION=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel"
  CC [M]  /tmp/modconfig-CFDksW/vmhgfs-only/message.o
  CC [M]  /tmp/modconfig-CFDksW/vmhgfs-only/dir.o
/tmp/modconfig-CFDksW/vmhgfs-only/dir.c: In function ‘HgfsDirLlseek’:
/tmp/modconfig-CFDksW/vmhgfs-only/dir.c:717:16: error: ‘struct inode’ has no member named ‘i_mutex’
    mtx = &inode->i_mutex;
                ^
scripts/Makefile.build:332: recipe for target '/tmp/modconfig-CFDksW/vmhgfs-only/dir.o' failed
make[2]: *** [/tmp/modconfig-CFDksW/vmhgfs-only/dir.o] Error 1
Makefile:1551: recipe for target '_module_/tmp/modconfig-CFDksW/vmhgfs-only' failed
make[1]: *** [_module_/tmp/modconfig-CFDksW/vmhgfs-only] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-45-generic'
Makefile:120: recipe for target 'vmhgfs.ko' failed
make: *** [vmhgfs.ko] Error 2
make: Leaving directory '/tmp/modconfig-CFDksW/vmhgfs-only'

雖然有解決方法,但是比較繁瑣,因此不採用自帶腳本安裝舊版本,而是從git庫中獲取新版本補丁,採用傻瓜式方法執行腳本來安裝:

#確保 open-vm-tools沒有安裝

sudo apt-get remove open-vm-tools

#確保完成更新

sudo apt-get update

#確保安裝git

sudo apt-get install git

#獲取patch

sudo git clone https://github.com/rasa/vmware-tools-patches.git

#進入patch目錄

cd vmware-tools-patches

#下載最新版本(補丁)

sudo ./download-tools.sh latest

#解壓縮包

sudo ./untar-and-patch.sh

#運行編譯腳本,編譯並安裝VMware Tools

sudo ./compile.sh

#腳本內容

kangruojin@kangruojin:~/vmware-tools-patches$ cat compile.sh  
#!/usr/bin/env bash

# compile and install VMware Tools

readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"  

if [[ ! -d vmware-tools-distrib ]]; then
  echo $0: Error: Directory not found: vmware-tools-distrib >&2
  exit 3
fi

if hash vmware-uninstall-tools.pl >/dev/null 2>&1; then
  sudo vmware-uninstall-tools.pl
fi

if [[ -n "$1" ]]; then
        VMWARE_INSTALL_OPTIONS="$1"
fi

pushd vmware-tools-distrib >/dev/null

if hash systemctl >/dev/null 2>&1; then
  echo "Creating empty init dirs for backwards compatibility"
  for x in {0..6}; do mkdir -p /etc/init.d/rc${x}.d; done
  sudo cp $SCRIPT_DIR/patches/vmware-tools.service /etc/systemd/system/
  sudo systemctl enable vmware-tools.service

  echo "Added and enabled VMware Tools systemd service"
fi

if sudo ./vmware-install.pl --help 2>&1 | grep -q 'force-install'; then
    VMWARE_INSTALL_OPTIONS="--force-install"
fi

sudo ./vmware-install.pl --default $VMWARE_INSTALL_OPTIONS
sudo ./bin/vmware-config-tools.pl --default

popd >/dev/null


kangruojin@kangruojin:~/vmware-tools-patches$ 

安裝完畢,通過(虛擬機-->設置-->選項-->共享文件夾-->總是啓用-->添加-->選擇路徑並設定共享文件夾名稱-->下一步-->完成-->確定):

在/mnt/hgfs下便是共享的文件夾/目錄:

#未掛載共享目錄之前

kangruojin@kangruojin:/$ ls /mnt/hgfs/
ls: 無法訪問'/mnt/hgfs/': 輸入/輸出錯誤

#掛載共享目錄之後

kangruojin@kangruojin:/$ ls /mnt/hgfs/
workspace

kangruojin@kangruojin:/$ 

kangruojin@kangruojin:~$ cd /mnt/hgfs/workspace/
kangruojin@kangruojin:/mnt/hgfs/workspace$ ll
總用量 53
drwxrwxrwx 1 root root  4096 10月 20 15:52 ./
dr-xr-xr-x 1 root root  4192 3月  29 22:29 ../
drwxrwxrwx 1 root root  4096 9月  13  2018 linux-2.6.24/
drwxrwxrwx 1 root root  4096 9月  13  2018 pgp262ii/
drwxrwxrwx 1 root root  4096 9月  14  2018 sdk-xgs-robo-5.6.1/
drwxrwxrwx 1 root root  4096 9月  13  2018 SourceCode/
drwxrwxrwx 1 root root 28672 7月  20  2018 wireshark-2.6.2-source-code/
kangruojin@kangruojin:/mnt/hgfs/workspace$ 

參考Blog:ubuntu 客戶機安裝VMware tools時出現編譯錯誤,無法與主機共享文件

後來覺得把要共享給Ubuntu的S3C2440,放在原來的H:/workspace/S3C2440/下再共享,不太安全,結構也不太清晰,所以在Windows上創建了一個VHD,將該VHD拆了幾個盤(O、P、Q)再把S3C2440放在O盤下,進行共享;之後再在Linux中用戶根目錄下,執行"ln /mnt/hgfs/O/S3C2440/ -s workspace"爲掛載的目標目錄在默認用戶根目錄下創建一個軟鏈接,便於訪問:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章