1. Overview
When dealing with storage devices and RAID arrays on a Linux system, Universally Unique Identifiers (UUIDs) are essential for distinguishing these components.
In Linux, two commonly used tools for managing storage and RAID arrays are blkid and mdadm. Both tools provide UUIDs, but not in the same manner.
In this tutorial, we’ll dive into the differences in the usage and implications between UUIDs obtained from blkid and mdadm. In addition, we’ll see code snippets to illustrate these distinctions.
2. Understanding UUIDs
A UUID is a 128-bit value that’s unique across all devices and systems. Moreover, it serves as a reliable way to identify many types of objects:
- storage devices
- partitions
- RAID arrays
- filesystems
Furthermore, UUID doesn’t change even when hardware configurations change or devices are reconnected.
2.1. blkid UUIDs
We use the blkid command to discover information about block devices, including their filesystem types and UUIDs.
Let’s explore how to use blkid to retrieve UUIDs:
$ blkid
/dev/sda1: UUID="e825b2cc-02c7-4e0f-bbe1-aebf04f4f4bb" TYPE="ext4"
/dev/sdb1: UUID="3b8c5e23-75e5-4e23-9a3f-8d03c48a7b92" TYPE="ext4"
In this output, we use the blkid command to query information about block devices:
- /dev/sda1 and /dev/sdb1: these devices are typically storage partitions on a disk
- UUIDs associated with the respective block devices
- TYPE=”ext4″ indicates the filesystem type of each block device
Particularly, each device has a UUID associated with it, used to uniquely identify the devices and their filesystems. Moreover, it’s extremely improbable to generate duplicate UUIDs but even if it happens, a given system wouldn’t accept non-unique identifiers.
2.2. mdadm UUIDs
On the other hand, mdadm is a tool that’s commonly used for managing Linux software RAID arrays. It assigns UUIDs to RAID arrays for identification and configuration purposes.
Let’s see how to obtain RAID array UUIDs using mdadm:
$ mdadm --detail --scan
ARRAY /dev/md0 metadata=1.2 UUID=dc6f3ee0:0d10c2e5:e2de8a35:b5e314ad
ARRAY /dev/md1 metadata=1.2 UUID=3d8f1b4f:e978bafc:2efc3002:2efc3002
The output shows details about the RAID arrays present in our system, including their UUIDs. Furthermore, we use the –detail option to provide a more comprehensive and detailed output. Moreover, the –scan option enables mdadm to fetch any missing information from configuration files.
Finally, we can notice a difference in how these UUIDs are represented, specifically their format:
- blkid uses hyphens as separators
- mdadm uses colons as separators
Otherwise, both formats are equivalent.
3. Theoretical Differences
The primary difference between the UUIDs obtained from blkid and mdadm lies in their scope and purpose.
Regarding the scope, UUIDs from blkid are associated with individual storage devices or partitions. In essence, they uniquely identify these devices and their filesystems.
However, UUIDs from mdadm are assigned to RAID arrays, identifying the entire RAID configuration involving multiple devices.
Shifting to their purposes, UUIDs from blkid often reference specific filesystems when mounting partitions or updating /etc/fstab.
On the other hand, UUIDs from mdadm are critical for assembling and managing RAID arrays, ensuring using the correct devices for rebuilding arrays, or maintaining consistent configurations.
4. Practical Differences
After looking at the main differences between UUIDs from blkid and mdadm, we’ll understand them with examples.
4.1. Using blkid
Let’s suppose we want to mount a filesystem located on a specific partition. Accordingly, we can use the UUID obtained from blkid to ensure that we mount the correct partition, regardless of device name changes.
Let’s check a real-life example:
$ UUID=$(blkid -s UUID -o value /dev/sdb1)
$ sudo mount UUID="$UUID" /mnt/mydisk
Firstly, we obtain the UUID using blkid. Particularly, blkid -s UUID -o value /dev/sdb1 extracts the UUID of /dev/sdb1:
- -s UUID searches for a specific attribute of the block device (UUID)
- -o value specifies the output format for the information that blkid provides
- the $UUID variable stores the extracted UUID
Finally, we use the mount command to mount the filesystem using the extracted UUID. As this action requires superuser privileges, we utilize the sudo command.
4.2. Using mdadm
As we saw previously, we use mdadm while dealing with or managing RAID arrays. In the following example, we have a RAID array consisting of /dev/sdc1 and /dev/sdd1.
Now, let’s manage this array using mdadm:
$ UUID="dc6f3ee0:0d10c2e5:e2de8a35:b5e314ad"
$ mdadm --assemble --uuid="$UUID" /dev/md0
First, we initialize a variable named $UUID.
Next, let’s delve deeper into the meanings of the mdadm commands:
- –assemble brings together the RAID array’s devices to function as a single logical unit
- –uuid identifies the UUID we’re using, identified in the first line of the code snippet
After bringing together the constituent devices and allowing them to function as a whole unit, we can perform actions on the RAID array.
For example, we can check its status via /dev/md0:
$ mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Mon Aug 16 14:30:40 2023
Raid Level : raid1
Array Size : 976760832 (931.39 GiB 1000.07 GB)
Used Dev Size : 976760832 (931.39 GiB 1000.07 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Mon Aug 16 14:35:08 2023
State : clean, resyncing
Active Devices : 2
Working Devices : 2
Failed Devices : 0
...
By using the mdadm command with the –detail option, we’re able to see detailed information about the RAID array of /dev/md0.
In summary, the differences lie in the level of management, partition versus RAID array, and the respective utility of each tool in their specific domains.
5. Conclusion
In this article, we learned that UUIDs obtained from blkid and mdadm serve distinct purposes in the realm of storage and RAID management on Linux systems.
We use blkid UUIDs to uniquely identify individual storage devices and partitions for filesystem-related tasks. On the other hand, UUIDs provided by mdadm serve to identify complete RAID arrays, facilitating dependable management of redundancy and ensuring uniform configurations.
Finally, whether we’re mounting filesystems or managing RAID arrays, utilizing the appropriate UUID source ensures accurate and reliable identification of our storage components, contributing to a stable and well-managed system.