You can connect your external hard disk drive (HDD) to any of the USB ports on the Raspberry Pi, and mount the file system to access the data stored on your HDD.
By default, Raspberry Pi automatically mounts some of the popular file systems such as FAT, NTFS, and HFS+ at /media/pi/<HARD-DRIVE-LABEL>
location.
To set up your HDD so that it always mounts to a specific location of your choice, you must manually mount your HDD.
If your HDD has an exFAT partition, install the exFAT driver.
Run the following commands in the command line to update the Aptitude repository, then install the exFAT driver using the Aptitude Package Manager.
sudo apt-get update
sudo apt-get install exfat-fuse
You can mount your HDD at specific empty folder locations.
-
Plug in the external HDD to a USB port on the Raspberry Pi.
-
List the disk partitions on the device. Run the following command:
sudo lsblk -o UUID,NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL
The Raspberry Pi uses mount points
/
and/boot
. -
Use the SIZE, LABEL, and MODEL columns to identify the name of the disk partition that points to your HDD. For example,
sda1
. -
Run the following command to get the location of the disk partition.
sudo blkid
For example,
/dev/sda1
. -
Create a target folder to be the mount point of the HDD. The mount point name used in this case is
PIHDD
. You can specify a name of your choice. Run the following command:sudo mkdir /mnt/PIHDD
-
Mount the HDD from the location of the partition to the mount point you created. Run the following command:
sudo mount /dev/sda1 /mnt/PIHDD
-
Verify that the HDD is mounted successfully by listing the content. Run the following command:
ls /mnt/PIHDD
You can modify the fstab
file to define the location where the HDD will be automatically mounted when the Raspberry Pi starts up. In the fstab
file, the disk partition is identified by the universally unique identifier (UUID).
-
Get the UUID of the disk partition. Run the following command:
sudo blkid
-
Find the disk partition from the list and note the UUID. For example,
5C24-1453
. -
Edit the fstab file using a command line editor such as nano. Run the following command:
sudo nano /etc/fstab
-
Add the following line in the
fstab
file.UUID=5C24-1453 /mnt/PIHDD exfat defaults,auto,umask=000,users,rw 0 0
For more information on the Linux commands, refer to the specific manual pages using the man
command. For example, man fstab
.
Before you unmount your HDD, ensure that there are no programs accessing the HDD. You can do this using the lsof
command.
-
Run the following commands to install
lsof
.sudo apt-get update sudo apt-get install -y lsof
-
Get the list of programs using the mount point:
lsof /mnt/PIHDD
where
PIHDD
is the mount point name. -
Manually close all the programs that are using the mount point.
-
Unmount the HDD. Run the following command:
sudo umount /mnt/PIHDD
-
Unplug the HDD and delete the mount point folder . Run the following command:
sudo rmdir /mnt/PIHDD