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.
sudo apt-get install cifs-utils
Create a credentials file (I do this so that special characters don’t affect fstab)
sudo nano /etc/cifsauth
Add this to
Adjust chmod for
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
sudo nano /etc/fstab
Add a new line to
/etc/fstab and edit
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
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
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
sudo mount -a