Reduce overhead due to network drive on Raspberry Pi

Problem

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 solutionReduce overhead due to network drive on Raspberry Pi

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

Scope

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

Prerequisite

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 133.134.55.21:/ /home/pi/remote_dir <strong>#Replace </strong><strong>133.134.55.21 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:

TIMEOUT=300 to TIMEOUT=600

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

Reduce overhead due to network drive on Raspberry Pi schematic

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

 

For more detail: Reduce overhead due to network drive on Raspberry Pi


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

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

Scroll to Top