Change website

From Jan 16 2015,


All post content will be move to we's offical website with many content...

Can access website here: http://justox.com

Thanks for your visit!

Thursday, 19 December 2013

Linux: How to retrieve and change partition`s

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
1# 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:
1# blkid /dev/sda1
/dev/sda1: UUID="03136e34-6187-4720-8594-b27508ef978f" TYPE="ext3"
2. udevinfo
1# udevinfo -q all -n /dev/sda1|grep uuid
S: disk/by-uuid/03136e34-6187-4720-8594-b27508ef978f
3. vol_id
1# 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/
1# 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/
1# 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.
1# 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:
1# uuidgen
e845a234-014a-49cf-83c6-785d777294f7
Now we use tune2fs command to change /dev/sda1 partition's UUID:
1# tune2fs /dev/hdb1 -U `uuid`
NOTE: uuidgen and tune2fs are included in e2fsprogs package

No comments:

Post a Comment