Ad Blocking Browser Extension
please consider deactivating it for this website.
Also see our Ads Policy.
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.
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
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 (
- The shared folder from the NAS device to be mounted
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
To unmount the device again, use:
sudo umount /mnt/music
/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
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:
@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.