2007-09-24

How to permanently mount a windows (samba) share on Ubuntu

These are barebones directions for mounting an NSLU2 drive on an Ubuntu box.

Install the smb file system: sudo apt-get install smbfs

Create a new directory under /media to use as a mount point: sudo mkdir /media/newdirectoryname.

Edit /etc/fstab: sudo nano /etc/fstab

Add a line for the new mount:
//10.10.10.110/DISK\0401 /media/newdirectoryname smbfs username=defaults,password=defaults,uid=username 0 0

Remount filesystem: sudo mount -a

For more detailed instructions: http://www.justlinux.com/nhf/Filesystems/Mounting_smbfs_Shares_Permanently.html

Additional Notes on how to allow users on Linux machine to read and write to a smbfs share that is mounted by adding entry in fstab:

  • The fourth field in an etc/fstab entry specifies the mount options for the drive being mounted. See the fstab man page or http://www.die.net/doc/linux/man/man5/fstab.5.html
  • The fstab man page doesn't give the mount options for every type of file system. For that you need the man page for the file systems. The man page for smbmount gives the syntax for specifying options in this fourth fstab field for smbfs mounts. See http://www.die.net/doc/linux/man/man8/smbmount.8.html
  • You can either use uid=username or gid=groupname to specify what user or group of users is the owner of the smbfs mount.
  • Here is the fstab entry that allowed linux user fred to copy files to smbfs mount on an NSLU2:
  • //10.10.10.110/DISK\0401 /media/nslu2 smbfs username=defaults,password=defaults,uid=fred 0 0
  • EDIT 2008-11-10: I believe that fmask and dmask properties discussed below have been deprecated and you should use umask in their place. I think a single umask=0000 in place of fmask and dmask should work, but I have not verified this.
  • After a lot of trial and error I figured out that its not enough to add the gid=groupname to the fstab entry. You also have to set fmask and dmask values which determine permissions for the mount. This fstab entry allows all members of group fredsfriends to read and write files on an smbfs mount:

    //10.10.10.110/DISK\0401 /media/nslu2 smbfs username=defaults,password=defaults,uid=fred,gid=fredsfriends,
    fmask=770,dmask=770 0 0
  • Apparently if you don’t set fmask and dmask then it uses the system default (umask value?) for file and directory permissions, which on my ubuntu install was read access but not write access.
  • I had a hard time finding out what values to use for fmask and dmask, but apparently 777 means all users have read & write access (which was apparently confirmed by running ls -l on the mount, which showed fred fredsfriends -rwxrwxrwx when dmask=777 and fmask=777), and a value of 770 gives read-write access to only the members of the group identified in gid=groupname (ls -l shows fred fredsfriends -rwxrwx—).
  • Another thing to note is that apparently in Linux only the owner of a file can change the timestamp, so a user that has read-write access to a smbfs mount by virtue of being a member of the group specified in gid=groupname will not be able to change timestamps on files on the mount, which means that when that user copies a file to the mount the file’s existing timestamp will not be carried over and instead it will be given the timestamp of when the copy action occurred.