Hyper-V centos7挂载windows共享文件夹,实现虚拟机编译本地编写

一、实现功能

将windows下的共享文件夹,挂载到centos上,从而可以在centos上操作文件系统。

二、环境

1.centos7.4
2.windows10

三、实现方法

1.windows准备工作

(1)在windows下,新建share文件夹,然后属性设置为共享文件夹。
 白俊遥博客

(2)新建共享文件,理论可以通过//win10的ip/share访问
(3)获得windows10的ip,在命令行输入ipconfig /all

白俊遥博客

3.    在CentOS下,执行挂载命令

(1)    新建挂载目录

mkdir /mnt/win10

(2)挂载远程win10目录

建议用第一条:
[root@localhost ~]# mount -t cifs -o username=root,password=dsg112,rw,uid=1000,gid=1000 //192.168.2.168/wwwroot2 /mnt/win10_2

[root@localhost ~]# mount -t cifs -o username=win10User,password=win10Pw,sec=ntlm //win10Ip/share /mnt/win10
或者
# mount -t cifs -o username=win10User,password=win10Pw //win10Ip/share /mnt/win10
或者
# mount.cifs //win10Ip/share /mnt/win10 -o username=win10User,password=win10Pw

(3)挂载完查看是否挂载成功,输入命令

df -Th

白俊遥博客


其中:

cifis:CIFS(Common Internet File System)文件系统也称通用Internet文件系统,它使程序可以访问远程Internet计算机上的文件并要求此计算机的服务。

win10User/win10Pw:分别是windows用户名和密码
win10Ip:windows的ip
share:windows的共享文件夹
/mnt/win10:最终挂载目录


四、参考

一、如果报错:

mount: 文件系统类型错误、选项错误、192.168.137.101:/data/wwwroot/pc  上有坏超级块、
       缺少代码页或助手程序,或其他错误
       (对某些文件系统(如 nfs、cifs) 您可能需要
       一款 /sbin/mount.<类型> 助手程序)

       有些情况下在 syslog 中可以找到一些有用信息- 请尝试
       dmesg | tail  这样的命令看看。

可以尝试:

yum install cifs-utils -y

或者

yum -y install nfs-utils
systemctl start nfs-utils
systemctl enable nfs-utils

二、如果每次重启之后想让系统自动挂载(前提是宿主机能有固定IP,需要先在路由器中分配好)


方法一:(建议)

在/etc/rc.local文件中添加下列代码,

mount -t cifs -o username=root,password=dsg112,rw,uid=1000,gid=1000 //192.168.2.168/wwwroot2 /mnt/win10_2

在CentOS 7中,rc.local的权限被降低了,所以还要多执行一句

chmod +x /etc/rc.d/rc.local

方法二:

在/etc/fstab文件中添加下列代码,

mount -t cifs -o username=root,password=dsg112,rw,uid=1000,gid=1000 //192.168.2.168/wwwroot2 /mnt/win10_2





白俊遥博客
请先登录后发表评论
  • 最新评论
  • 总共0条评论