HOWTO get a disks UUID number
Linux machines name disks according to their placement on the controllers so the first SATA SSD or HDD would be sda, the second sdb and so on. This is impractical when adding and removing disks so Linux also gives drives a unique UUID number.
If you add drives partitions using paths like
/dev/sdc2 to files like
/etc/crypttab you'll run into trouble if you swap drives around at a later date. Your
/dev/sdc2/ would become
/dev/sdb2 if you pull the second drive. Using UUIDs ensures that the reference to the partition you specify remains the same, the drives ID stays the same regardless of SATA port it's attached to or how many drives are present.
blkid will list all your UUIDs
blkid to get a nice list of all the drives and storage units present and their UUID numbers. This command can be used as a regular user. blkid has some more advanced options too and many of them require you to run it as the
lsblk will give you a nice-looking tree list
lsblk will give you a nice-looking tree view of the drives and partitions attached to the system. This command can list UUIDs but does not do so by default. The trick as laid out in the secret manual page is to add
-o to change the output and
+UUID to get it's standard output + UUID numbers. Thus:
lsblk -o +UUID
will produce an output similar to:
The UUIDs will be listed on the right side of the output. lsblk does not require you to be
|Note: Both |
What if you only know the ata output?
dmesg errors will sometimes refer to something like
ata7.00 - how to do turn that into a UUID?
First step would be to find out what Linux calls the drive in question. This small script will show you what
ataX kernel entries correspond to actual drive names like sda, sdb and so on:
Running this script will output a short list like
sda: 1 sdb: 2 sdc: 5
If you were interested in UUIDs of
ata5.00 which in this case is
sdc you could get the information by running
blkid | grep sdc or
lsblk -o +UUID |grep sdc