Day 3 setting my pi to mount network drives at startup

Another day and another challange.

First off i’m going to use a samba share instead of a NFS with this one.

To mount any network share you need to amend your FSTAB file.

A word of caution first though. You will be messing with system configuration files that can have the potential to destroy your system to the point where where it will not boot and you will have to re-image your sd card.

First off you will need to make a mount point. To do this log into your Pi and create a new directory where you want your share to be mounted to. for instance type ‘sudo mkdir /home/pi/desktop/My_network_share’

then create a file called ‘.smbcredentials’ in the home directory  ‘/home/pi’

enter your log in details for the share in this format, save and exit:

username=MyUsername
password=MyPassword

Next you will have to amend your FSTAB file

To get to your FSTAB file type ‘sudo nano /etc/fstab’

this will open up your file and you should see something like this:

/dev/mmcblk0p1  /boot      vfat    defaults          0       2
/dev/mmcblk0p2  /        ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that

 

amend the end of the file with the following, remember to put your share details in where indicated.

//<share IP address/<share path>  /home/pi/Desktop/<My_network_share>  cifs credentials=/home/pi/.smbcredentials 0 0

save the file and exit.

Next make sure your share will now  mount by typing ‘sudo mount -a’

you should now be able to ‘cd’ to the new file path.  If not then make sure you have put in the correct path in your now amended FSTAB file and try again.

All being well you should have a working share point 🙂

 

 

Leave a comment