您好,登錄后才能下訂單哦!
通過VMware Tools實現物理機與虛擬機之間的文件共享。然而CentOS 7在安裝(或更新)VMware Tools可能會遇到一些問題,需要手動修改源文件并打包,重新安裝。
環境說明
環境 | 版本 |
---|---|
物理機 | Windows 10 |
VMware | VMware Workstation 12 Pro, 版本是 12.5.2 build-4638234 |
CentOS 7 | kernel-3.10.0-514.21.1.el7.x86_64 |
1、檢查VMware Tools
檢查是否已經安裝了VMware Tools, 如果已經安裝好,可以跳到步驟4,配置共享文件夾。
單擊菜單 虛擬機
如果下拉列表中出現了如下圖所示的 更新 VMware Tools
,則說明已經安裝好了(但這并不意味著能成功配置共享文件夾,如果此時VMware默認的共享目錄/mnt/hgfs/不存在,那基本意味著需要重新安裝了),可以暫時跳過安裝步驟。
如果出現 安裝 VMware Tools ,則直接點擊安裝
2、安裝 VMware Tools
點擊安裝VMware Tools
或更新VMware Tools
后, CentOS會自動掛載VMware Tools, 雙擊打開,將里面的VMwareTools-X.tar.gz復制到桌面上
在桌面打開終端,解壓tar.gz包
進入解壓得到的vmware-tools-distrib目錄,開始安裝(需要已root身份進行),過程中遇到需要輸入信息的,一路回車下去,采用默認設置即可
[hadoop@centos7-2 vmware-tools-distrib]$ sudo ./vmware-install.pl
安裝過程可能不會一路順利,比如會遇到以下錯誤
Using kernel build system. make: Entering directory `/tmp/modconfig-yqRMXf/vmhgfs-only' /bin/make -C /lib/modules/3.10.0-514.21.1.el7.x86_64/build/include/.. SUBDIRS=$PWD SRCROOT=$PWD/. \ MODULEBUILDDIR= modules make[1]: Entering directory `/usr/src/kernels/3.10.0-514.21.1.el7.x86_64' CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/message.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/dir.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/rpcout.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/filesystem.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/cpName.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/link.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/request.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/hgfsUtil.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/file.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/bdhandler.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/transport.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/module.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/super.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/stubs.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/fsutil.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/cpNameLinux.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/hgfsBd.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/backdoorGcc64.o /tmp/modconfig-yqRMXf/vmhgfs-only/backdoorGcc64.o: warning: objtool: BackdoorHbIn()+0xd: duplicate frame pointer save /tmp/modconfig-yqRMXf/vmhgfs-only/backdoorGcc64.o: warning: objtool: BackdoorHbOut()+0xd: duplicate frame pointer save CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/page.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/backdoor.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/hgfsEscape.o CC [M] /tmp/modconfig-yqRMXf/vmhgfs-only/inode.o /tmp/modconfig-yqRMXf/vmhgfs-only/page.c: In function ‘HgfsWbRequestWait': /tmp/modconfig-yqRMXf/vmhgfs-only/page.c:1649:23: warning: passing argument 3 of ‘wait_on_bit' makes integer from pointer without a cast [enabled by default] TASK_UNINTERRUPTIBLE); ^ In file included from include/linux/mmzone.h:9:0, from include/linux/gfp.h:5, from include/linux/mm.h:9, from include/linux/pagemap.h:7, from /tmp/modconfig-yqRMXf/vmhgfs-only/page.c:28: include/linux/wait.h:1044:1: note: expected ‘unsigned int' but argument is of type ‘int (*)(void *)' wait_on_bit(void *word, int bit, unsigned mode) ^ /tmp/modconfig-yqRMXf/vmhgfs-only/page.c:1649:23: error: too many arguments to function ‘wait_on_bit' TASK_UNINTERRUPTIBLE); ^ In file included from include/linux/mmzone.h:9:0, from include/linux/gfp.h:5, from include/linux/mm.h:9, from include/linux/pagemap.h:7, from /tmp/modconfig-yqRMXf/vmhgfs-only/page.c:28: include/linux/wait.h:1044:1: note: declared here wait_on_bit(void *word, int bit, unsigned mode) ^ make[2]: *** [/tmp/modconfig-yqRMXf/vmhgfs-only/page.o] Error 1 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [_module_/tmp/modconfig-yqRMXf/vmhgfs-only] Error 2 make[1]: Leaving directory `/usr/src/kernels/3.10.0-514.21.1.el7.x86_64' make: *** [vmhgfs.ko] Error 2 make: Leaving directory `/tmp/modconfig-yqRMXf/vmhgfs-only'
上網查了下,此時需要修改vmware-tools-distrib/lib/modules/source/vmhgfs-only/page.c
[hadoop@centos7-2 vmware-tools-distrib]$ cd lib/modules/source/ [hadoop@centos7-2 source]$ tar -xvf vmhgfs.tar [hadoop@centos7-2 source]$ cd vmhgfs-only/ [hadoop@centos7-2 vmhgfs-only]$ chmod 777 page.c #該文件是只讀的,這里隨便更改了下權限,只要讓它可寫就行 [hadoop@centos7-2 vmhgfs-only]$ vi page.c # 進入文件編輯模式 :set number # 顯示行號 :1639 # 跳到第1639行,需要對該行進行修改
把第1639行的:
if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) 改成 if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
說明:因為 CentOS 7 的內核版本是 3.10.0
修改保存后,重新歸檔
[hadoop@centos7-2 source]$ mv vmhgfs.tar vmhgfs.tar.bak [hadoop@centos7-2 source]$ tar -cvf vmhgfs.tar vmhgfs-only [hadoop@centos7-2 source]$ cd ../../.. [hadoop@centos7-2 vmware-tools-distrib]$ sudo ./vmware-install.pl
此后一路回車下去,最終看到如下信息,表示安裝成功
Creating a new initrd boot image for the kernel. Starting Virtual Printing daemon: done Starting vmware-tools (via systemctl): [ OK ] The configuration of VMware Tools 10.0.10 build-4301679 for Linux for this running kernel completed successfully. Enjoy, --the VMware team
重新啟動CentOS
3、配置共享文件夾
打開虛擬機設置
進入虛擬機設置
啟用共享文件夾,添加物理機上需要共享的目錄
VMware默認的共享路徑是在/mnt/hgfs
,這是寫死在VMware Tools的腳本里的,我們可以從/etc/init.d/vmware-tools
查到:
vmhgfs_mnt="/mnt/hgfs" #Mount all hgfs filesystems" vmware_mount_vmhgfs() { if [ "`is_vmhgfs_mounted`" = "no" ]; then if [ "`vmware_vmhgfs_use_fuse`" = "yes" ]; then mkdir -p $vmhgfs_mnt vmware_exec_selinux "$vmdb_answer_BINDIR/vmhgfs-fuse \ -o subtype=vmhgfs-fuse,allow_other $vmhgfs_mnt" else vmware_exec_selinux "mount -t vmhgfs .host:/ $vmhgfs_mnt" fi fi }
此時在CentOS 7中就能看到物理機上面共享的文件夾了:
[hadoop@centos7-2 ~]$ ll /mnt/hgfs/ dr-xr-xr-x. 1 root root 0 Jun 15 00:17 pc-share
至此物理機與虛擬機CentOS 7之間的文件夾共享設置就成功了。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。