Skip to navigation

How to mount a samba share

I have an external harddrive (NAS), the Lacie Ethernet disk mini. Today, I finally figured out how to mount it so that I can rsync to it (thanks to some friendly help on comp.os.linux.misc).

Some info first:

  • The edmini is set up to get an IP address via DHCP. It is then connected to the router (a Netgear box) with a LAN cable. The Netgear is set to reserve the IP address 192.168.0.5 for the hardware address of the edmini’s network card.
  • I want the edmini not to be mounted at boot time, but I want to be able to mount it at any time with “mount edmini”, and then I want to see the data in /home/mpromber/edmini.

Step one: create directory to which you want to mount

mkdir ~/edmini

Can be anything, but you shouldn’t use it for other data.

Step two: create credentials file

If you don’t need a username and password to access the samba share, skip this step. If you do, you could put your username and password into /etc/fstab, but since this file is readable by all, that’s not very secure. So create a file in your home directory:

nano ~/.fstab-edmini-credentials

Of course:

  • Substitute your favorite text editor for nano
  • Pick your own name for the file. Choose something that’s meaningful to you. A dot before the filename is handy to make it hidden: this way it doesn’t clutter your home directory.

Put the following lines in there, substituting your username and password for “foo” and “bar”:
username=foo
password=bar

Make this file readable only by you:

chmod 600 ~/.fstab-edmini-credentials

Step three: add line in /etc/fstab

sudo nano /etc/fstab

The line I have looks like this
(Addendum: modifed, added “intr” option):

//192.168.0.5/ED_mini   /home/mpromber/edmini   smbfs credentials=/home/mpromber/.fstab-edmini-credentials,noauto,users,dmask=755,fmask=644,intr 0 0

Explanation:

  • The first entry is the share you want to mount. “//” goes before a samba share, then the IP address (could be hostname) and the share. Make sure you’ve got this right, else you’re in for “file not found” errors.
  • The second entry is the directory to which you mount.
  • The third is the file type.
  • The fourth are the options, separated by commas and no spaces:
    • we give the credentials file. If you don’t need a username and password, leave this empty, or you may have to put username=defaults,password=defaults here (I haven’t tried this).
    • noauto means “don’t mount at boot time.” You may want to omit this. If you omit this, I think you have to add uid=USERNAME, gid=GROUPNAME, else root will own the mounted directory and your user may not have read/write permissions for it.
    • users means anyone can mount this share, not just root. Probably omit this if you omit “noauto”.
    • dmask=755 sets the directory permissions for the mounted share to 755 (rwx for owner, rw for all others),
    • fmask=644 sets the file permissions to 644 (rw for owner, read only for all others).
    • Addendum:
      intr Option prevents system freeze if you forget to unmount and just turn off the external HD!
  • The two zeroes: the first does something about dumping, which I don’t understand, see man fstab. The last zero tells fsck the order of filesystem checks at boot time. “0” means it won’t be checked. In my /etc/fstab, the root partition has a “1” here, and the /home/ partition a “2”, which makes sense.

Step four

When I tried all this, it didn’t work! I got:

mpromber@audrey:~$ mount edmini
smbmnt must be installed suid root for direct user mounts (1000,1000)
smbmnt failed: 1

but I came across the following, which did the trick:

sudo chmod u+s /usr/bin/smbmnt

How to use it

Now, all you have to do is say:

mount edmini

then you can access the share like any regular directory, copy and move files, etc. When you’re done, if necessary:

umount edmini

That’s it.

Comments are closed.