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
Easily Monitor CPU Utilization in Linux Terminal With Stress Terminal UI
Viewed 4292 times since Thu, Apr 18, 2019
debian How to Upgrade Debian 8 Jessie to Debian 9 Stretch
Viewed 2515 times since Sun, Sep 23, 2018
awk printf
Viewed 15603 times since Wed, Aug 19, 2020
How to remove CTRL-M (^M) characters from a file in Linux
Viewed 2819 times since Thu, Feb 7, 2019
Linux - How to get Memory information
Viewed 2085 times since Fri, Jun 8, 2018
RHEL: Crash kernel dumps configuration and analysis on RHEL 6
Viewed 5023 times since Sat, Jun 2, 2018
Szybkie sprawdzenie zewnętrznego adresu IP i hosta
Viewed 3541 times since Thu, May 24, 2018
10 Linux rsync Examples to Exclude Files/Directories
Viewed 11134 times since Wed, Oct 31, 2018
Linux Linux Network Statistics Tools / Commands
Viewed 9357 times since Mon, Sep 21, 2020
Red Hat 8 How to Set Up Automatic Updates for CentOS 8
Viewed 3998 times since Fri, Sep 25, 2020