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
Secure NTP with NTS
Viewed 8599 times since Sun, Dec 6, 2020
stunnel: Authentication
Viewed 9268 times since Fri, Sep 28, 2018
debian Debian/Ubuntu Linux: Find If Installed APT Package Includes a Fix/Patch Via CVE Number
Viewed 9598 times since Sun, Sep 23, 2018
Stunnel Setup
Viewed 17982 times since Fri, Sep 28, 2018
debian How to check Debian CVE status using python script
Viewed 3727 times since Sun, Sep 23, 2018
10 Linux rsync Examples to Exclude Files/Directories
Viewed 11086 times since Wed, Oct 31, 2018
RHEL: Adding a boot entry to GRUB/GRUB2 configuration
Viewed 4856 times since Sun, May 27, 2018
How to run command or code in parallel in bash shell under Linux or Unix
Viewed 3397 times since Tue, Aug 6, 2019
Linux Customizing Bash
Viewed 2239 times since Sun, Dec 6, 2020
Inxi: Find System And Hardware Information On Linux
Viewed 2441 times since Sat, Jun 2, 2018