4

I have set-up my RPi to automatically mount a NAS drive. My /etc/fstab file looks like:

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p5  /boot           vfat    defaults          0       2
/dev/mmcblk0p6  /               ext4    defaults,noatime  0       1
//192.168.2.11/Videos /home/pi/NASvideos cifs username=NASUSER,password=NASPAS,iocharset=utf8 0 0    
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that

When I start up the RPi and type in ls NASvideos there is no output while the Videos folder on the NAS drive contains files. However, when I then manually mount the drive by typing in sudo mount -a followed by ls NASvideos it now shows the files. I don't understand why I can manually mount the drive like this but it doesn't do it automatically at boot.

2

The problem with the RPi not auto-mounting might have to do with the network not yet being up when it runs the /etc/fstab file (as suggested by user KenR). One can resolve this issue by writing a short script that mounts all drives that is run automatically each time the RPi boots:

Create script in /etc/init.d:

sudo nano /etc/init.d/mountscript

Add the following (or similar) text to the file:

#! /bin/sh
# /etc/init.d/mountscript 

### BEGIN INIT INFO
# Provides:          Mounting of all drives
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Simple script to mount drives at boot
# Description:       Added 30jan 2014
### END INIT INFO

#Now mount all drives
sudo mount -a
echo "All drives mounted"

Make script executable:

sudo chmod 755 /etc/init.d/mountscript

Test starting the script:

sudo /etc/init.d/mountscript start

Register script to be run at start-up:

sudo update-rc.d mountscript defaults

Reboot the RPi and see if the NAS drive is mounted:

sudo reboot
ls NAMEOFDRIVE

If you ever want to remove the script from start-up

sudo update-rc.d -f  mountscript remove

See more on writing start-up scripts here: http://www.stuffaboutcode.com/2012/06/raspberry-pi-run-program-at-start-up.html

  • 1
    Thanks, this worked perfectly. Was trying quite a few things, but this finally helped. – BadSnowflake Feb 19 at 12:17
2

Setting it to automount worked for me

Append _netdev,x-systemd.automount to your options

For example:

//192.168.2.11/Videos /home/pi/NASvideos cifs username=NASUSER,password=NASPAS,iocharset=utf8,_netdev,x-systemd.automount 0 0    
1

I have experienced a similar problem. The problem, in my case, was that the network was not 'UP' when the pi booted so the fstab mount failed without any messages. This prevented my script from running. I solved it in my script by adding the following few lines at the beginning... while true ; do

if ! ( ping -c 1 My_ROUTER_IP ) > /dev/null

then

   echo "network is NOT up so wait"

   sleep 2

else

   echo "Network is UP"

   sudo mount -a

   break

fi

done

Hope that helps KenR

  • Thanks for your feedback, I decided to write a script that is run at start-up based on your idea, see my answer above. – crazjo Jan 30 '15 at 10:34
0

I tried this suggestion, and it trashed my Pi. The boot process failed with a message "You are in emergency mode" among others, and went into an infinite loop. So I could not complete the boot process and get control to reverse these changes. Thank goodness for backups!
A simpler solution that worked for me is to use cron, with a single schedule entry:
@reboot sudo mount -a
This is using Raspian version 9 (Stretch). Posted Feb 22, 2019

  • Which suggestion? Do you mean one of the previous answers? If that's the case then you should not have added this as a new answer, but as a comment on that answer. – Dirk Feb 23 at 0:04
  • You should take note that using cron to start jobs at boot is not the best way because Crontab suddenly doesn't start jobs. – Ingo Feb 23 at 0:27
0

I used mountscript as outlined above but it still didn't work on boot while working fine if executed manually.

I eventually added $network to the Required-Start line in the script and it now works

  • It might have to do with your rpi not waiting for the network on boot. Check that in your rpi settings. – crazjo Jun 25 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.