Raspberry PI (all) - mounting a NAS or external drive via USB
If you use an external drive and it is not available it will delay booting, so ensure it is always connected.
Disclaimer: This works fine with my Western Digital (WD) MyCloud drive, I am aware that Synology NAS drives use a different file system and I will provide code for them at a later date. I can’t test every NAS so try the code with caution and test before rebooting to prevent issues. If you can’t reboot, load the SD card into Windows or Linux and use a text editor to comment (#) out the line that you just added.
First, make a folder for your external drive or NAS to load into
cd ~
sudo mkdir myNAS
now let’s edit fstab to make it mount at boot time
check cifs is installed, this allows the drive to be mapped
sudo apt install cifs-utils
then edit fstab (file system table)
sudo nano /etc/fstab
it should look something like this
proc /proc proc defaults 0 0
PARTUUID=ea7d04d6-01 /boot vfat defaults 0 2
PARTUUID=ea7d04d6-02 / ext4 defaults,noatime 0 1
# a swapfile is not a swap partition, no line here# use dphys-swapfile swap[on|off] for that
now add a comment # (so that in 6 months you will remember why you did it) and the line below it like so
# myNAS
//192.168.0.10/private /home/pi/myNAS cifs username=username,password=mypassword
where 192.168.0.10 is the IP address or machine name of your NAS and the folder that you want to share. /home/pi/myNAS is the folder that you created on the PI and username and password are the credentials that you access your NAS with, if any.
exit nano by pressing ctr_x, y to save. If you made a mistake just type n instead of y.
test the mounting by typing
sudo mount -a
after a short delay open the file browser and enter the myNAS folder or type
cd myNAS
ls
if you see files then all is well and you can
sudo reboot
if not either check the new entry in /etc/fstab or put a comment # in front of it before you reboot, then investigate.
Disclaimer: This works fine with my Western Digital (WD) MyCloud drive, I am aware that Synology NAS drives use a different file system and I will provide code for them at a later date. I can’t test every NAS so try the code with caution and test before rebooting to prevent issues. If you can’t reboot, load the SD card into Windows or Linux and use a text editor to comment (#) out the line that you just added.
cd ~
sudo mkdir myNAS
now let’s edit fstab to make it mount at boot time
check cifs is installed, this allows the drive to be mapped
sudo apt install cifs-utils
then edit fstab (file system table)
sudo nano /etc/fstab
it should look something like this
proc /proc proc defaults 0 0
PARTUUID=ea7d04d6-01 /boot vfat defaults 0 2
PARTUUID=ea7d04d6-02 / ext4 defaults,noatime 0 1
# a swapfile is not a swap partition, no line here# use dphys-swapfile swap[on|off] for that
now add a comment # (so that in 6 months you will remember why you did it) and the line below it like so
# myNAS
//192.168.0.10/private /home/pi/myNAS cifs username=username,password=mypassword
where 192.168.0.10 is the IP address or machine name of your NAS and the folder that you want to share. /home/pi/myNAS is the folder that you created on the PI and username and password are the credentials that you access your NAS with, if any.
exit nano by pressing ctr_x, y to save. If you made a mistake just type n instead of y.
test the mounting by typing
sudo mount -a
after a short delay open the file browser and enter the myNAS folder or type
cd myNAS
ls
if you see files then all is well and you can
sudo reboot
if not either check the new entry in /etc/fstab or put a comment # in front of it before you reboot, then investigate.
Happy NAS sharing!
Comments
Post a Comment