5 steps in mounting a shared NAS folder to a Raspberry Pi

Mounting a shared NAS folder onto a Paspberry Pi
Published: by
Last updated:
Raspberry Pi

Network Attached Storage (NAS) devices are popular to add large amounts of data storage space to a network. A networked Raspberry Pi can also make use of this storage to, for example, make use of its space or to have access to its files. 5 steps in mounting a shared NAS folder to a Raspberry Pi will go through the process using NFS (Linux Network File System).

Assumptions & requirements

All the steps, including the mounting command and making the process automatic after boot-up, will be done from the terminal. The process can also be done through PuTTY.

With this post it is assumed to have an up and running Raspberry Pi with Raspbian installed. Root (sudo) permissions will be necessary. The NAS and the Raspberry Pi is connected to the same network (LAN) via Ethernet or Wi-Fi (not USB).

It is also assumed that the NAS folder (directory) to be mounted is already shared and broadcasted on the LAN. On most NAS devices, folders can be shared on a network using NFS. Other NFS-related settings that might be relevant, e.g. IP (host) filtering and read/write permissions must also be conducive to the purpose of the shared folder. NAS systems with a static IP address will make the process more permanent to maintain.

Note: Not all NAS devices have the ability to grant access to a Raspberry Pi through NFS. Connecting to newer NAS devices, that uses the NFS4 protocols, will not need a different method for connecting and will not be discussed in this post.

The following steps are to be done on the (target) Raspberry Pi.

Step 1 Installing the software

Installing/updating the required packages:

sudo apt-get install nfs-common
sudo apt-get install portmap

nfs-common contains the showmount command.

Step 2 Create the local mount directory

Any mount directory can be used, but Raspbian has a very convenient /mnt directory recommended to be used as a central mounting point.

Assuming the Raspberry Pi’s mount directory was decided to be /mnt/music, it can be created with the following terminal command:

sudo mkdir /mnt/music

Note that the Linux directory structure is case sensitive. Different user permissions/ownerships can be used, but to make the directory accessible to all users on the network use:

sudo chmod -R 777 /mnt/music
sudo chown pi:pi /mnt/music

Step 3 Run rpc.statd

rpc.statd is a little daemon script that ‘listens’ for a reboot notification from other hosts and tells other hosts when the Raspberry Pi reboots. It manages mounted drives after the drive was rebooted. In older versions it was automatically included in the Raspbian boot sequence, but apparently to save space and time it was excluded in later versions.

To run rpc.statd use the following terminal command:

sudo service rpcbind start

To automatically include this daemon in the Raspbian boot sequence, use:

sudo update-rc.d rpcbind enable

and to remove rpc.statd from the Raspbian boot sequence, use:

sudo update-rc.d rpcbind disable

To stop the rpc.statd service, use:

sudo service rpcbind stop

The rpc.statd service only needs to be added to the boot sequence once.

Step 4 Collect the correct data for the mounting command

The following information will be necessary for the mounting command:

  • NAS device’s IP address: 192.168.1.xx
  • The local mounting directory created in step 2 (/mnt/music)
  • The shared folder from the NAS device to be mounted

The showmount command will list all the NAS device folders that are shared through NFS:

showmount -e 192.168.1.xx

where 192.168.1.xx is the IP address of the NAS device. Some NAS devices will also be able to give the shared folder address on the folder sharing section.

Step 5 Run the mount command

Assuming the NAS shared folder address is /shares/Music, The NFS Mount command is used as follows:

sudo mount -t nfs 192.168.1.xx:/shares/Music /mnt/music

which will mount the NAS’s /shares/Music directory to the Raspberry Pi’s /mnt/music directory.

To unmount the device again, use:

sudo umount /mnt/music

where /mnt/music is the local Raspberry Pi directory. Unmounting will only take place when outside the mount directory.

Additional step – Mount at boot

To automatically mount a shared folder during the boot sequence of Raspbian, the mounting command can either be added to Crontab or the rc.local file.

To add the mount command to the rc.local file use:

sudo nano /etc/rc.local

and add the line from step 5 to the bottom of the file.

For Crontab, use:

crontab -e

and add:

@reboot sudo mount -t nfs 192.168.1.xx:/shares/Music /mnt/music

Errors & solutions

NFS Stale File Handle error

Sometimes, while trying to use the NFS Mount command, the following error is displayed:

mount.nfs: Stale NFS file handle

This NFS Stale File Handle error occurs if the directory is modified on the NAS server, but the directories modification time is not updated on Raspbian. To fix this issue, try unmounting the directory and remount it again.

About the author
Renier busies himself with improving his English writing, creative web design and his websites, photoshopping, micro-electronics, multiple genres of music, superhero movies and badass series.
Behind the Scenes is a free, informative website. If you find value in any of our content, please consider making a donation to our cause.
Donate via PayPal

Save, share & Disqus

Use the buttons below, on the left or the bottom of this page to share this post. Your comment is important, but don't be a knob. Keep it constructive and polite.

Comment via Disqus

Disqus is a worldwide comment hosting service for web sites and online communities. This secure platform ensures a pleasant commenting environment which is manageable from one account. Use the Login button to sign up.

More home network related posts

Communicating between 2 Raspberry Pi's using sshpass
Communicating between 2 Raspberry Pis using sshpass
10 September 2016 | Updated 24 October 2018
sshpass is a Linux software package that can be used to establish a direct (secure) connection between two Linux operated computers. This connection allows ‘remote’ access to a ‘local’ computer to run commands ‘locally’. Communicating between 2 Raspberry Pi’s using sshpass will show you how. More…
Raspberry Pi
Understanding common network protocols
Understanding some common network protocols
7 September 2016 | Updated 29 February 2020
Deeper exploration into the world of inter-computer communications will reveal more and more types of communications (e.g. radio waves, Ethernet, Bluetooth, etc.), their interfaces and the network protocols they use. More…