raspberry pi

Mount a Network Share at Boot on your Raspberry PI 3

Tracking down information… is the hardest part of it.

I had an interesting time finding all of the commands that would work to mount a network share on my little linux box.

After a bit of trial and error, the steps needed to mount a network drive consist of first creating a mount point:

mkdir pictures

Then to mount the network drive against that location.  You first need to have a network share available.  I have a Synology Drive:

51k5dp6xx7l-_sl1280_

Synology Disk Station

These little boxes are AWESOME for a lot of reasons.  The main one for me is they provide a download and local store of all of my files on GoogleDrive… which is tremendous.  All of the family devices sync to Google’s Cloud, then this little drive downloads it to my local network.

All the convenience of the cloud – none of the risk of Google booting me for some random reason.

Additionally – I get to use the network drive to get access to my pictures for the PI Picture frame.

Anyway… back to the mount.  The Synology drive is at a locally reserved IP on my network.  So I can mount it like this:

sudo mount -t cifs -o username=<USERNAME>,password=<PASSWORD>,vers=1.0 //<RESERVED IP>/homes/admin/GoogleDrive /home/pi/pictures/

If that worked, then you can add an entry to your fstab, which will cause this drive to be ready to go every time the PI boots.

But first… remove the mount:

sudo umount /home/pi/pictures

Then, add a line to your fstab file, like this (I use vim, but nano is a good alternative):

vim /etc/fstab

And add the line (make sure to replace all of the <> entries with the right values, note also the path to the directories you might be after could be a little different.):

//<RESERVED IP>/homes/admin/GoogleDrive  /home/pi/pictures       cifs username=<USERNAME>,password=<PASSWORD>,nofail,x-systemd.automount,x-systemd.requires=network-online.target,x-systemd.device-timeout=1,vers=1.0  0

A good way to figure out what the mount directory should be is to first explore it using the network shares feature of Mac’s Finder or Window’s File Explorer.

Now… check to see if it works with:

mount -av

The “v” gives you the verbose output.  If it failed you’ll see:

mount: failed to parse mount options

If you were successful simply list the files in the mount:

ls /home/pi/pictures

If you see your stuff… Golden!  If not, double check the options in the fstab file to ensure you have all of the right details listed there.

Then reboot your pi.  If all goes well, it should be automatically mounted when the box comes back up.

Combine this with: Boot your PIXEL Based PI into Chromium Kiosk! and you can make a picture frame that has ALL of your photos.

The final result…

The code for this little page is available here.

https://github.com/mamacker/picserver

Note, you’ll need to change the IP address in a few places.  Grep for “192.168.1.33”, and replace with the IP address of your pi.

When you do – make sure you “reserve” the IP in your router, or use the mDNS entry of your pi instead of the IP.  For MDNS check out my article here:

Name your PIs with mDNS – forget the IPs with ZeroConf

6 thoughts on “Mount a Network Share at Boot on your Raspberry PI 3

  1. A more advanced fstab entry is:
    ///homes/admin/GoogleDrive /home/pi/pictures cifs username=,password=,nofail,x-systemd.automount,x-systemd.requires=network-online.target,x-systemd.device-timeout=1,uid=root,gid=root

    This has a couple of interesting additions. Seeing the user and group, as well as making sure it waits for the network before mounting the drive.

    Like

  2. This guide is nearly perfect, except in my case where I was trying to add a folder called ‘Media Library’.

    I found that I had to encapsulate the folder name in single quotes due to the space separating the two words.

    Posting for anyone else that runs into this. I spent 3 hours driving myself crazy on this.

    RIP

    Like

  3. mamaker you are a genius!
    I have had several attempts over the years to auto mount my Synology NAS to the various Raspberry Pi’s I have had. – Just got a second Raspberry Pi 4 (2GB) with the version of Raspbian up to date on 10 March 2020.
    Each time I do various searches and try numerous different commands.
    Each time previously (and before your blog today) they have failed. I give up and manually remount the NAS after every reboot.
    Your version worked!!! Both the command line mount and the auto mount in fstab.
    You have to repost this for everyone so that it comes higher up in the search listings, because it is the only one that has ever worked.

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.