Table of Contents
A uuid or universally unique identifier is used to uniquely identify objects. This 128bit standard allows anyone to create a unique uuid.
This chapter takes a brief look at uuid's.
Older versions of Linux have a vol_id utility to display the uuid of a file system.
root@debian5:~# vol_id --uuid /dev/sda1 193c3c9b-2c40-9290-8b71-4264ee4d4c82
Red Hat Enterprise Linux 5 puts vol_id in /lib/udev/vol_id, which is not in the $PATH. The syntax is also a bit different from Debian/Ubuntu/Mint.
root@rhel53 ~# /lib/udev/vol_id -u /dev/hda1 48a6a316-9ca9-4214-b5c6-e7b33a77e860
This utility is not available in standard installations of RHEL6 or Debian6.
Use tune2fs to find the uuid of a file system.
[root@RHEL5 ~]# tune2fs -l /dev/sda1 | grep UUID Filesystem UUID: 11cfc8bc-07c0-4c3f-9f64-78422ef1dd5c [root@RHEL5 ~]# /lib/udev/vol_id -u /dev/sda1 11cfc8bc-07c0-4c3f-9f64-78422ef1dd5c
There is more information in the manual of uuid, a tool that can generate uuid's.
[root@rhel65 ~]# yum install uuid (output truncated) [root@rhel65 ~]# man uuid
You can use the uuid to make sure that a volume is universally uniquely identified in /etc/fstab. The device name can change depending on the disk devices that are present at boot time, but a uuid never changes.
First we use tune2fs to find the uuid.
[root@RHEL5 ~]# tune2fs -l /dev/sdc1 | grep UUID Filesystem UUID: 7626d73a-2bb6-4937-90ca-e451025d64e8
Then we check that it is properly added to /etc/fstab, the uuid replaces the variable devicename /dev/sdc1.
[root@RHEL5 ~]# grep UUID /etc/fstab UUID=7626d73a-2bb6-4937-90ca-e451025d64e8 /home/pro42 ext3 defaults 0 0
Now we can mount the volume using the mount point defined in /etc/fstab.
[root@RHEL5 ~]# mount /home/pro42 [root@RHEL5 ~]# df -h | grep 42 /dev/sdc1 397M 11M 366M 3% /home/pro42
The real test now, is to remove /dev/sdb from the system, reboot the machine and see what happens. After the reboot, the disk previously known as /dev/sdc is now /dev/sdb.
[root@RHEL5 ~]# tune2fs -l /dev/sdb1 | grep UUID Filesystem UUID: 7626d73a-2bb6-4937-90ca-e451025d64e8
And thanks to the uuid in /etc/fstab, the mountpoint is mounted on the same disk as before.
[root@RHEL5 ~]# df -h | grep sdb /dev/sdb1 397M 11M 366M 3% /home/pro42
Recent Linux distributions (Debian, Ubuntu, ...) use grub with a uuid to identify the root file system.
This example shows how a root=/dev/sda1 is replaced with a uuid.
title Ubuntu 9.10, kernel 2.6.31-19-generic uuid f001ba5d-9077-422a-9634-8d23d57e782a kernel /boot/vmlinuz-2.6.31-19-generic \ root=UUID=f001ba5d-9077-422a-9634-8d23d57e782a ro quiet splash initrd /boot/initrd.img-2.6.31-19-generic
The screenshot above contains only four lines. The line starting with root= is the continuation of the kernel line.
RHEL and CentOS boot from LVM after a default install.
1. Find the uuid of one of your ext3 partitions with tune2fs ( and vol_id if you are on RHEL5).
2. Use this uuid in /etc/fstab and test that it works with a simple mount.
3. (optional) Test it also by removing a disk (so the device name is changed). You can edit settings in vmware/Virtualbox to remove a hard disk.
4. Display the root= directive in /boot/grub/menu.lst. (We see later in the course how to maintain this file.)
5. (optional on ubuntu) Replace the /dev/xxx in /boot/grub/menu.lst with a uuid (use an extra stanza for this). Test that it works.
1. Find the uuid of one of your ext3 partitions with tune2fs ( and vol_id if you are on RHEL5).
root@rhel55:~# /lib/udev/vol_id -u /dev/hda1 60926898-2c78-49b4-a71d-c1d6310c87cc root@ubu1004:~# tune2fs -l /dev/sda2 | grep UUID Filesystem UUID: 3007b743-1dce-2d62-9a59-cf25f85191b7
2. Use this uuid in /etc/fstab and test that it works with a simple mount.
tail -1 /etc/fstab UUID=60926898-2c78-49b4-a71d-c1d6310c87cc /home/pro42 ext3 defaults 0 0
3. (optional) Test it also by removing a disk (so the device name is changed). You can edit settings in vmware/Virtualbox to remove a hard disk.
4. Display the root= directive in /boot/grub/menu.lst. (We see later in the course how to maintain this file.)
paul@deb503:~$ grep ^[^#] /boot/grub/menu.lst | grep root= kernel /boot/vmlinuz-2.6.26-2-686 root=/dev/hda1 ro selinux=1 quiet kernel /boot/vmlinuz-2.6.26-2-686 root=/dev/hda1 ro selinux=1 single
5. (optional on ubuntu) Replace the /dev/xxx in /boot/grub/menu.lst with a uuid (use an extra stanza for this). Test that it works.