Posted on
Filesystem

Using `blkid` to View Filesystem UUIDs

Author
  • User
    Linux Bash
    Posts by this author
    Posts by this author

Understanding and Utilizing blkid: A Guide to Viewing Filesystem UUIDs in Linux

For Linux system administrators and enthusiasts, managing and identifying storage devices is a critical task. One of the primary tools that prove indispensable in this context is blkid. This utility allows users to display the UUIDs (Universally Unique Identifiers) along with other crucial filesystem information. In this blog post, we will dive deeper into what blkid is, why UUIDs are important, and how to effectively use this command to manage your system's storage.

What is blkid?

blkid stands for 'block identification' and is a command-line utility in Linux used to find or print block device attributes. This tool can be found in the util-linux package, which is available in most Linux distributions. blkid provides information about available block devices (like hard disks and USB drives), which includes data such as UUIDs, filesystem type, label, and more.

Importance of UUIDs

UUIDs are crucial because they provide a unique identifier for each filesystem, which doesn't change even if the disk is moved to another port or even another system. This stability makes UUIDs highly reliable for mounting filesystems in the /etc/fstab file, rather than traditional device names (like /dev/sda1, /dev/sdb1) which can change based on how or when devices are connected.

How to Use blkid

To get started with using blkid, you simply need to open your terminal and type the blkid command. Here's a basic usage example to kick things off:

sudo blkid

Basic Output

Running this command will give you a list of all block devices and their corresponding UUIDs, as well as other information such as TYPE (the filesystem type) and LABEL (if any). For example, the output might look like this:

/dev/sda1: UUID="504fa85d-11b8-376f-92c7-03ff5d1756ca" TYPE="ext4" PARTUUID="000e1f45-01"
/dev/sda2: UUID="76253a8b-eeee-478b-b433-627de151de37" TYPE="swap" PARTUUID="000e1f45-02"

Advanced Options

blkid also has several options that can be used to filter and manage the output:

  • -o value : Outputs only specific parts of the information. For example, blkid -o value -s UUID will output only the UUIDs of the devices.

  • -s TAG : Allows you to specify which tag (like UUID, TYPE, PARTUUID, etc.) should be displayed.

  • -c /dev/null : Clears the cache before executing, ensuring that you're getting the most recent data.

Practical Examples

Checking UUID for a Specific Device

If you need the UUID of a particular device, you can specify the device name:

sudo blkid /dev/sda1

Using UUID in the fstab File

One practical application of UUIDs from blkid is using them in the /etc/fstab file for stable system mounts:

UUID=504fa85d-11b8-376f-92c7-03ff5d1756ca /               ext4    errors=remount-ro 0       1

This entry tells the system to mount the filesystem found on the device with this UUID at the root directory /.

Conclusion

The blkid utility is a powerful tool for managing and retrieving information about block devices in Linux. By using UUIDs that blkid provides, administrators can ensure that their system mounts are reliable and consistent, regardless of changes in device connections. Whether you're a seasoned sysadmin or a Linux beginner, getting comfortable with blkid and UUIDs will significantly augment your arsenal in system management.

Learning how to use blkid effectively can make handling of disks and filesystems much easier and safer, minimizing risk and maximizing performance of your Linux environment.