Non-Persistant Connection
I have often found it necessary to access files on my raspberry pi that are hosted on either my windows computer, or on an Windows File Server on my Active Directory Network.
In order to mount a network drive you need to have a folder on the RPi ready. This can be anywhere, depending on your needs. If you are going to mount the share permanently, I recommend creating a directory in the /mnt directory. Alternatively, if it is only a quick file access you can create a new directory in the /home/pi folder.
Either way, change directory into the parent directory you are creating a folder in
cd /mnt
or
cd /home/pi
you can now create your new directory
sudo mkdir directory-name
change directory-name to be something of your choosing that corresponds to what you are mounting.
To mount your folder type the following into your terminal
sudo mount -t cifs -o username=yourusername,password=yourpassword //server/share /path/to/directory-name
If you Have got spaces in your //server/share path, enclose the path with double quotes e.g. “//server/share path”. Remember to replace yourusername and yourpassword with the correct values to allow you to log in to your network share.
To check if you have correctly mounted your network share run the following command
df -h
You will see a list of all your mounted volumes, one of which should be the one you mounted above. Alternatively (or as well) navigate to the share path and list the contents of the folder e.g.
cd /mnt/directory-name ls
If there are any files on your share, you will now be able to see them.
Persistent Connection
The initial steps are the same as for a non-persistent connection, however rather than mounting the share via the terminal, we need to mount it via fstab. Edit the fstab
sudo nano /etc/fstab
Append the following lines to the end of fstab.
//server/share /path/to/directory-name cifs username=yourusername,password=yourpassword 0 0
Save the file, and run
more /etc/fstab
Your mount should be listed in information on screen. Reboot your RPi and run
df -h
You should still see your mount, and be able to access your directory.
Unmount a share
Run the following command in the terminal
sudo umount //server/share