blkid useful examples

Similar to lsblk, the blkid is a command-line utility to locate/print block device attributes. To do so, type the following at a shell prompt as root:

# blkid
/dev/sda: UUID="a4dc8beb-1f79-4a54-883c-26bad0570794" TYPE="xfs" LABEL="/dcs07_l4_5"
/dev/sdb1: UUID="e10dc5c0-c27a-4617-8945-daab6d597137" TYPE="ext4"
/dev/sdb2: UUID="8e37d096-4494-4a31-80df-e74b6a8c26e3" TYPE="ext4"
/dev/sdb3: UUID="8b13596f-3647-4289-b8ab-89ce31719e42" TYPE="swap"
/dev/sdb5: UUID="f2b734b2-2e14-44cd-a1c8-2421b7e4d1b7" TYPE="ext4"
/dev/sdb6: UUID="3166aa04-d05e-4b32-a306-939679882090" TYPE="ext4"
/dev/sdb7: UUID="27043be4-5a02-44e3-ad6d-eacc4823c81f" TYPE="ext4"
/dev/sdb8: UUID="63d12776-b54a-454e-b721-e92526980b3f" TYPE="ext4"
/dev/sdb9: UUID="4442fda3-7149-4f78-b114-ac8820c51549" TYPE="ext4"
/dev/sdc1: LABEL="/data" UUID="d21aebfe-716e-11e2-97f7-001a64633f00" TYPE="ext4"
/dev/mapper/dcsunit07_lun4_5: LABEL="/dcs07_l4_5" UUID="a4dc8beb-1f79-4a54-883c-26bad0570794" TYPE="xfs"
As it says in its own man page
       The  blkid  program  is  the  command-line  interface to working with libblkid(3) library.
  It can determine the type of content (e.g.
filesystem, swap) a block device holds, and also
attributes (tokens, NAME=value pairs) from the content metadata (e.g. LABEL  or  UUID
fields).
It has two types of operations, display and search.

Display: The very first example shows all block devices on the host
# blkid -i /dev/sdc1
MINIMUM_IO_SIZE=512
PHYSICAL_SECTOR_SIZE=512
LOGICAL_SECTOR_SIZE=512

# blkid -p /dev/sdc1

/dev/sdc1: LABEL="/data" UUID="d21aebfe-716e-11e2-97f7-001a64633f00" VERSION="1.0" TYPE="ext4" USAGE="filesystem"

# blkid -po udev /dev/sdc1

ID_FS_LABEL=/data
ID_FS_LABEL_ENC=\x2fdata
ID_FS_UUID=d21aebfe-716e-11e2-97f7-001a64633f00
ID_FS_UUID_ENC=d21aebfe-716e-11e2-97f7-001a64633f00
ID_FS_VERSION=1.0
ID_FS_TYPE=ext4
ID_FS_USAGE=filesystem

# blkid -po full /dev/sdc1
/dev/sdc1: LABEL="/data" UUID="d21aebfe-716e-11e2-97f7-001a64633f00" VERSION="1.0" TYPE="ext4" USAGE="filesystem"
Here is more detail about -o option
       -o format
              Display blkid's output using the specified format.  The format parameter may be:
              full   print all tags (the default)
              value  print the value of the tags
              list   print the devices in a user-friendly format, this output format is unsupported for low-level probing (-p or -i)
              device print the device name only, this output format is always enabled for -L and -U options
              udev   print key="value" pairs for easy import into the udev environment
              export print key=value pairs for easy import into the environment.  This output format is automatically enabled when I/O Limits (-i option) are requested.
 

Search operations

# blkid -U 8b13596f-3647-4289-b8ab-89ce31719e42
/dev/sdb3


# blkid -L /data
/dev/sdc1

# blkid -l -t TYPE=ext4
/dev/sdb1: UUID="e10dc5c0-c27a-4617-8945-daab6d597137" TYPE="ext4"

# blkid -l -t UUID=d21aebfe-716e-11e2-97f7-001a64633f00
/dev/sdc1: LABEL="/data" UUID="d21aebfe-716e-11e2-97f7-001a64633f00" TYPE="ext4"

# blkid -l -t UUID=a4dc8beb-1f79-4a54-883c-26bad0570794
/dev/mapper/dcsunit07_lun4_5: LABEL="/dcs07_l4_5" UUID="a4dc8beb-1f79-4a54-883c-26bad0570794" TYPE="xfs"

# blkid -l -t LABEL=/data                             
/dev/sdc1: LABEL="/data" UUID="d21aebfe-716e-11e2-97f7-001a64633f00" TYPE="ext4"

# blkid -l -t TYPE=swap
/dev/sdb3: UUID="8b13596f-3647-4289-b8ab-89ce31719e42" TYPE="swap"
Note: When you specify TYPE in -t option, it only shows the first device which matchs, I don't like this.

One thing need to mention is that -p and -i are low level probing options, which they bypass cachefiles, default is /etc/blkid/blkid.tab, so when you use low level probing options, you can also specify other options like -s and -u to restrict probing functions
 Low-level probing options:
  -p          low-level superblocks probing (bypass cache)

  -i          gather information about I/O limits
  -S <bytes>  overwrite device size
  -O <bytes>  probe at the given offset
  -u <list>   filter by "usage" (e.g. -u filesystem,raid)
       -u  list
              Restrict probing functions to defined (comma separated) list of "usage" types.
  Supported usage types  are:  filesystem,  raid,
crypto and other.
The list can be prefixed with "no" to specify the usage types which should be ignored.
For example:

              blkid -p -u filesystem,other /dev/sda1
              probes for all filesystems and others (e.g. swap) formats, and
              blkid -p -u noraid /dev/sda1
              probes for all supported formats exclude RAIDs. This option is useful with -p only.