.. title: Finding the UUID for Linux Drives
.. slug: uuid_drives
.. date: 2010/06/22 22:26
.. tags: linux, drives, devices
.. link: 
.. description: Some notes on how to get the UUID info for devices on a linux system.
.. type: text

**UPDATE:** I use the term "Drives" here for two reasons.  One, people coming from Windows understand a harddisk drive (generally C: or another "device" letter).  Two, this is specific to harddrives and not other devices in Linux (like the terminal, printer or scanner).

The Universally Unique Identifier (UUID) is a good way to mount drives under Linux with SATA drives (or any drives, PATA or IDE).  This ensures that when you have more than one harddrive, it always gets mounted to the same location specified in ``/etc/fstab``.  The reason is that SATA drives are mounted when they're found and on one reboot can come up as ``/dev/sda`` and the next time as ``/dev/sdb``.

So in order to set up your file system table correctly, you should specify the UUID instead of the physcial device.  So your ``/etc/fstab`` will look like this:

.. code-block:

 # /dev/sda3
 UUID=d0082790-10b3-466a-8408-a109a6d1a010 /               ext3     relatime,errors=remount-ro 0       1
 # /dev/sda1
 UUID=213d26d6-3fe8-4443-a50d-9d1fea138ac5 /boot           ext3    relatime        0       2
 # /dev/sda6
 UUID=485554c3-e681-4254-9344-6f038c826fb8 /home           ext3    relatime        0       2
 # /dev/sda5
 UUID=f95f1c10-8496-481c-a84b-e8f8a4ec9061 /var            ext3    relatime        0       2
 # /dev/sda2
 UUID=82b38f49-9f85-4d32-887b-24357b0661c8 none            swap    sw              0       0
 /dev/scd0       /media/cdrom0   udf,iso9660 user,noauto,exec,utf8 0       0
 /dev/sdb1       /media/sdb1                               ext3    relatime        0       0

Ok, so if you want to use the UUID, how can you find it?  We're assuming the drive is already mounted, of course!

One way is to use

.. code-block:: bash

 $ ls -l /dev/disk/by-uuid
 lrwxrwxrwx 1 root root 10 11. Okt 18:02 485554c3-e681-4254-9344-6f038c826fb8 -> ../../sda2

This will list all the devices by UUID and tell you where they're currently mounted.  Another would be to use the blkid command.

.. code-block:: bash

 # blkid /dev/sda1
 /dev/sda1: LABEL="/" UUID="485554c3-e681-4254-9344-6f038c826fb8" SEC_TYPE="ext2" TYPE="ext3"

One problem with this is that the ``blkid`` command can only list one device at a time.  A secondary problem is that the command ``blkid`` has to be run as the root user.

Additional information can be found by googling Linux and UUID.
