Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Label RAID Drives With QR Codes

I knew this day would come. One of the drives in my RAID array has died and now I need to figure out which one and remove it. Unfortunately, I have not labelled any of the drives, and I am not using any kind of hot swap hard drive cage with activity lights.

Today's Resolution

This means the best course of action I can take (after recovering the BTRFS RAID array) is to keep unplugging one drive at a time before rebooting my computer. When the computer manages to boot the array successfully, I know I have found the failed drive.

A Real Solution.

Going forward, I'm going to use sudo btrfs fi show to list all of the devices in my array.

Label: none  uuid: 7c95ba2a-deb8-4163-aa3c-299667bfcb43
    Total devices 2 FS bytes used 2.00TiB
    devid    1 size 2.73TiB used 2.04TiB path /dev/sdc1
    devid    2 size 2.73TiB used 2.04TiB path /dev/sda

Then I am going to cross-reference the /dev/sd* items against the output of sudo blkid:

/dev/sda: UUID="7c95ba2a-deb8-4163-aa3c-299667bfcb43" UUID_SUB="8d0f5b96-2f93-4afe-b602-c3a8e0497111" TYPE="btrfs" 
/dev/sdb1: UUID="D1AC-53DB" TYPE="vfat" 
/dev/sdb2: UUID="69cdbe20-9773-4036-9e84-d6a48faf4c4b" TYPE="swap" 
/dev/sdb3: UUID="3e81667f-9ed3-417f-816d-d64dd11f2a69" TYPE="ext4" 
/dev/sdc1: UUID="7c95ba2a-deb8-4163-aa3c-299667bfcb43" UUID_SUB="b9371f1c-33ea-4ceb-9fc8-fe374cf9fc8f" TYPE="btrfs"

... to find the UUID of each of the drives in my btrfs array. So for the example above, I want:

/dev/sda: UUID="7c95ba2a-deb8-4163-aa3c-299667bfcb43"
/dev/sdc1: UUID="7c95ba2a-deb8-4163-aa3c-299667bfcb43"

I will then use a QR code generator to print QR codes which I will then stick on the appropriate drives for in future. These QR codes only need to tell me the UUID of the drive, and not bother with the /dev/sd[x] part which would confuse things. We don't record the /dev/sd[x] because these can "move around" as you unplug and re-plug in your drives. However the UUID will always remain the same.

In the future, when a drive fails, I can use btrfs fi show again to list all of the working drives. I then cross reference all of the /dev/sd[x] against the UUIDs from sudo blkid to find all the working UUIDs. Then I can just scan the QR codes on each drive and remove it if it is not in that list.

Last updated: 21st June 2021
First published: 16th August 2018