Automatically Mount Samba Shares via Fstab

Long ago I kinda sorta began collecting computers. Well, maybe not collecting as much as hording. Anyway, being as I had so many computers, it was no longer a simple matter of opening an mp3 on my local hard drive and playing it. So I decided to create a file server to store all of my files for easy access from any machine on the network.

So, back on topic. I wanted to be able to mount shares automatically so I wouldn’t have to enter cumbersome commands every time I wanted to play an mp3.

Step 1: Create a folder on your local hard drive to mount your share to.

Open a terminal as root/sudo and type:

mkdir foldername

This will create a folder in your current working directory called foldername. You may want to call it something else though.


Step 2: Open /etc/fstab

as root/sudo type:

nano /etc/fstab

This will open your fstab file in my favorite text editor, nano. You may use vi if you would rather or if there is something wrong with you.

Step 3: Edit /etc/fstab

Add the following line to the end of your fstab replacing the text where applicable. FYI the 0 0 are zeros.

//serverip/share/sharefolder /home/username/foldername smbfs 0 0

Now use ctrl O to write the changes you have made and then ctrl X to exit nano.

Step 4: You’re done wasn’t that easy?

The next time you reboot your shares should be mounted if you did everything right. If you want to mount the shares immediately you can always type:

mount -a

An Example: Here is what your fstab may look like after you have added your shares.

# /etc/fstab: static file system information.

#

#

proc /proc proc defaults 0 0

# /dev/sda1

UUID=59916d5a-286f-41e3-b934-5e5ff7e600a1 / ext3 relatime,noatime,errors=remount-ro 0 1

# /dev/sda5

UUID=65a14b5b-49f5-40d5-abf3-663d4d548c85 none swap sw 0 0

/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec,utf8 0 0

# Samba Documents

//10.10.10.2/share/Private/ash /home/ash/Documents smbfs 0 0

# Samba Videos

//10.10.10.2/share/Public/Video /home/ash/Videos smbfs 0 0


Some things to think about:

This how-to did not cover mounting shares that require user names and passwords. You can simply add the user name and password to your /etc/fstab, but obviously this is highly insecure and using a password file is more advisable.

Unmounting at shutdown bug caused by Gnome Network Manager:

There is a nasty bug where during a shutdown or reboot your system will hang because the network manager has already disconnected your lan connection before smbfs could unmount your shares. There is, however, a work around. I have been using the work around for several weeks without adverse side effects.

  1. No trackbacks yet.