通过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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。