In this tutorial we will describe how to connect your Raspberry Pi to a network drive and permanently mount it to your system. Even though this article uses a Raspberry Pi as an example to connect to an SMB drive, the steps used can be applied to any Debian based system, such as Ubuntu.
If you have a Raspberry Pi you might have noticed that the storage possibilities are kind of limited unless you have some external storage. Even though you can get SD cards with 64+gb of storage, you probably want more if you have a lot of music and movies that you are streaming through your Pi.
There are several choices when it comes to storage for your Pi, such as network drives, flash drives, or external USB HDDs. Using a network drive you can not only access your files from the Pi, but from any computer connected to your network, which is very convenient.
Prerequisites
Before we start, I will assume you already
- have a network drive connected to your LAN, and
- know its LAN IP address
Note: remember to change all text in red to your own values.
Installation
In order to mount the drive, you need to have cifs-utils installed on your system. If you are running a newer version of Raspbian or RaspBMC you should already have this installed. You can check whether it is installed or not by running the following command:
dpkg -s cifs-utils
If it is installed, it should output something like this:
Package: cifs-utils Status: install ok installed Priority: optional Section: otherosfs Installed-Size: 189 Maintainer: Debian Samba Maintainers <pkg-samba-maint@lists.alioth.debian.org> Architecture: armhf Version: 2:5.5-1 ...
If it says that it’s not installed, you need to install it:
sudo apt-get install cifs-utils
Mounting unprotected (guest) network folders
You might have public folders on your network drive that can be accessed by anyone without having to provide any credentials. These are mounted in the same way as password-protected folders (we will mount these in the next section), but with a few different options.
First, let’s create a directory on the Pi where we want to mount the directory. You will need a separate directory for each network folder that you want to mount. I will create the folders in the /media folder:
sudo mkdir -p /media/networkshare/public
Then edit your /etc/fstab file (with root privileges) and add this line:
//192.168.0.18/publicshare /media/networkshare/public cifs guest,uid=1000,gid=1000,iocharset=utf8 0 0
The first part is the IP of your network drive, and the public folder you want to mount.
The second part is the folder on your local machine where you want to mount the network share.
The third part indicates what type of drive you want to mount (cifs).
The last part is the set of options you can pass, and here’s an explanation of the ones we are using:
- guest is basically telling the network drive that it’s a public share, and you don’t need a password to access it (not to confuse with username),
- uid=1000 makes the Pi user with this id the owner of the mounted share, allowing them to rename files,
- gid=1000 is the same as uid but for the user’s group,
- iocharset=utf8 allows access to files with names in non-English languages.
Note: If there is any space in the server path, you need to replace it by \040, for example //192.168.0.18/My\040Documents
To find the uid and gid for your username, use the following command:
id username
Now that we have added this to our /etc/fstab, we need to (re)mount all entries listed in /etc/fstab:
sudo mount -a
Now you can access your network drive from /media/networkshare/public (or wherever you chose to mount it).
Mount password-protected network folders
Mounting a password-protected share is very similar to mounting a public ones, with some minor changes to the options we pass. Let’s start by making a new folder where we want to mount the password-protected share:
sudo mkdir -p /media/networkshare/protected
Again, open /etc/fstab (with root privileges), and add this line:
//192.168.0.18/protectedshare /media/networkshare/protected cifs username=msusername,password=mspassword,uid=1000,gid=1000,iocharset=utf8 0 0
While this is a perfectly valid way of mounting your protected folder, it’s not very secure. Since /etc/fstab is readable by everyone, so are your credentials in it. So, let’s make it more secure by using a credentials file. This file will contain nothing else but your username and password, but we will make readable only to you. This way, other users on the system won’t be able to see your credentials.
Using a text editor, create a file that will contain the credentials for your protected network share:
vim ~/.smbcredentials
Enter your username and password for the protected share in the file:
username=msusername password=mspassword
Save the file.
Change the permissions of the file to make sure only you can read it:
chmod 600 ~/.smbcredentials
Then edit your /etc/fstab file and change the line where we are mounting the protected share to look like this:
//192.168.0.18/protectedhare /media/networkshare/protected cifs credentials=/home/username/.smbcredentials,uid=1000,gid=1000,iocharset=utf8 0 0
Save the file.
Again, we need to (re)mount all entries listed in /etc/fstab:
sudo mount -a
Now you’re all set to access your public and protected folders from your Pi.
I have tried every way mentioned on the web to do this and always get about the same result.
if I leave out the -o part, it will prompt for a password.
It is a Nextar LX smb server with a 300 gb ide drive
I can read it with my main Debian system, and windows xp but not with the pi.
I can read shares on my Debian system with the pi
I know the device and the pi both work they just don’t like each other
I updated the firmware to 48 v 70 but that didn’t help
This is the result and below it is part of fstab
pi@raspberrypi ~ $ sudo mount -av
mount.nfs: timeout set for Fri Aug 22 16:19:16 2014
mount.nfs: trying text-based options ‘rsize=8193,wsize=8192,timeo-14,intr,vers=4,addr=192.168.0.104,clientaddr=192.168.0.110′
mount.nfs: mount(2): Invalid argument
mount.nfs: an incorrect mount option was specified
mount: proc already mounted
mount.cifs kernel mount options: ip=192.168.0.10,unc=\\192.168.0.10\private,umask=000,uid=1000,user=root,pass=********
mount error(22): Invalid argument
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
mount.cifs kernel mount options: ip=192.168.0.10,unc=\\192.168.0.10\Public,guest,iocharset=utf8,uid=1000,gid=1000,user=,pass=********
mount error(5): Input/output error
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
pi@raspberrypi ~ $
#nexstar
//192.168.0.10/private /mnt/2tb/part2 cifs password=,uid=1000,umask=000 0 0
//192.168.0.10/Public /mnt/smb cifs guest,uid=1000,gid=1000,iocharset=utf8 0 0
I have tried every way mentioned on the web to do this and always get about the same result.
if I leave out the -o part, it will prompt for a password.
It is a Nextar LX smb server with a 300 gb ide drive
I can read it with my main Debian system, and windows xp but not with the pi.
I can read shares on my Debian system with the pi
I know the device and the pi both work they just don’t like each other
I updated the firmware to 48 v 70 but that didn’t help
This is the result and below it is part of fstab
pi@raspberrypi ~ $ sudo mount -av
mount.nfs: timeout set for Fri Aug 22 16:19:16 2014
mount.nfs: trying text-based options ‘rsize=8193,wsize=8192,timeo-14,intr,vers=4,addr=192.168.0.104,clientaddr=192.168.0.110′
mount.nfs: mount(2): Invalid argument
mount.nfs: an incorrect mount option was specified
mount: proc already mounted
mount.cifs kernel mount options: ip=192.168.0.10,unc=\\192.168.0.10\private,umask=000,uid=1000,user=root,pass=********
mount error(22): Invalid argument
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
mount.cifs kernel mount options: ip=192.168.0.10,unc=\\192.168.0.10\Public,guest,iocharset=utf8,uid=1000,gid=1000,user=,pass=********
mount error(5): Input/output error
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
pi@raspberrypi ~ $
#nexstar
//192.168.0.10/private /mnt/2tb/part2 cifs password=,uid=1000,umask=000 0 0
//192.168.0.10/Public /mnt/smb cifs guest,uid=1000,gid=1000,iocharset=utf8 0 0
pi@raspberrypi ~ $ smbclient -L Nexstar
WARNING: The security=share option is deprecated
Enter pi’s password:
Sharename Type Comment
——— —- ——-
PUBLIC Disk
Private Disk
SkyDrive Disk
ftp Disk
Notes Disk
Manuals Disk
Projects Disk
Silabs Disk
Portfolio Disk
Music Disk
Users Disk
IPC$ IPC
Server Comment
——— ——-
Workgroup Master
——— ——-
pi@raspberrypi ~ $
I have since found that the same command does not work in my Debian but I can Go to the drive
I don’t have an fstab file – I have an fstab.d directory.
I tried creating a named “default” in fstab.d but that did not work.
Any suggestions?
Just used sudo nano /etc/fstab and I got write access (as opposed to sudo leafpad, then navigating though the file tree)
However now when I sudo mount -a I get:
Couldn’t chdir to /media/networkshare/publicshare: No such file or directory
denote that this is a name you decide for yourself. Please do not type an actual
sudo mkdir /media/
e.g. sudo mkdir /meda/myremoteshare
or
sudo mkdir /media/networkshare
sudo mkdir /media/networkshare/
sudo mkdir /media/whateverTheRemoteShareIsCalled
e.g. sudo mkdir /meda/myremoteshare
or
sudo mkdir /media/networkshare
sudo mkdir /media/networkshare/whateverTheRemoteShareIsCalled
//server/share /mnt/name cifs defaults,rw,username=username,password=password,domain=domain 0 0
correct way
Thanks for the clear no-nonsense tutorial. I’m failing miserably. using Rasperry Pi with rasparian, headless using VNC to access. My server is a toshiba 1Tb hard drive in a USB port on netgear 6200 wifi router. I can access the hard disk fine from Windows8, and via the netgear genie app on my iPad.
the pi can see the ReadyShare, output from nmblookup
root@raspberrypi1:~# nmblookup -A 192.168.0.1
Looking up status of 192.168.0.1
READYSHARE – B
READYSHARE – B
READYSHARE – B
..__MSBROWSE__. – B
WORKGROUP – B
WORKGROUP – B
WORKGROUP – B
MAC Address = 00-00-00-00-00-00
contents of stab
root@raspberrypi1:~# cat /etc/fstab
proc /proc proc defaults 0 0
/dev/mmcblk0p5 /boot vfat defaults 0 2
/dev/mmcblk0p6 / ext4 defaults,noatime 0 1
//192.168.0.1/USB_Share /media/ReadyShare cifs username=admin,password=password,uid=1000,gid=1000,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
root@raspberrypi1:~# sudo mount -a
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
root@raspberrypi1:~#
I’m tearing my hair out. any suggestions please?
Hello Friend, Thank you so much for this guide. It helped me a lot. You explained it so easily for a noob like me.
I successfully mounted guest accessible smb path to my Rtorrent webUI, however there is a part I don’t understand.
When I tested my saving path, everything was okay. Rtorrent downloaded my file (300mb) to the smb path (192.168.0.1/volume1/folder , it’s the router’s usb stick’s sharing path) like I wanted.
But it’s looks like it also downloaded file to (inside raspberry) “/media/networkshare/public” and I don’t know which path is the original file is located?
TL;DR Everytings works I just wonder, when I download a torrent file it also saves the file to “/media/networkshare/public” and also my desired smb path and I dont know which path is the original file located?
If you kindly answer my silly question I’d be thankful, have a nice day take care
was getting error “pi mount error(13): Permission denied” when running command sudo mount -a. fixed by adding “sec=ntlmv2″ to the line in fstab. in case that helps anyone.
YOU ARE THE BEST! I have spent like three days trying too sort that out!
My partition does not mount in the statup – I have following at the startup
root@PI:/home/pi# df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 29G 2.7G 25G 10% /
/dev/root 29G 2.7G 25G 10% /
devtmpfs 214M 0 214M 0% /dev
tmpfs 44M 252K 44M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 88M 0 88M 0% /run/shm
/dev/mmcblk0p1 56M 19M 37M 34% /boot
Also below is my /etc/fstab looks like
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
//192.168.1.110/Public /media/NetworkShare/Public cifs guest,uid=1000,gid=1000,iocharset=utf8 0 0
//192.168.1.110/Sales /media/NetworkShare/Sales cifs username=abcd,password=abcd,uid=1000,gid=1000,iocharset=utf8 0 0 sec=ntlmv2
please help!
Try
//192.168.1.110/Sales /media/NetworkShare/Sales cifs username=abcd,password=abcd,sec=ntlmv2,uid=1000,gid=1000,iocharset=utf8 0 0
YOU RESCUED ME man… I WAS GOING TO GIVE UP! thanks
If you’re editing /etc/fstab and you have drive names, username, passwords, etc. which contain spaces, you may want to try replacing the spaces with ’40’ as escaping backslashes and quotes doesn’t seem to be permitted in the fstab file
Comment system stripped out useful characters from my previous answer. ’40’ should read [backslash][zero]40
Excellent tutorial! I have successfully accessed my Seagate NAS with Raspbian (rpi2) and played a movie. Thank you so much!
Then I had a play with OSMC (installed and running from a different microSD) and used the same tutorial with great effect.
My question is – how do I mount the drives as the OSMC boots up, because it is difficult to get a terminal on there?
I am a very ancient newbie, so please keep it simple!!
Very many thanks!
Works like a charm…