Mount harddisk for Raspberry Pi / UP Board

2.5 inch hard disks are available in different sizes with 2TB, 3TB and even 4TB, mostly as external source with USB 3.0 connection. The Western Digital (WD) hard drives are best suited for single board computers as they are downward compatible to USB 2.0 (max. 500mA) and therefore do not require an additional power source or Y-cable. WD also offers the so-called WDLabs PiDrive Devices for the Raspberry Pi & Co.

Recommended: Storage - HDD / SSD + cable:

Hard disk with EXT4:

Most hard disks are delivered "ready to use" with a partition in NTFS format and must be reformatted as follows.

pi@raspberrypi:~ $ sudo fdisk -l
...
Disk /dev/mmcblk0: 7.5 GiB, 8010072064 bytes, 15644672 sectors
...
Device         Boot Start      End  Sectors  Size Id Type
/dev/mmcblk0p1       8192    93813    85622 41.8M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      94208 15644671 15550464  7.4G 83 Linux

Disk /dev/sda: 292.5 GiB, 314038026240 bytes, 613355520 sectors
...
Device     Boot Start       End   Sectors   Size Id Type
/dev/sda1        2048 613355519 613353472 292.5G  7 HPFS/NTFS/exFAT

1. Create partition(s)

pi@raspberrypi:~ $ sudo fdisk /dev/sda
...
Command (m for help): p
Device     Boot Start       End   Sectors   Size Id Type
/dev/sda1        2048 613355519 613353472 292.5G 83 Linux

Important: All data will be lost irrevocably!

Commands:

  • Delete partition: d
  • Create a partition: n, p,[enter],[enter],[enter] or a size of +8G
    repeat for more partitions
  • View partition: p
  • Write the changes: w

2. Format partition(s)

pi@raspberrypi:~ $ sudo mkfs.ext4 -L NEW_HDD_NAME -E lazy_itable_init=0,lazy_journal_init=0 /dev/sda1

This formatting avoids the "ext4lazyinit" process, which consumes a low I/O bandwidth (approx. 11-13 Mb/s) in idle mode. You see it if the LED is continuously flashing, but the hard disk not being read or written.

3. Mount partition(s)

pi@raspberrypi:~ $ sudo mkdir /mnt/HDD1
pi@raspberrypi:~ $ sudo mount /dev/sda1 /mnt/HDD1

Hard disk with NTFS:

In this form you can continue to use the hard disk in the Windows world.

1. Install ntfs-3g

pi@raspberrypi:~ $ sudo apt-get install ntfs-3g

2. Mount partition(s)

pi@raspberrypi:~ $ sudo mount -t ntfs-3g -o rw,uid=pi,gid=pi /dev/sda1 /mnt/HDD1

Mount automatically at boot:

To mount hard disks permanently, you can put the above mount command in a start script or enter it into the fstab file. To avoid confusion with multiple hard disks, the device specification (/dev/sda1) should be replaced with the UUID (UUID=59d68b0d-663a-47af-8498-963f61cfbc3d).

1. find out UUID

pi@raspberrypi:~ $ sudo blkid -o list
device               fs_type   label      mount point              UUID
-------------------------------------------------------------------------------------------------------
/dev/mmcblk0p1       vfat      boot       /boot                    B60A-B262
/dev/mmcblk0p2       ext4                 /                        9a7608bd-5bff-4dfc-ac1d-63a956744162
/dev/mmcblk0                              (in use)
/dev/sda1            ext4      TESTHDD    (not mounted)            59d68b0d-663a-47af-8498-963f61cfbc3d

2. Add a hard disk to fstab

pi@raspberrypi:~ $ sudo nano /etc/fstab

UUID=59d68b0d-663a-47af-8498-963f61cfbc3d /mnt/HDD1 ext4 defaults 0 0

or

UUID=59d68b0d-663a-47af-8498-963f61cfbc3d /mnt/HDD1 ntfs-3g defaults,uid=pi,gid=pi,noatime 0 0

Comments:

Allowed HTML-Tags: <strong>, <a href="">, <em>
Info: Comment will be shown shortly after processing.