5

I have a raspberry pi humming along happily. I'd like it to mount an NFS directory and so I've set up an /etc/fstab rule:

192.168.1.4:/media /mnt/media nfs rw,auto,hard,intr

The directory exists locally and remotely. sudo mount -a as the "pi" user mounts it with no fuss.

My problem is that the directory does not seem to mount automatically if I reboot the pi. I don't want to boot off this directory or anything, I just want it to come up when I do boot.

Any ideas what I'm doing wrong here or possibly any pointers of things I should be looking at?

RPiAwesomeness
  • 3,001
  • 4
  • 30
  • 51
Gregable
  • 153
  • 1
  • 1
  • 3
  • 1
    The problem is almost certainly due to the fact that the network interface is not initialised at the time fstab is executed. Many other seem to have similar problems, particularly with WiFi network. I suggest you put in a script that runs at log on time. – Milliways Mar 03 '14 at 00:46
  • In my case, the network is ethernet, not WiFi. A login script won't work in my use case as I want a script at startup to be able to access the mount rather than a user logging in. I was unsure at what point the mount would be guaranteed available otherwise the startup script could handle this. I was worried that even if the startup script seemed to work, it may depend on a race condition that wouldn't always work. – Gregable Mar 04 '14 at 04:11

6 Answers6

9

I had the same problem as you. In my case, running

sudo raspi-config

and selecting Wait for network at boot/Yes did the trick.

Niclas Börlin
  • 191
  • 1
  • 3
6

A quick and dirt hack would be to edit /etc/rc.local and add "mount /mnt/media". This will automatically be carried out on boot. The correct way, I think, would be to add the nfs-common init script to the default runlevel. This can be done by using the update-rc.d command.

sudo update-rc.d nfs-common enable
Fred
  • 4,552
  • 18
  • 29
1

Another option (requiring a little more work) that you may want to look into is AutoFS. AutoFS will allow you to configure mount points such that they are mounted automatically when the mount point is accessed and unmounted after some time of inactivity. When using this with NFS it can help you reduce your network traffic by only keeping that connection open when it's needed.

http://greenfly.org/tips/autofs.html

http://linux.die.net/man/5/autofs

smokes2345
  • 173
  • 7
0

I hadn't seen all the updated answers on this thread, but managed to find a similar way to mount an NFS drive on my Raspberry Pi 4.

The main prob seems to be that the LAN/network interface is very late coming up / going active.

I added a @reboot on the 1st line of my crontab.

Then ran a small bash script ---

#!/bin/bash

pause 30 sudo mount -a

I'm sure this could be done better, poss the exact NFS mount command, so this bash file is merely running the mount command I previously had to run manually.

MatsK
  • 2,791
  • 3
  • 16
  • 20
0

I had a similar problem. Try the following solution, the last step might be what you want,

Get the uuid of the external hard drive with following command

sudo blkid

Add the entry into fstab so that when you restart the raspberry device it is auto mounted every time

sudo nano /etc/fstab

UUID=0A423D084xxxxxx /mnt/data ntfs defaults,noatime,auto 0 0

Some explanation for above command - I mounted it to /mnt/data directory. ( You need to create it first if doesn't exist with sudo mkdir /mnt/data ) Mine was a NTFS format. You might try only the defaults option. I added noatime and auto to experiment a few things. You can check more details about it on internet.

Some Raspberry device ( including mine ) needs one more addition ( optional, try only if above doesn't work ), after above command, add a 5 seconds delay to loading the device as sometimes the Raspberry OS loads faster than external drive and external hard drive loads a little slower and need more time to start, in this case the external drive isn't auto mounted and it is skipped with an error at the start. Add the following property/value to the end of your cmdline.txt inside /boot folder

sudo nano /boot/cmdline.txt

Add

rootdelay=5

Hope it helps!

Anmol Saraf
  • 121
  • 4
0

I found an answer here:

https://discourse.osmc.tv/t/nfs-kernel-server-wont-start-on-boot/5936/18

From the user "mandelsoft"

Create this file: /etc/systemd/system/nfs-kernel-server.service.d/10-dep.conf

And within it:

[Unit]
Requires=rpcbind.service
After=rpcbind.service

I'm running on MATE for the pi. So other OSes may give you different results, but on my system at least, this fixes the problem reliably.