Sunday, 24 July 2011

Linux: mount a Windows share with CIFS

When you are a web developer and developing a software run on a Linux platform you might end up running your dev pc with Windows with a Linux virtual machine client. Then comes the question: how to share the source code transparently with the virtual machine and the host?
Here's a possible setup:
Windows 7 host, Ubuntu server in a VMware Player. On the host I share (with the simple Windows share, Samba if you like) my web development directory with all of the sources I would like the Linux server to use as well. Then I mount that share on through a bridged or host-only network interface on the Linux server with the following two choices:

1. Modify /etc/fstab. Add the following line:
//192.168.x.x/hostdir /opt/clientdir cifs username=hostuser,password=hostuserpass,uid=1000,gid=1000,file_mode=0666,dir_mode=0777,noserverino,rw,iocharset=utf8 0 0
2. If you do not have the share served all the time or in some cases it is dynamically available then use this shell script instead to mount it:
#!/bin/sh
mount -t cifs //192.168.x.x/hostdir /opt/clientdir -o username=hostuser,password=hostuserpass,uid=1000,gid=1000,file_mode=0666,dir_mode=0777,noserverino,rw,iocharset=utf8