udev - UUID


 

Is there a way to identify univocally a partition?  udev can refer to a partition (doesn't matter the device name) using the UUID. What' UUID, how to discover it and how to use it?

Before reading this post should be useful to read this one: udev - hal - dbus: how does linux recognize devices?

UUID stands for Universally Unique Identifier  and is a number. Every partition in a disk has a UUID. UUID can be used in /etc/fstab to identify a partition without refering to a partition device such as /dev/sda1 and in /boot/grub/menu.lst to se the root partition.

Why we should need UUID? To be more safe. It happened to me in the past to have troubles with device names. Adding or removing devices from a computer can change the device naming at boot: in this case the kernel can't be loaded. Even worst buggy bioses sometimes randomly change the device order at boot and in this case grub can't be loaded.

Let's see how to use it.

We can retrieve the UUID of a partition using the vol_id utility. vol_id is part of the udev package. If you don't have vol_id in your PATH also if u have the udev package installed probably you can find it in /lib/udev/vol_id.

vol_id /dev/sda1 

result:

ID_FS_USAGE=filesystem
ID_FS_TYPE=ext3
ID_FS_VERSION=1.0
ID_FS_UUID=e4e59c89-8714-4f75-b2b7-dba4cd4aad12 ID_FS_UUID_ENC=e4e59c89-8714-4f75-b2b7-dba4cd4aad12
ID_FS_LABEL=
ID_FS_LABEL_ENC=
ID_FS_LABEL_SAFE=

So the UUID of sda1 is e4e59c89-8714-4f75-b2b7-dba4cd4aad12

FSTAB

We can use it in fstab to refer to the device in place of /dev/sda1:

vim /etc/fstab 

We can comment this line
#dev/sda1 / ext3 defaults,errors=remount-ro 0 1
and rewrite it in this way
UUID=e4e59c89-8714-4f75-b2b7-dba4cd4aad12 / ext3 defaults,errors=remount-ro 0 1


GRUB

vim /boot/grub/menu.lst

We comment this line (Note: double "#")
## kopt=root=/dev/sda1 ro
and add this line (Note: single "#")
# kopt=root=UUID=e4e59c89-8714-4f75-b2b7-dba4cd4aad12 ro

In this way we are sure that this modification will be permanent also upgrading the kernel or initramfs. Then we run

sudo update-grub

to update all grub entries with the new UUID parameter.

Now we are ready to reboot.

References: http://developer.osdl.org/dev/DCL/PSDN/Testing_udev_notes.html

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
4 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.