This post is an update to two posts I wrote previously on how to make your network shares mount automatically when you start up your Ubuntu Linux computer. In this method we modify the fstab file so that when all the file systems are mounted the network shares are mounted as well.
This method works for me in Ubuntu Gusty Gibbon 7.10 and is probably the most secure. I have only tested this on a wired connection, so I don’t know exactly what will happen if you use this method when using a wireless connection.
First you have to install smbfs:
sudo apt-get install smbfs
Then create a folder inside of the /media directory to mount the share on:
sudo mkdir /media/Storage
You can call it whatever you want, I call it Storage. If you change the name remember to change it below when we edit the fstab file.
Create a credentials file in /root so that you can save your password and have it protected by the root account:
sudo gedit /root/.cifscredentials
Add the following information to the file, but change Guest to your SMB username and add your SMB password.
Note: If your fileserver allows Guest access you can just leave the file as above. If it is password protected you have to put in your username and password.
Save and close the .cifscredentials file.
Now open up your fstab file so that you can add mounting instructions:
sudo gedit /etc/fstab
Add the following line to the bottom of the file:
//192.168.0.10/SHARENAME /media/Storage cifs auto,iocharset=utf8,uid=USER,gid=users,credentials=/root/.cifscredentials,file_mode=0775,dir_mode=0775 0 0
You have to change the following information:
Change 192.168.0.10 to the IP address or DNS name of your server
Change SHARENAME to the share you want to mount
Change USER to your Ubuntu username
The file_mode=0775,dir_mode=0775 part sets the mounted directory as read/write for all users so long as the SMB username you set in .cifscredentials has read/write access.
Now save the file and run the following command to test to see if you mount now works:
sudo mount -a
If that worked you should see a new drive icon on your desktop that lets you access your share. Now try rebooting and see if your shares mount automatically. If everything went as planned you will have a nice little drive mounted on your desktop every time you start up.
SMB Shares with Spaces in the Names
If you have a share with a space in the path you can replace the space with \040. For example:
//192.168.0.10/Storage\040130 /media/Storage\040130 cifs auto,iocharset=utf8,uid=matt,gid=users,credentials=/root/.cifscredentials,file_mode=0775,dir_mode=0775 0 0
This mounts my 130GB drive on my fileserver to a local directory called Storage 130.