Automatically Mounting SMB Shares v2.0

  1. This article is outdated!

    I have written a new post with a better mounting method. Please read my new Mounting Windows SMB Shares v3 post before trying anything in this one.

My first guide on automatically mounting SMB shares worked pretty well most of the time. However, I found that after installing updates and rebooting sometimes I would get this error message “Failure Initializing HAL!” and I would not be able to get into the desktop. I realized eventually that if I commented out the two share lines in my fstab file that I could then get into Ubuntu. Then I could re-enable the auto shares until next time I updated when I would have to go through the procedure again.

Another method for automatically mounting a share on boot would be to create a bash script to run when your computer boots up.

First you still have to install SMBFS

sudo apt-get install smbfs

Then you can create the folders in /media for your shares

sudo mkdir /media/Storage

Then you can create a new bash script

gedit ~/.mountshares.sh

put the following line in the file

#~/bin/bash
sudo mount -t smbfs \FILESERVER\storage /media/Storage -o uid=USER,gid=users

Replace FILESERVER with the DNS name of your SMB server and USER with the user name of the local Linux account

Save and close the file and then make it an executable

chmod 775 .mountshares.sh

If you run the script now you will see it prompts you for a password twice. We don’t want to be prompted for a password every time we restart our computer, so we need to create a file called .smbcredentials in our home directory.

gedit ~/.smbcredentials

Then in that file we want to type

user=Guest
password=

and then save the file. If your SMB shares are password protected you would put the SMB credentials above instead of Guest.

Then change the lines in our mountshares.sh file to look like this

sudo mount -t smbfs \FILESERVER\storage /media/Storage -o credentials=/home/USER/.smbcredentials,uid=USER,gid=users

Now we want this script to run after we log into Ubuntu. I was never able to get it to work by adding it to the gnome session startup items so I added it to the init process instead. Open a terminal window and type the following two commands.

sudo cp ~/mountshares.sh /etc/init.d/
sudo update-rc.d mountshares.sh defaults

Now reboot and you should see your share on the desktop.

2 Responses to “Automatically Mounting SMB Shares v2.0”

  1. ChristianM Says:

    Thank you for taking the time creating this guide. Really helpful.

    - ChristianM

  2. Random Says:

    user=Guest
    password=

    didn’t work for me, I had to use:

    username=Guest
    password=

    without it, I would just get : mount error(13): Permission denied

Leave a Reply