Accessing a NAS drive from your Raspberry Pi

Often enough, you will need much more storage space than is available on your Raspberry's SD Card. With a few setup files in the Raspbian OS, writing to and reading from a NAS drive in your home network is possible.

The following works for Raspbian Stretch. It is a bit finnicky to set up, and very parameter dependent, so it may or may not work for other Raspbian versions.

When finished, you will have a new folder (here, named as 'WDMyCloud') in your Raspberry's directory structure. It will behave like a local folder on the Raspi's SD card, but it is actually a folder on the NAS drive.


Step 1:
Create a folder on the Pi that you will later mount the NAS share in. That folder needs to be somewhere in the home/pi structure. I have put that folder in the /home/pi/ directory and simply named it after my NAS which, you guessed it, is a WDMyCloud device. In a Raspberry terminal window, create that folder with the following commands:
cd /home/pi 
sudo mkdir DRIVE 

Now, go into your NAS drive's directory and create a new folder that holds all the content you want to share with the Raspi. A word of caution here. I have tried to share a password protected NAS folder with the Pi. I just couldn't get it to work. All sorts of access denied and other errors while trying to access either from my Windows computer, or from the Raspi, or both. Finally, I gave up on the password protection. The shared NAS folder is now simply a folder in the unprotected 'PUBLIC' share.

The network path of that shared folder is http://192.168.1.11/Public/RaspberryPi

I had given my NAS drive a fixed IP Address of 192.168.1.11. For reasons I never fully understand, addressing the NAS drive by its hostname 'WDMyCloud' just doesn't work reliably when accessing from the Raspis. So, whenever I need my Raspi to contact the NAS drive (or other network devices), I use only their (static) IP addresses.
'Public' is the name of the default unprotected share of a WDMyCloud drive.
'RaspberryPi' is the name of the folder I created in that 'Public' share. 'RaspberryPi' will hold all data that my Raspi's will read from or write to.

So, having created the share folders on the Raspi as well as the NAS drive, we can instruct the Raspi to connect to the NAS drive ('mount the drive').

Edit the fstab file with:

sudo nano /etc/fstab


Add this line at the end of that file:
//192.168.1.11/Public/RaspberryPi /home/pi/WDMyCloud cifs auto,x-systemd.automount,username=pi,password=raspberry,_netdev,uid=1000,gid=1000,iocharset=utf8, 0 0

This tells the Raspi to mount the NAS share found at //192.168.1.11/Public/RaspberryPi, this will be mounted on the Pi as a folder called /home/pi/WDMyCloud. Additionally, with the option x-systemd.automount, the mount will automatically be done after earch reboot. Oddly enough, the command only works if I provide a username and password even though the access to the NAS requires neither. For the other options, I have no idea what they do... 

^X, Enter to write the file out and exit. Reboot the Pi, and check if you can find the folder/home/pi/WDMyCloud on the Pi:
If yes: congratulations! If not: grab a coffee and start googling... I'm afraid there's a great number of reasons why it doesn't work... :-( 
 

Comments

Popular posts from this blog

Why yet another Raspberry Pi blog?

Remotely control your Raspberry Pi Zero W from your Windows computer with SSH