Skip to main content

HDD Management

You are more than likely to require a HDD or multiple for storage since the RPi microSD card is quite small, typically.

Items discussed:

  • Locate
  • Create mount location
  • Automate mount on reboot

Prerequisites

  • External HDD to connect to your RPi
  • Knowledge of your HDD filetype (ntfs, ext4, etc..)
    • This tutorial is specifically for ntfs or ext4 formatted HDD

Locate your HDD(s)

Using the terminal; let's locate your HDD(s)

df -h

This will list your filesystems on the RPi in a tabular view like below:

FilesystemSizeUsedAvailUse%Mounted on
/dev/root31G10G20G30%/
/dev/mmcblk0p1255M31M225M13%/boot
/dev/sdb11.9T231G1.6T13%/media/pi/my-harddrive

In this example, your harddrive is the filesystem /dev/sdb1

Create mount location

My personal preference is to mount my drives into /mnt directory. You can feel free to use whatever structure you prefer!

Naming my hard drive volume

sudo mkdir /mnt/volume

Setting appropriate permissions

sudo chmod 770 /mnt/volume

Automated Mounting

The goal is to make our HDD mounted to the same directory every boot.

To do this we need to update the /etc/fstab file.

First, let's locate the UUID for the HDD

sudo blkid
  • You will get a response and need to find the line that has the filesystem identified earlier (/dev/sdb1).
  • Copy the value of the UUID in the UUID="this is your uuid"

Next, create a backup of your fstab file

sudo cp /etc/fstab /etc/fstab.backup

Add line to fstab

sudo vim /etc/fstab

Add the following line to your fstab file depending on HDD filetype

  • Remember to replace UUID with the UUID we found in the step before
Important

Keep nofail option in otherwise if you have a type-o in your fstab your RPi may not boot

fstab
# ntfs-3g for ntfs file types
UUID={UUID} /mnt/volume ntfs-3g async,big_writes,nofail,auto,users,permissions 0 0

# ext4 for ext4 file types
UUID={UUID} /mnt/volume ext4 defaults,auto,users,rw,nofail 0 0

For example your fstab may look like if you have ntfs filetype HDD:

fstab
proc            /proc           proc    defaults          0       0
PARTUUID=0d6899fd-01 /boot vfat defaults 0 2
PARTUUID=0d6899fd-02 / ext4 defaults,noatime 0 1
UUID=442840C019EC3B8A /mnt/volume ntfs-3g async,big_writes,nofail,auto,users,exec,permissions 0 0
# a swapfile is not a swap partition, no line here
# use dphys-swapfile swap[on|off] for that

Finished

Now, when you reboot your RPi you will notice that the HDD is mounted at /mnt/volume or wherever your specified!

df -h