How to retrieve and change partition’s UUID Universally Unique Identifier on linux

On some unix systems a hard drives partition is referred by to as Universally Unique Identifier( UUID ) instead of the location of the it relevant block device file for example like in /etc/fstab:

UUID=A00CB51F0CB4F180      /my/moutn/point     vfat    
defaults,umask=007,gid=46 0 0

In this case it would be harder to find which partition is mounted behind /my/moutn/point. Here are some ways how to retrieve relevant partition UUID. I have listed here 7 ways on how to retrieve UUID so let me know if you know more.

blkid

# blkid
/dev/sda1: UUID="A00CB51F0CB4F180" TYPE="ntfs"
/dev/sda2: UUID="333db32c-b91e-41da-86c7-801c88059660"
TYPE="ext3"
/dev/hdb1: UUID="ec4dfd3a-5811-4967-a28d-ba76c8ad55a9"
TYPE="ext3"
/dev/hdb5: TYPE="swap"

or you can specify argument to retrieve a single partition UUID:

# blkid /dev/sda2
/dev/sda2: UUID="333db32c-b91e-41da-86c7-801c88059660"
TYPE="ext3"

/dev/disk/by-uuid/

another way is to consult /dev/disk/by-uuid/ :

ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 2010-03-23 23:56 333db32c-b91e-41da-86c7-801c88059660 -> ../../sda2
lrwxrwxrwx 1 root root 10 2010-03-23 23:56 A00CB51F0CB4F180 -> ../../sda1
lrwxrwxrwx 1 root root 10 2010-03-23 23:56 ec4dfd3a-5811-4967-a28d-ba76c8ad55a9 -> ../../hdb1

/dev/.udev/db/

the partition information is also stored by udev. cat the file which ends as your block device file of your partition. For example lets get uuid for sda2:

# cat /dev/.udev/db/*sda2 | grep uuid
S:disk/by-uuid/333db32c-b91e-41da-86c7-801c88059660

in other words this is the same UUID which we retrieved previously.

udevadm

yet again retrieve the same information using udevadm command:

#udevadm info -q all -n /dev/sda2 | grep uuid
S: disk/by-uuid/333db32c-b91e-41da-86c7-801c88059660

udevinfo

Same as previous command now we use udevinfo which actually 'udevadm info':

#udevinfo -q all -n /dev/sda2 | grep uuid
S: disk/by-uuid/333db32c-b91e-41da-86c7-801c88059660

vol_id

As it was not already enough we can also use a vol_id command to retrieve UUID from partition:

# vol_id /dev/sda2 | grep UUID
ID_FS_UUID=333db32c-b91e-41da-86c7-801c88059660
ID_FS_UUID_ENC=333db32c-b91e-41da-86c7-801c88059660

hwinfo

another way on how to access a UUID and the hardrives/block devices is to use hwinfo command. hwinfo is not installed by defualt so you may need to install it first:

hwinfo --block

Change UUID

Now let's talk about how to change a partition's UUID. First we need to install uuid command ( if not already installed ) which will help us to generate uuid string: EXAMPLE:

# uuid
3fa4ae0a-365b-11df-9470-000c29e84ddd
# uuid
46a967c2-365b-11df-ae47-000c29e84ddd

NOTE: on some systems you can have uuidgen command instead of uuid !

let's see how it works: old partition UUID:

# vol_id  /dev/hdb1
ID_FS_USAGE=filesystem
ID_FS_TYPE=ext3
ID_FS_VERSION=1.0
ID_FS_UUID=50722b6b-dfd8-4faf-bb27-220fd69b0deb
ID_FS_UUID_ENC=50722b6b-dfd8-4faf-bb27-220fd69b0deb
ID_FS_LABEL=
ID_FS_LABEL_ENC=
ID_FS_LABEL_SAFE=

now we use a tune2fs linux command to change /dev/hdb1 partition's UUID:

# tune2fs /dev/hdb1 -U `uuid`
tune2fs 1.41.3 (12-Oct-2008)

confirm changes:

#vol_id  /dev/hdb1
ID_FS_USAGE=filesystem
ID_FS_TYPE=ext3
ID_FS_VERSION=1.0
ID_FS_UUID=94d5ceae-365b-11df-81ee-000c29e84ddd
ID_FS_UUID_ENC=94d5ceae-365b-11df-81ee-000c29e84ddd
ID_FS_LABEL=
ID_FS_LABEL_ENC=
ID_FS_LABEL_SAFE=
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
sed Delete / Remove ^M Carriage Return (Line Feed / CRLF) on Linux or Unix
Viewed 10430 times since Thu, Feb 7, 2019
RHCS6: Basic operations on clustered services
Viewed 2757 times since Sun, Jun 3, 2018
Linux 20 Netstat Commands for Linux Network Management
Viewed 9723 times since Mon, Sep 21, 2020
ZPOOL: Remove an existing zpool
Viewed 2388 times since Sun, Jun 3, 2018
RHEL: Forgotten ’root’ password / using single-user to gain access
Viewed 7619 times since Sat, Jun 2, 2018
LVM: Reduce SWAP size by shrinking existing Logical Volume
Viewed 6302 times since Sat, Jun 2, 2018
Managing temporary files with systemd-tmpfiles on Red Hat Enterprise Linux 7
Viewed 9716 times since Sun, Nov 22, 2020
RHEL: Back-up/Replicate a partition table
Viewed 3506 times since Sun, May 27, 2018
Procedura powiekszania OCFS2 online
Viewed 5514 times since Fri, Jun 8, 2018
RHCS6: Mirror/unmirror a GFS2 volume
Viewed 5338 times since Sun, Jun 3, 2018