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

Mounting a shared NAS folder onto a Paspberry Pi

A Raspberry Pi can be connected to a NAS This post will show how to mount a Raspberry Pi NFS (Linux Network File System).

Introduction to mounting a shared NAS folder to a 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 storage from a NAS device. This will enable the Raspberry Pi OS (Raspbian) to 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 and 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 are 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 use 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 required software

Installing/updating the required packages using the apt-get terminal command:

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 for being 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 mkdir 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 the chmod and chown terminal commands can be used:

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 in 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.

The device can be unmounted using the umount terminal command:

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 Nano can be used:

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 and 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.

Conclusion

Network Attached Storage (NAS) devices can be mounted to a networked Raspberry Pi to share its disk space. This post went through the 5 steps in mounting a shared NAS folder to a Raspberry Pi.

7 comments

Nick Haddock

Hi Renier, great article – after carefully following the instructions, Automount to my NAS works fine. EXCEPT— I’ve configured my system to safely shut down at night as I don’t use it all the time. When I come to power things back on, the NAS takes longer to boot and is therefor not ready by the time the Pi has booted. It misses mounting the NAS drive. I can power up the NAS and wait a couple of minutes before booting the Pi. So, is there a way of asking the Rpi4 to check and mount ‘When’ the NAS becomes available?

David Robottom

Hi Renier,
I am also getting the message:

clnt_create: RPC: Unable to receive

when I enter the “showmount” command.
I have successfully pinged the NAS drive, which is a Synology DS414. The nfs-common and portmap packages were installed successfully.

Any help would be gratefully received.
Thanks in anticipation

David Robottom

Leave a Reply

Your email address will not be published. Required fields are marked *