Introduction: Reduce Overhead Due to Network Drive on Raspberry Pi

About: Systems Administrator and Software Programmer.


We add a line entry to /etc/fstab when Raspberry Pi needs to automatically mount a network drive. The problem with this approach is that:

Raspberry Pi needs to mount the network drive from the point of when booting up to shutting down. In other words, Raspberry Pi has to use CPU and RAM to keep the mount going all the time even when network drive is not needed. This incurs unnecessary expense on the Raspberry Pi. Further more, if the network drive is offline, the Raspberry Pi will complain and demand that you repair before doing anything else.

To avoid the problem above, we don't use /etc/fstab. Instead, we can manually mount a network drive using the mount command. The problem with using the mount command is that the user executing the mount must be ROOT user. However, only one user can be ROOT.

To avoid the ROOT user requirement, you can configure sudo settings to let every other users use the mount. The problem with this approach is that we have to constantly update sudo settings every time we add new users or remove existing ones. You incur administrative cost.

There is a better solution


The solution is to use an automounter. The automounter automatically mounts only when the directory or files of the network drive is used or needed. The automounter automatically unmounts the network drive after a period of Inactivity thereby eliminating unnecessary overhead. The automounter will mounts for every user and not just for the ROOT user.

The automounter daemon, /usr/sbin/automount is provided by the autofs package


This instructable will show:

  • Install the necessary package
  • Configure the master map to use INDIRECT map
  • Configure the INDIRECT map to mount a Network File System (NFS) drive

This instructable will NOT show how to serve NFS drive


Raspberry Pi running Raspbian OS

NFS server of a remote computer exporting and sharing a network drive to your Raspberry Pi

Step 1: Install Automounter

Open terminal emulator on Raspberry Pi

$sudo apt-get update

$sudo apt-cache show autofs

$sudo apt-get install autofs

Step 2: Identify the Remote Shares to Access

Open terminal emulator

$cd ~

Make a temporary directory for this step

$mkdir /home/pi/remote_dir

Request the NFS server to send all the remote shares available to you

$sudo mount /home/pi/remote_dir <strong>#Replace </strong><strong> with your NFS address</strong>

List all the remote directories shared with your Raspberry Pi

$ls -l /home/pi/remote_dir

Unmount after you have identified the remote share that you want

$sudo umount /home/pi/remote_dir

Delete the temporary directory

$rm -Rf /home/pi/remote_dir

Step 3: Configure Automounter to Unmount After 10 Minutes of Inactivity

This step is optional. By default automount will unmount after 3 minutes of inactivity. I extend the period of inactivity to avoid too much mount-unmount cycles.

Open terminal emulator in Raspberry Pi

$ cd /etc/default
$ vi autofs

Refer to screenshot. Change:


Save the file

Step 4: Configure Master Map

Open terminal emulator

Open master map file

$sudo vi /etc/auto.master

Add the following line at the end, like shown in the screenshot:

/home/pi/music_share    /etc/music.autofs

Save the /etc/auto.master

Create the directory that was specified in auto.master.

$mkdir /home/pi/music_share

Step 5: Create Indirect Map

Open terminal emulator in Raspberry Pi

$cd /etc
$sudo vi /etc/music.autofs

Add the following entry if NFS server is operating in NFSv2, NFSv3 and NFSv4 OR NFSv2 and NFSv3

songs_piano 122.344.55.3:/remote/share   #Replace 122.344.55.3 with your NFS server

Add the following entry if NFS server is operating in NFSv4 ONLY

songs_piano  -fstype=nfs4  122.344.55.3:/remote/share #Replace 122.344.55.3 with your NFS server
        #Replace /remote/share with the one you identified in Step 2

Save the file

automounter will monitor /home/pi/music_share/songs_piano

Step 6: Start Automounter

Open terminal emulator in Raspberry Pi

$sudo service autofs stop
$sudo service autofs start

Step 7: Test

Open terminal emulator in Raspberry Pi

$cd /home/pi/music_share/songs_piano

List the files

$ls -l