Wednesday, July 30, 2014

Auto Mount SMB Share at Boot

I have an Asus RT-N66U Router and it has two USB ports, one of which I have a 1 TB Western Digital Hard Drive attached.  To access it from my Ubuntu 14.04 box I have to use the BROWSE NETWORK option in Nautilus.  This usually works just fine but I started using a Backup Program called BACK IN TIME which does scheduled backups and it needs the remote server share attached all the time.  What we need to do is make a SMB Network Share (MS Windows Share) Auto Mount on Boot.

It's a little harder to do than just installing a few programs but it's not too bad.  Here's how we do it: (Read the NOTES section before starting)

1.  Open a Terminal Window

2.  Install CIFS (this may already be installed, Mine was)
         sudo apt-get install cifs-utils

3.  Create the mount directory.
          sudo mkdir /media/NautilusName

4.  Open your /etc/fstab file with gedit so you can edit it.
          sudo gedit /etc/fstab

5.  Once gedit opens your fstab file add the following 2 line to the bottom of the file and then save it.
         # Mount Point for Network SMB Share
         //192.168.1.1/ServerShare  /media/NautilusName cifs  guest,uid=1000,iocharset=utf8  0  0

6.  After you add the entry to /etc/fstab type:
         sudo mount -a

This last command will (re)mount all entries listed in /etc/fstab.  Open Nautilus and if you see your NautilusName is listed under NETWORK.  If so your good to go just reboot your computer and your network share will automount.

NOTES

We are connecting to the remote SMB Share as a guest which indicates you don't need a password to access the share.  To learn how to mount password protected shares go here.

NautilusName can be replaced by any name you want and it is what will show up in Nautilus.

//192.168.1.1/ is the IP address of your server and should be changed.

ServerShare is the share name on your server, change it to match yours.


The lines you added to your FSTAB file explained:

uid=1000 makes the Linux user specified by the id the owner of the mounted share, allowing them to rename files.

iocharset=utf8 allows access to files with names in non-English languages. This doesn't work with devices or Windows machines that export their shares using ISO8895-15.
 
If there is any space in the server path, you need to replace it by \040, for example if your server path is  "//servername/My Documents" use this instead  //servername/My\040Documents


Here is an image of the lines I added to my FSTAB file.


 

4 comments:

Anonymous said...

Thanks....I have been scouring the internet for this information.

Anonymous said...

Thanks for the article. What I would really be interested in is finding out how to mount 2 hard drives using both your usb ports. I am struggling with an asus router with 2 usb ports and can only get one drive to work. On another note messing with fstab can render your machine bootless if not done properly.

Jeff M. said...

Anonymous. Maybe this will help, the my ASUS Route has a limit on size of the Hard drive you can attach. 2TB for FAT Format and 3TB for EXT Format. One of your two drives may be exceeding this limit.

lux said...

I have a 500GB drive connected by USB to my RT-AC68U router. I had to construct the smb uri in a slightly different way to make it work. This mounts a folder called "apps"":

//192.168.1.1/apps\040(at\040my_book) /media/usb_share cifs credentials=/home/username/.smbcredentials,uid=1000,iocharset=utf8 0 0

Notice how I had to include spaces in the samba uri, denoted as "\040" and the share is called "apps\040\(at\040my_book)" with "my_book" being the name of my external hard drive.

Since I have permissions set on drive, I created a file called .smbcredentials in my home directory and populated it with:

username=shareuser
password=sharepassword
domain=domain_or_workgroupname

You need to chmod 600 this file