Multiple HDDs attached to Raspberry Pi

One problem that I always faced with the Raspberry Pi: I couldn’t figure out how to attach multiple hard drives to it and still boot from the right one. Thanks to the non-deterministic nature of the drives spinning up, /dev/sdaX will be from whatever drive came first in being available.

But why is spinning up an issue and would I want to attach multiple hard drives?

Well, first of all, I don’t want to use the SD card to run my operating system (I use Kodi as media center). It’l wear out in no time and it is also quite slow. Moving the operating system partition onto a hard drive makes things last longer and faster (after copying a partition using dd or gparted, you just have to change the root parameter in the /boot/cmdline.txt file to point to the right partition).

Secondly, rather than having another RPi for my backup server, I wanted to attached another large external drive to act as my remote rsync end.

And that’s where the spinning up gave me a headache…

However, I came across this post, that explained how to use UUID and PARTUUID instead of device names like /dev/sdaX.

Here is what my IDs look like when running blkid while all hard drives are attached:

pi@kodi:~ $ blkid
/dev/mmcblk0p1: LABEL="boot" UUID="109A-9113" TYPE="vfat" PARTUUID="eb67ae85-01"
/dev/mmcblk0p2: UUID="673b8ab6-6426-474b-87d3-71bff0fcebc3" TYPE="ext4" PARTUUID="eb67ae85-02"
/dev/sda1: LABEL="boot" UUID="109A-9113" TYPE="vfat" PARTUUID="9ecd633f-77b0-4e9f-992a-1757dc0a5c4e"
/dev/sda2: UUID="673b8ab6-6426-474b-87d3-71bff0fcebc3" TYPE="ext4" PARTUUID="7e59eb39-5d2a-4ce5-80dc-7981a01918a2"
/dev/sda3: LABEL="media" UUID="0166275F38583870" TYPE="ntfs" PARTUUID="d7681eeb-202f-4829-a2e9-ef817ed78deb"
/dev/sdb1: LABEL="backup" UUID="c4ef183c-1f98-4e5a-b388-d2d8e393d653" TYPE="ext4"
/dev/sdb2: SEC_TYPE="msdos" LABEL="boot" UUID="DF8E-C7AE" TYPE="vfat" PARTUUID="000b5ea7-02"
/dev/sdb3: UUID="cea0b7ae-2fbc-4f01-8884-3cb5884c8bb7" TYPE="ext4" PARTUUID="000b5ea7-03"

My /boot/cmdline.txt now looks like this (rootwait and rootdelay are important):

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=7e59eb39-5d2a-4ce5-80dc-7981a01918a2 rootfstype=ext4 elevator=deadline rootwait rootdelay=5

And my /etc/fstab like this:

proc /proc proc defaults 0 0

# boot partition
PARTUUID=eb67ae85-01 /boot vfat defaults 0 2

# root partition
PARTUUID=7e59eb39-5d2a-4ce5-80dc-7981a01918a2 / ext4 defaults,noatime 0 1

# media partition
PARTUUID=d7681eeb-202f-4829-a2e9-ef817ed78deb /media/xbmc ntfs permissions,locale=en_US.utf8 0 2

# backup hd
UUID=c4ef183c-1f98-4e5a-b388-d2d8e393d653 /media/backup ext4 defaults,noatime 0 1