Sunday, August 30, 2020

How To Find The UUID of a Device or Filesystem in Linux

How to find the UUID of a Device or Filesystem in Linux

How to find the UUID of a Device or Filesystem in Linux
UUID stands for Universally Unique IDentifier is a unique tag assigned to each and every device partitions attached to the system. Have you ever seen entry in "/etc/fstab" file wherein 128-bits Hex numbers separated by hyphens that looks like UUID="6085679d-f72c-425c-8b00-2d1eb0eb5efe". Such entries are called universally unique identifiers (UUID). This to make hard drive management easier. Suppose you want to attach a new file system or partition on a Linux box and want to make an entry in /etc/fstab file for persistent mounting. You can't do unless you find the UUID of new file systems partitions. UUID's can assure you that the device you are trying to access is the exact device you intended. Kernel will identify the device by it's unique UUID number no matter what type of disks are attached to the system. Here, in this post we are going to see how to find UUID and Modify Persistent Naming Attributes.
Prerequisites:
. Running Instance of Linux system
. root or sudo privileges
Also Read: Red Hat Enterprise Linux 8.1 Installation with Screenshots.
Also Read: CentOS Linux 8 Installation with Screenshots.
. Sample output of "/etc/fstab" (Click on picture below to enlarge it).

Find currently available UUID's of devices or partitions in a system using blkid command (Click on picture below to enlarge it).
#  blkid | grep UUID

Or you can do the following method to determine the UUID's of all currently available partitions (Click on picture below to enlarge it).
# ls -l /dev/disk/by-uuid/

lsblk command prints all block devices with UUID's in tree-like format (Click on picture below to enlarge it).
# lsblk -o name,mountpoint,size,uuid

Also Read: Linux Commands That Every Linux System Administrator Should Know With Examples Part-4

Modifying Persistent Naming Attributes (XFS and EXT4 File System)

Here, we are going to demonstrate how you can change LABEL attribute with friendly name. To  change the UUID or LABEL attributes of an XFS file system, umount the file system and then use the "xfs_admin" utility to change the attribute:
We have one unpartition or raw drive "/dev/sdb" for demo as per below screen. we are going to partition "/dev/sdb" and see how LABEL attribute can be changed (Click on picture below to enlarge it).
# fdisk -l

. Partitioning device using fdisk command (Click on picture below to enlarge it).
#fdisk /dev/sdb

Type 'n' to create new partition and then type 'p' for primary partition and 'w' to write the changes.
Format the newly created partition "/dev/sdb1" and also "UUID" is assigned to device as shown below.
Format Partition
# mkfs.xfs /dev/sdb1
Verify UUID is assigned for partition below (Click on picture below to enlarge it).
# blkid /dev/sdb1

Unmount the partition and use "xfs_admin" command to change LABEL Attribute as per below (Click on picture below to enlarge it):
Umount "/dev/sdb1" partition
# umount /dev/sdb1
List UUID
#blkid /dev/sdb1
Change LABEL Attribute
# xfs_admin -U 18f2ded1-6a90-4968-b4d2-5bd12df87d8b -L New Label /dev/sdb1
# udevadm settle
# blkid /dev/sdb1

Also Read: Linux Commands That Every Linux System Administrator Should Know With Examples Part-1
Modify or create entry in "/etc/fstab" file for persistent mount. In place of "UUID" make an entry of LABEL="New Label" which was created on previous step as highlighted below (Click on picture below to enlarge it).
# vi /etc/fstab

As per above, we have successfully changed LABEL attribute for XFS filesystem. Now we going to see how you can change LABEL attribute with friendly name to EXT4 file system. Below are the steps involved to  change the UUID or LABEL attributes of an EXT4 file system, umount the file system and use tune2fs utility as shown below (Click on picture below to enlarge it).
# umount /dev/sdb1
# tune2fs -U 13fcc10-0916-4c40-b373-ab9195a9d631 -L New Lebel EXT4 /dev/sdb1
# udevadm settle
# blkid /dev/sdb1
# vi /etc/fstab
# mount -a
# df -h

Also Read: Manage User Password Expiration and Aging with Chage Command in Linux.
In this post, we have seen how to find UUID's in Linux, these are the generic steps same can be followed for other variant of Linux. And also we changed the LABEL Attribute for XFS and EXT4 file system. This steps will work for other File Systems (EXT2, EXT3). Please share it and comment in case of any issue in our comment box. Also follow us Our tecluesdotcom Facebook Official Page.

No comments:

Post a Comment

Please do not enter any spam link in the comment box.