Under most circumstances, connecting any USB storage to a Raspberry Pi will result in the media auto mounting under /media/pi. While this approach is fine for migrating files to and from the Pi it might not be the best solution for a more permanent storage location.
In Raspian, the filesystem mounting is dictated by the fstab file located in /etc. Opening the file reveals its contents. The convention may not be so obvious. A rough explanation of the columns are as follows;
[DEVICE] [MOUNT POINT] [FS FORMAT] [OPTIONS] [BACKUP] [FSCK ORDER]
A detailed explanation of each column can be found in the man file for fstab.
To add our device we need to obtain some information. This will be done by using the mount command. Devices will normally show as mounted on /media/pi/… Ours here is listed as device /dev/sda1
We can get more detailed information on the device by using the blkid command using the -p, probe option. Take note of the UUID and TYPE. We will use this for our new fstab line.
Now using sudo we can open our favorite editor and add the following line.
For the DEVICE column we will use the UUID= label. It is preferred as it will not change, though we could also use PARTUUID= label or even the link /dev/sda1.
An empty folder was created in the /mnt directory and is chosen for our MOUNT POINT.
The FS TYPE was ext4.
Using defaults for OPTIONS should meet general requirements and allow read/write capability to the device. I have added noatime for performance, and nofail for if the drive is ever detached to allow the system to start on boot.
BACKUP is set to 0 and currently I do not see a reason to set otherwise.
FSCK is set to the 3rd device. It is a good idea to have fsck run to ensure integrity of the data.
After saving the changes we should be able to reboot and find our drive mounted in our new location.
Look for more helpful posts coming soon…