- blog.up-link.ro - https://blog.up-link.ro -

Linux: How to retrieve and change partition`s UUID

A Universally Unique Identifier (UUID) is an identifier standard used in software construction, standardized by the Open Software Foundation (OSF) as part of the Distributed Computing Environment (DCE).

How to retrieve UUID

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

UUID=03136e34-6187-4720-8594-b27508ef978f /boot ext3 defaults,noatime 1 2

In this case it would be harder to find which partition is mounted behind /boot. Here are some ways how to retrieve relevant partition UUID.

1. blkid

# blkid

/dev/mapper/VolGroup00-LogVol02: TYPE="swap"
/dev/mapper/VolGroup00-LogVol01: UUID="8bd5ec66-b842-4e43-98d1-d717520e025f" TYPE="ext3"
/dev/mapper/VolGroup00-LogVol00: UUID="c7b0bb1f-ea78-46fc-a3f2-f7f4ca79358a" TYPE="ext3"
/dev/sda1: UUID="03136e34-6187-4720-8594-b27508ef978f" TYPE="ext3"
/dev/VolGroup00/LogVol00: UUID="c7b0bb1f-ea78-46fc-a3f2-f7f4ca79358a" TYPE="ext3"
/dev/VolGroup00/LogVol02: TYPE="swap
"

Or you can specify an argument to retrieve a single partition UUID:

# blkid /dev/sda1

/dev/sda1: UUID="03136e34-6187-4720-8594-b27508ef978f" TYPE="ext3"

2. udevinfo

# udevinfo -q all -n /dev/sda1|grep uuid

S: disk/by-uuid/03136e34-6187-4720-8594-b27508ef978f

3. vol_id

# vol_id /dev/sda1 | grep UUID

ID_FS_UUID=03136e34-6187-4720-8594-b27508ef978f
ID_FS_UUID_ENC=03136e34-6187-4720-8594-b27508ef978f

4. /dev/disk/by-uuid/

# ls -l /dev/disk/by-uuid/

total 0
lrwxrwxrwx 1 root root 10 Aug 1 03:42 03136e34-6187-4720-8594-b27508ef978f -> ../../sda1

5. /dev/.udev/db/

# cat /dev/.udev/db/*sda1|grep uuid

S:disk/by-uuid/03136e34-6187-4720-8594-b27508ef978f

6. hwinfo

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

# hwinfo --block
 

How to set or change UUID

Now let's talk about how to change a partition's UUID. We'll use uuidgen to generate uuid string:

# uuidgen

e845a234-014a-49cf-83c6-785d777294f7

Now we use tune2fs command to change /dev/sda1 partition's UUID:

# tune2fs /dev/hdb1 -U `uuid`

NOTE: uuidgen and tune2fs are included in e2fsprogs package