I setup network shares all the time on our Ubuntu VMs. The process would be much the same for Raspberry Pi OS.
Step 1 - Backup your uSD - because you can brick the OS with typos in fstab
and RPi OS doesn’t support GRUB for easy fixes.
Install CIFS:
sudo apt-get install cifs-utils
Create a credentials file (I do this so that special characters don’t affect fstab) /etc/cifauth
sudo nano /etc/cifsauth
Add this to /etc/cifauth
username=NAS_USER
password=NAS_USER_PW
Adjust chmod for /etc/cifauth
sudo chmod 600 /etc/cifsauth
Create the target directory (which basically becomes a symbolic link for the mounted drive). Change TARGET
with your preferred foldername
sudo mkdir /media/TARGET
Edit fstab
sudo nano /etc/fstab
Add a new line to /etc/fstab
and edit NAS_STATIC_IP
, NAS_FOLDER_NAME
, TARGET
based on your preferences
//NAS_STATIC_IP/NAS_FOLDER_NAME /media/TARGET cifs guest,uid=pi,gid=pi,credentials=/etc/cifsauth,nofail 0 0
uid=pi
and gid=pi
can be modified if you have changed the default user on the RPi.
And as always, never reboot an operating system after editing fstab without first testing…
sudo umount /media/nas_share/
sudo mount -a
While you may get a warning/error on the first command above (because it was already unmounted), the second command should not error. If untested and there is a typo, you may brick your operating system on the next boot and it gets more complicated quickly.
And that’s it. The whole process will be fully automated every boot.
When the RPi boots, there is a risk that the NAS is offline. This isn’t a huge issue as the fstab
option nofail
is set (the RPi will boot fine, however, no folder will be mounted). When the NAS is online again either restart the RPi (likely preferrable) or run this command to invoke the fstab
configurations:
sudo mount -a