您的位置:首页 > 运维架构 > Linux

linux使用cifs方式mount(挂载)Windows7共享文件

2017-08-15 20:33 1191 查看
说实话,在linux环境下开发应用程序太难了,其实gnome图形界面本身就不可靠,慢的要死,可想而知运行在gnome上的一些可视化IDE(JetBrains家的clion或者qt以及eclipse)能好到哪里去。就可视桌面而言gnome比windows落后了大概20年吧,今年是2017年,centos7的gnome相当于windows95的水准,当然了windows又比mac os落后了10年,三者的差距形成跟unix以及linux操作系统发展史有关。

如果安装centos7或者其他linux发行版本,最好还是选择最小系统,然后勾上开发工具以及基本库,开发的话还是老老实实跑去windows环境,使用visual studio IDE,代码差不多写好以后再去linux上编译调试提交。

另外,我还发现像我这种新手玩家想要入坑linux,那么99%的时间是在搜google整linux环境或者开发工具,只有1%的时间用来写代码或者设计程序。而新手入坑windows则正好相反,我觉得还是把主要精力专注于业务比较好。

设置共享及挂载

linux和windows共享文件,实质还是一个充当文件服务器,另一个充当客户端,然后通过多种协议进行文件传输(push或者pull),smb(server message block )就是其中一个协议,微软自己制订的,现在已经升级为cifs(common internet file system)。最简单的方式是将windows作为服务器把一个文件夹通过网络共享的方式共享出来,然后将linux作为客户端使用cifs方式去mount这个共享。



网上有很多这方面的帖子,windows账户的用户名是xm,密码是1234。linux账户的用户名也是xm,密码也是1234。所以我这边是这样mount的:

[root@localhost /]# mount -t cifs -o username=xm,password=1234,uid=xm,gid=xm //XM-PC/share /home/xm/project


让root以小明的名义把小明的windows共享文件mount到小明的linux工作目录中。

当然这个只是一个demo,root实际还是要在/etc/fstab中进行永久mount的。

设备挂载点文件系统类型选项这是什么东西?
/dev/mapper/cl-root/xfsdefaults0 0
UUID=3488368d-*/bootxfsdefaults0 0
/dev/mapper/cl-swapswapxfsdefaults0 0
//XM-PC/share/home/xm/projectcifsusername=xm,password=1234,uid=1000,gid=10000 0
这样就mount成功了,而且看上去似乎没什么问题,其实坑还是有的。

出现的问题

cp个项目进来(理解为push):

[xm@localhost ~]$ cp -r test project/test


然后就报错:

cp: cannot create regular file ‘project/test/gyp/gyptest.py’: Input/output error

cp: cannot create regular file ‘project/test/gyp/gyp_main.py’: Input/output error

cp: cannot create regular file ‘project/test/gyp/LICENSE’: Input/output error



或者cp个项目出来(理解为pull):

[xm@localhost ~]$ cp -r project/test test


继续报错

cp: cannot open ‘project/test/echo-server.c’ for reading: Input/output error

cp: cannot open ‘project/test/runner.h’ for reading: Input/output error

cp: cannot open ‘project/test/test-tty.c’ for reading: Input/output error

cp: cannot open ‘project/test/test-ipc.c’ for reading: Input/output error



解决方法

说实话这个问题困扰了我2天。



在这里找到一个链接,貌似有用的样子,点进去。



找到了,原来是cifs版本的问题。





win7对应的smb版本是v2.1,但是linux这边mount如果不显式的把版本写出来,那么就会默认为v1.0,而windows那边却强制使用2.1版本的cifs模块,两者当然不能匹配,所以会造成push和pull出现奇怪的麻烦。

SMB protocol version. Allowed values are:

· 1.0 – The classic CIFS/SMBv1 protocol. This is the default.

· 2.0 – The SMBv2.002 protocol. This was initially introduced in

Windows Vista Service Pack 1, and Windows Server 2008. Note

that the initial release version of Windows Vista spoke a

slightly different dialect (2.000) that is not supported.

· 2.1 – The SMBv2.1 protocol that was introduced in Microsoft

Windows 7 and Windows Server 2008R2.

· 3.0 – The SMBv3.0 protocol that was introduced in Microsoft

Windows 8 and Windows Server 2012.

改一下mount命令(同时在/etc/fstab文件中进行修改),在-o 选项后面添加vers=2.1

[root@localhost /]# mount -t cifs -o username=xm,password=1234,uid=xm,gid=xm,vers=2.1 //XM-PC/share /home/xm/project


这是我的



哦,对了,设置完/etc/fstab后,记得用more /proc/mounts命令查看一下当前挂载情况



好了,这样的话,客户端和服务器的cifs协议版本匹配了,然后不管什么样的cp命令就都没问题了。

顺便吐槽一下baidu以及csdn等国内技术性质的blog,完全就是没有责任心,不用心做产品,导致我们这些新人走很多很多的弯路。当然了,我还是服啊,不服气的话我自己又没法去搞个搜索产品或者技术blog出来。真是蛋疼。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: