How to Get UUID of Hard Disks and Mount using UUID in Linux

The Universally Unique Identifier can be used to identify a device independent form its mount point or device name. This is more and more important as many devices today support hot-plugging or are external anyway. Therefore it makes sometimes sense to access a device (for example in fstab) not by device name but by the UUID.

There are several ways to get the UUID. The first one uses the /dev/ directory. While you are on is you might want to check other by-* directories, I never knew of them.

[root@jira ~]# ls -l /dev/disk/by-uuid
total 0
lrwxrwxrwx. 1 root root 10 May 14 12:06 24136044-94a0-4106-9f06-1be49356b1d5 -> ../../sdc1
lrwxrwxrwx. 1 root root 10 May 14 11:55 69354ec2-9edd-48ed-833b-575bfe25622f -> ../../sdb1
lrwxrwxrwx. 1 root root 10 May 14 11:55 6f5ef646-a484-4b4e-9007-c58bdc85faff -> ../../sda3
lrwxrwxrwx. 1 root root 10 May 14 11:55 93acd8b4-5442-4f42-a4c9-a9ae45e165ef -> ../../sda1
lrwxrwxrwx. 1 root root 10 May 14 11:55 9798da8e-f4a8-4ada-91d9-3a2bda4285e5 -> ../../sda2
[root@jira ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Mon May 14 11:17:45 2012
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=6f5ef646-a484-4b4e-9007-c58bdc85faff /                       ext4    defaults        1 1
UUID=93acd8b4-5442-4f42-a4c9-a9ae45e165ef /boot                   ext4    defaults        1 2
UUID=69354ec2-9edd-48ed-833b-575bfe25622f /data01                 ext4    defaults        1 2
UUID=9798da8e-f4a8-4ada-91d9-3a2bda4285e5 swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

[root@jira ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              67G  2.8G   61G   5% /
tmpfs                 3.9G  100K  3.9G   1% /dev/shm
/dev/sda1             194M   30M  154M  17% /boot
/dev/sdb1             493G  198M  467G   1% /data01
/dev/sdc1             493G  198M  467G   1% /data02

[root@jira ~]# blkid /dev/sda*
/dev/sda1: UUID=”93acd8b4-5442-4f42-a4c9-a9ae45e165ef” TYPE=”ext4″
/dev/sda2: UUID=”9798da8e-f4a8-4ada-91d9-3a2bda4285e5″ TYPE=”swap”
/dev/sda3: UUID=”6f5ef646-a484-4b4e-9007-c58bdc85faff” TYPE=”ext4″
[root@jira ~]#
[root@jira ~]#

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA * Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.