VMware中CentOS 7设置文件夹共享的方法

时间:2021-11-17 13:44:44

通过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中CentOS 7设置文件夹共享的方法

如果出现 安装 vmware tools ,则直接点击安装

2、安装 vmware tools

点击安装vmware tools更新vmware tools后, centos会自动挂载vmware tools, 双击打开,将里面的vmwaretools-x.tar.gz复制到桌面上

VMware中CentOS 7设置文件夹共享的方法

在桌面打开终端,解压tar.gz包

复制代码 代码如下:

[hadoop@centos7-2 desktop]$ tar -xzvf vmwaretools-10.0.10-4301679.tar.gz

 

 

进入解压得到的vmware-tools-distrib目录,开始安装(需要已root身份进行),过程中遇到需要输入信息的,一路回车下去,采用默认设置即可

?
1
[hadoop@centos7-2 vmware-tools-distrib]$ sudo ./vmware-install.pl

安装过程可能不会一路顺利,比如会遇到以下错误

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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

?
1
2
3
4
5
6
7
8
[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行的:

?
1
2
3
if linux_version_code >= kernel_version(3, 19, 0)
改成
if linux_version_code >= kernel_version(3, 10, 0)

说明:因为 centos 7 的内核版本是 3.10.0

修改保存后,重新归档

?
1
2
3
4
[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

此后一路回车下去,最终看到如下信息,表示安装成功

?
1
2
3
4
5
6
7
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中CentOS 7设置文件夹共享的方法

进入虚拟机设置

启用共享文件夹,添加物理机上需要共享的目录

VMware中CentOS 7设置文件夹共享的方法

vmware默认的共享路径是在/mnt/hgfs,这是写死在vmware tools的脚本里的,我们可以从/etc/init.d/vmware-tools查到:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
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中就能看到物理机上面共享的文件夹了:

?
1
2
[hadoop@centos7-2 ~]$ ll /mnt/hgfs/
dr-xr-xr-x. 1 root root 0 jun 15 00:17 pc-share

至此物理机与虚拟机centos 7之间的文件夹共享设置就成功了。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:http://www.jianshu.com/p/bbb42f6a070c?utm_source=tuicool&utm_medium=referral