UUID
A uuid
uuid or universally unique identifier
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
.
vol_id (legacy)
================
Older versions of Linux have a vol_id
vol_id(1) 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/7 or Debian6/⅞.
lsblk -f
You can quickly locate the uuid
of file systems with lsblk -f
. This
is a screenshot from a Macbook Pro Retina with Debian 8.
root@debian8:~# lsblk -f
lsblk: sdb2: unknown device name
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 vfat EFI 67E3-17ED /boot/efi
├─sda2 hfsplus Macintosh HD de87321a-95e3-3b5b-9bc4-855c173d8337
├─sda3 hfsplus Recovery HD 3ddc4f86-4e26-308e-a52c-0216318ab73e
├─sda4 hfsplus Recovery HD 672f06bd-5e13-3f62-995b-c5e3dc5ee19e
└─sda5 ext4 5361cc68-746e-4800-8e6c-108d0054b6f0 /
sdb
└─sdb1
root@debian8:~#
The same command will also work on recent RHEL and CentOS servers.
[root@centos7 ~]# lsblk -f /dev/sdf
NAME FSTYPE LABEL UUID MOUNTPOINT
sdf
├─sdf1 xfs 0697ab0c-5c99-4c80-880f-10bb0f9aa948 /boot
└─sdf2 LVM2_mem ZWr0TY-W0qX-Uwva-qMT1-Nkhp-RsXU-HDUIil
├─c...-swap swap 14c9d978-f547-4e18-91e2-a2ab140fe82c [SWAP]
└─c...-root xfs fd931dbd-cdea-41e8-9943-1d9668d39857 /
[root@centos7 ~]#
tune2fs
Use tune2fs
tune2fs(1) 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
uuid
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
uuid in /etc/fstab
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
/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
/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
uuid as a boot device
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. practice: uuid and filesystems ==============================
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.
solution: uuid and filesystems
==============================
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.