How to show UUID of a block device and other attributes

root's picture

I can write tons of bla bla about block devices, UUID and all related but the internet (especially wikipedia) is full of this so I will let you do a search if you are more interested about any of this.
So, I will keep it simple: you arrived here because you need a fast way to see the UUIDs of your block devices (call them hdds, partitions, as you like).
There are various tools and commands to achieve that. Read on.

The command blkid

Easy way to see UUIDs is with blkid.

23:23:25 root@service:~# blkid -s UUID
/dev/sdb1: UUID="aI3YWz-bVDK-WGmA-JaXa-oz4Q-o2od-3rB5Bv"
/dev/sda1: UUID="62e9bc3f-d6fe-4c6f-8208-3aae4cf65f5d"
/dev/sda5: UUID="ThMkRa-CvWI-Wd5g-c6ak-C1Ur-guLm-H5Iz3X"
/dev/mapper/rootvg-root: UUID="8ad42698-b6ea-46f0-9285-7acc9871d62f"
/dev/mapper/rootvg-swap: UUID="d8db6cbf-4e8f-411d-a47c-7f198f278a62"
/dev/mapper/dockervg-docker: UUID="2c3d98f7-9af9-4789-8a1a-ad501b077e0f"
/dev/mapper/rootvg-tmp: UUID="d448fe50-15a7-4a77-abb8-a7925477a00b"
/dev/mapper/rootvg-exploit: UUID="3175557f-afc7-4820-8666-1572df6054b5"
/dev/mapper/rootvg-cache: UUID="e93d0230-3fca-4eeb-a690-d119f18cfc29"
/dev/mapper/rootvg-www: UUID="43887e9f-c779-413c-8291-c52e6a6f4f9b"

This tool is quite nice and you can find much more about your block devices (like physical or logical sector sizes, etc.). Read it's manual for more information.

Another useful command is lsblk

This one will show you also a tree view of your block devices. Neat.
Without any options, lsblk won't show you the UUIDs:

23:26:15 root@service:~# lsblk
NAME                MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                   8:0    0   20G  0 disk 
├─sda1                8:1    0  243M  0 part 
├─sda2                8:2    0    1K  0 part 
└─sda5                8:5    0 19.8G  0 part 
  ├─rootvg-root     254:0    0    6G  0 lvm  /
  ├─rootvg-swap     254:1    0  3.7G  0 lvm  [SWAP]
  ├─rootvg-tmp      254:3    0  488M  0 lvm  /tmp
  ├─rootvg-exploit  254:4    0    1G  0 lvm  /exploit
  ├─rootvg-cache    254:5    0    5G  0 lvm  /cache
  ├─rootvg-www      254:6    0    3G  0 lvm  /usr/share/nginx
  └─rootvg-drbd     254:7    0  512M  0 lvm  
sdb                   8:16   0 50.3G  0 disk 
└─sdb1                8:17   0 50.3G  0 part 
  └─dockervg-docker 254:2    0   50G  0 lvm  /docker

For that, you will have to use -o.

23:26:18 root@service:~# lsblk -o "NAME,UUID"
NAME                UUID
sda                 
├─sda1              62e9bc3f-d6fe-4c6f-8208-3aae4cf65f5d
├─sda2              
└─sda5              ThMkRa-CvWI-Wd5g-c6ak-C1Ur-guLm-H5Iz3X
  ├─rootvg-root     8ad42698-b6ea-46f0-9285-7acc9871d62f
  ├─rootvg-swap     d8db6cbf-4e8f-411d-a47c-7f198f278a62
  ├─rootvg-tmp      d448fe50-15a7-4a77-abb8-a7925477a00b
  ├─rootvg-exploit  3175557f-afc7-4820-8666-1572df6054b5
  ├─rootvg-cache    e93d0230-3fca-4eeb-a690-d119f18cfc29
  ├─rootvg-www      43887e9f-c779-413c-8291-c52e6a6f4f9b
  └─rootvg-drbd     
sdb                 
└─sdb1              aI3YWz-bVDK-WGmA-JaXa-oz4Q-o2od-3rB5Bv
  └─dockervg-docker 2c3d98f7-9af9-4789-8a1a-ad501b077e0f

Or -f to see also filesystem types and mount points:

23:33:37 root@service:~# lsblk -f
NAME                FSTYPE      LABEL UUID                                   MOUNTPOINT
sda                                                                          
├─sda1              ext3              62e9bc3f-d6fe-4c6f-8208-3aae4cf65f5d   
├─sda2                                                                       
└─sda5              LVM2_member       ThMkRa-CvWI-Wd5g-c6ak-C1Ur-guLm-H5Iz3X 
  ├─rootvg-root     reiserfs    slash 8ad42698-b6ea-46f0-9285-7acc9871d62f   /
  ├─rootvg-swap     swap              d8db6cbf-4e8f-411d-a47c-7f198f278a62   [SWAP]
  ├─rootvg-tmp      reiserfs    tmp   d448fe50-15a7-4a77-abb8-a7925477a00b   /tmp
  ├─rootvg-exploit  reiserfs          3175557f-afc7-4820-8666-1572df6054b5   /exploit
  ├─rootvg-cache    reiserfs          e93d0230-3fca-4eeb-a690-d119f18cfc29   /cache
  ├─rootvg-www      reiserfs          43887e9f-c779-413c-8291-c52e6a6f4f9b   /usr/share/nginx
  └─rootvg-drbd                                                              
sdb                                                                          
└─sdb1              LVM2_member       aI3YWz-bVDK-WGmA-JaXa-oz4Q-o2od-3rB5Bv 
  └─dockervg-docker reiserfs          2c3d98f7-9af9-4789-8a1a-ad501b077e0f   /docker

Read tool's manual for more.

Via /dev

Yep, /dev is your friend if none of the tools above is in your system (e.g. if you are in some minimal linux without the possibility to install anything on it).

23:17:53 root@service:~# ls -la /dev/disk/by-uuid/
total 0
drwxr-xr-x 2 root root 200 Apr  2 18:16 .
drwxr-xr-x 6 root root 120 Apr  2 18:16 ..
lrwxrwxrwx 1 root root  10 Apr  2 18:16 2c3d98f7-9af9-4789-8a1a-ad501b077e0f -> ../../dm-2
lrwxrwxrwx 1 root root  10 Apr  2 18:16 3175557f-afc7-4820-8666-1572df6054b5 -> ../../dm-4
lrwxrwxrwx 1 root root  10 Apr  2 18:16 43887e9f-c779-413c-8291-c52e6a6f4f9b -> ../../dm-6
lrwxrwxrwx 1 root root  10 Apr  2 18:16 62e9bc3f-d6fe-4c6f-8208-3aae4cf65f5d -> ../../sda1
lrwxrwxrwx 1 root root  10 Apr  2 18:16 8ad42698-b6ea-46f0-9285-7acc9871d62f -> ../../dm-0
lrwxrwxrwx 1 root root  10 Apr  2 18:16 d448fe50-15a7-4a77-abb8-a7925477a00b -> ../../dm-3
lrwxrwxrwx 1 root root  10 Apr  2 18:16 d8db6cbf-4e8f-411d-a47c-7f198f278a62 -> ../../dm-1
lrwxrwxrwx 1 root root  10 Apr  2 18:16 e93d0230-3fca-4eeb-a690-d119f18cfc29 -> ../../dm-5

sda1 = means that is a partition on a disk, you can find more on that with fdisk -l /dev/sda
dm* = those are usually LVM devices and lvm tools like lvs can provide you more details.

However, you will need more commands to map UUIDs with a human understandable name, by combining the output above with the one below.

23:27:49 root@service:~# ls -la /dev/disk/by-id/
total 0
drwxr-xr-x 2 root root 520 Apr  2 18:16 .
drwxr-xr-x 6 root root 120 Apr  2 18:16 ..
lrwxrwxrwx 1 root root   9 Apr  2 18:16 ata-VBOX_HARDDISK_VB78ec805f-d53179e0 -> ../../sda
lrwxrwxrwx 1 root root  10 Apr  2 18:16 ata-VBOX_HARDDISK_VB78ec805f-d53179e0-part1 -> ../../sda1
lrwxrwxrwx 1 root root  10 Apr  2 18:16 ata-VBOX_HARDDISK_VB78ec805f-d53179e0-part2 -> ../../sda2
lrwxrwxrwx 1 root root  10 Apr  2 18:16 ata-VBOX_HARDDISK_VB78ec805f-d53179e0-part5 -> ../../sda5
lrwxrwxrwx 1 root root   9 Apr  2 18:16 ata-VBOX_HARDDISK_VB9350881b-d29e0572 -> ../../sdb
lrwxrwxrwx 1 root root  10 Apr  2 18:16 ata-VBOX_HARDDISK_VB9350881b-d29e0572-part1 -> ../../sdb1
lrwxrwxrwx 1 root root  10 Apr  2 18:16 dm-name-dockervg-docker -> ../../dm-2
lrwxrwxrwx 1 root root  10 Apr  2 18:16 dm-name-rootvg-cache -> ../../dm-5
lrwxrwxrwx 1 root root  10 Apr  2 18:16 dm-name-rootvg-drbd -> ../../dm-7
lrwxrwxrwx 1 root root  10 Apr  2 18:16 dm-name-rootvg-exploit -> ../../dm-4
lrwxrwxrwx 1 root root  10 Apr  2 18:16 dm-name-rootvg-root -> ../../dm-0
lrwxrwxrwx 1 root root  10 Apr  2 18:16 dm-name-rootvg-swap -> ../../dm-1
lrwxrwxrwx 1 root root  10 Apr  2 18:16 dm-name-rootvg-tmp -> ../../dm-3
lrwxrwxrwx 1 root root  10 Apr  2 18:16 dm-name-rootvg-www -> ../../dm-6
lrwxrwxrwx 1 root root  10 Apr  2 18:16 dm-uuid-LVM-bn4Cdi653tbx8tjQKcIRuIIZWT5dAORTXko1bKHrRDRXTn2RuXDVOOnLZcliz4NR -> ../../dm-2
lrwxrwxrwx 1 root root  10 Apr  2 18:16 dm-uuid-LVM-y9N2fwviUSPuRrerxN6hTYDqna8i9KBGE1x2wrFQHKJcbx8l10gmJcHnRsyxqGyZ -> ../../dm-4
lrwxrwxrwx 1 root root  10 Apr  2 18:16 dm-uuid-LVM-y9N2fwviUSPuRrerxN6hTYDqna8i9KBGEhJmnF1mWg1Lb9vZWLzElMMQvbRsR46U -> ../../dm-0
lrwxrwxrwx 1 root root  10 Apr  2 18:16 dm-uuid-LVM-y9N2fwviUSPuRrerxN6hTYDqna8i9KBGM8n2LxuZKeHp6Wfgfpj7OrO3Q5zJfD0r -> ../../dm-1
lrwxrwxrwx 1 root root  10 Apr  2 18:16 dm-uuid-LVM-y9N2fwviUSPuRrerxN6hTYDqna8i9KBGMuLXMmBHeZUuvVlPQLYc1G5o70EefeUp -> ../../dm-3
lrwxrwxrwx 1 root root  10 Apr  2 18:16 dm-uuid-LVM-y9N2fwviUSPuRrerxN6hTYDqna8i9KBGoETe0tQAVsF7L0Vs24B2CRusEjkWkr8o -> ../../dm-7
lrwxrwxrwx 1 root root  10 Apr  2 18:16 dm-uuid-LVM-y9N2fwviUSPuRrerxN6hTYDqna8i9KBGRQvtaVIJ2fXOgpVjvez1YvT0gkKs1NbP -> ../../dm-6
lrwxrwxrwx 1 root root  10 Apr  2 18:16 dm-uuid-LVM-y9N2fwviUSPuRrerxN6hTYDqna8i9KBGTjAaeEy2g7J25hgKRCB5C6ezKDgJVtiP -> ../../dm-5
lrwxrwxrwx 1 root root  10 Apr  2 18:16 lvm-pv-uuid-aI3YWz-bVDK-WGmA-JaXa-oz4Q-o2od-3rB5Bv -> ../../sdb1
lrwxrwxrwx 1 root root  10 Apr  2 18:16 lvm-pv-uuid-ThMkRa-CvWI-Wd5g-c6ak-C1Ur-guLm-H5Iz3X -> ../../sda5

This one shows you also the disk labels (yes, I am using VirtualBox).
What can I say, /dev is your friend if you know how to use it.

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.

Recent content

root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root