Skip to content

Instantly share code, notes, and snippets.

@KageKirin
Last active December 11, 2022 23:29
Show Gist options
  • Save KageKirin/2418db9b3e54b03ba46263da925bae89 to your computer and use it in GitHub Desktop.
Save KageKirin/2418db9b3e54b03ba46263da925bae89 to your computer and use it in GitHub Desktop.
Properly mounting harddrives on Raspi (and by extension Linux)

Properly mounting harddrives on Raspi (and by extension Linux)

This guide is intended mostly for my own reference, but I figured it can be of use to others as well.

Conventions

/dev/sdxy is the device/partition to mount/label/..., eg. /dev/sda or /dev/sdb1.

Listing up what we've got

sudo blkid

returns a table like the following

/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="37E2-62C3" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="467086ff-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="6a932c1f-7335-42d9-9351-1b1b2ca538d4" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="467086ff-02"
/dev/sda: LABEL="TIME_MACHINE" UUID="10f1b8d9-6166-4dee-9f6f-bf71aa56379a" BLOCK_SIZE="4096" TYPE="ext4"
/dev/loop0: TYPE="squashfs"
/dev/loop1: TYPE="squashfs"
/dev/sdb: LABEL="DATA_SERVER" UUID="409c8a4c-0629-4fde-b049-82eff80fe308" BLOCK_SIZE="4096" TYPE="ext4"

Hard drives have UUID

Partitions have PARTUUID

Hard drives and partitions can have LABEL

Label makes it the easiest to reference. Label the harddrives/partitions properly.

Partitioning

List partitions

fdisk -l

Partition using fdisk

sudo fdisk /dev/sdx

Partition using parted

sudo parted /dev/sdx

Formatting

EXT4

sudo mkfs.ext4 /dev/sdxy -v Label

HFS+ (only for TimeMachine drives)

sudo mkfs.hfsplus /dev/sdxy -v Label

ZFS

(more involved, TODO)

Labeling

Labeling the device/partition makes it easier to retrieve it, and by extension referencing it in /etc/fstab

sudo e2label /dev/sdxy "HDD_LABEL"

Mounting

mkdir /mnt/mountpoint # by convention, mount stuff in /mnt.
mount /dev/sdxy /mnt/mountpoint

/etc/fstab

LABEL=HDD_LABEL   /mnt/mountpoint   ext4    defaults,noatime  0       2

Reference: fstab documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment