Automatically mount a NAS, at boot, on a Raspberry Pi

Cyborg by Son of 8-Bits, on FlickrNow that I am able to control the Raspberry Pi with Synergy, as well as via SSH from another computer on the network, I’d like my multimedia files (music, movies, etcetera) to be readily available to me on the machine. XBMC/OpenElec has neat little GUI’s and even an on screen keyboard to configure your local shares, but Raspbian does not. So we’re gonna mount a NAS via CIFS (or any other CIFS compatible share, like SMB, known as Samba) so I can get to my files.

We’re starting at your home folder (YOUR_USER, pi by default)

$ cd /home/YOUR_USER/

Again, the default username is pi.

$ mkdir NAS

Or any other name you’d like the Folder containing your shares to have. You can use this new folder to mount the NAS, meaning the shared files’ll appear right here. But I made sub-folders because my NAS has multiple shares. If you’d like to make multiple mounts as well, enter:

$ cd NAS

Or the name you picked in the step before this one. and enter:

$ mkdir FOLDER

Name this new subfolder whatever you like, I went with the same name as the shared folder on the NAS so it’ll be easy to recognize. The name of the shared folder on the NAS is the same as SHARED_FOLDER in the text you’ll have to enter below, but first enter:

$ sudo nano /etc/fstab

This file we’ve opened and are about to edit is the file which tells the OS (Raspbian) to mount these shares as soon as you boot/login. (Sidenote: I’m not sure at which point this happens, as I’ve set my Raspberry to boot straight into the Desktop environment, LXDE.)

Go past whatever text is already there and enter the string of data below, don’t forget to edit the CAPITALIZED text to match your info. (Olawd, that rhymed!)


For IP_OF_NAS you can also set the name of the computer, which is also it’s domain name. If you don’t know what this is, ignore it and make sure the local IP of the NAS is correct. The SHARED_FOLDER is the shared folder we’re trying to mount.

Satellite dish by Son of 8-Bits, on FlickrIf you have your NAS set to accept any connection (shared folder-wise) without authentication, you can enter “guest” as the username and leave the password empty. This should work, but is however untested as I’ve secured my own NAS. You can always enter the admin username and password of the device, if you the credentials.

If you’ve entered this correctly it should automatically mount the shared folder(s) on the next login/boot. When you enter the folder(s) we’ve made earlier the files (and folders) contained in the share will appear as if they’re right there on your Raspberry Pi! But in fact it’s still just the NAS. Now you should be able to use these files in your applications. Please note: I can’t delete or edit files unless I use a sudo command, this might be different for you depending on your NAS and it’s configuration. Anyway, if you’re ready to try this auto-mount thing out, reboot the Raspberry Pi by entering:

$ sudo reboot



1 Comment

  • By Tom, 21/07/2015 @ 22:57

    If you’re editing /etc/fstab and you have drive names, username, passwords, etc. which contain spaces, you may want to try replacing the spaces with ’40’ as escaping backslashes and quotes doesn’t seem to be permitted in the fstab file.

Other Links to this Post

RSS feed for comments on this post. TrackBack URI

Leave a comment