|
Softpanorama |
||||||
| Contents | Bulletin | Latest | Last year | Top visited | Scriptorama | |
| News | Reference | Man Pages | ||||
| Logical Volume Manager (LVM) | udev | Software RAID | Partition labels | Linux Disk Partitioning | Humor | Etc |
UUID is a Universally Unique IDentifier. It's a identification code given to each storage device you have on your system, aimed to help you uniquely identify each device no matter what.
UUIDs can be used to identify DVD drives, removable media (USB flashsticks) and each partition on any of your hard drives. UUID is a pretty long hexadecimal string, for example:
c73a37c8-ef7f-40e4-b9de-8b2f81038441
UUID is the only way to guarantee you recognize the same drive or partition no matter what. For example, if you introduce to your system another hard drive, this might upset quite a few things, starting with the way your system boots up (or stops booting up upon the new drive introduction). Using UUID helps remedy most of such things.
Automatically assigned device names in your system are not consistent, they are according to the order of loading the kernel modules up during (most usually) the startup time, and thus the names will look different if you boot with one of your USB flashsticks attached and then reboot after you plug it out.
UUIDs really useful for mounting removable media : you can use UUID to always mount the same card at the same location.
GRUB relies on UUIDs as well. If you look into /boot/grub/menu.lst file, you'll find something similar to this:
kernel /boot/vmlinuz-2.6.24-16-generic root=UUID=c73a37c8-ef7f-40e4-b9de-8b2f81038441
ro quiet splash
To list UUID on your system you can use command blkid
If you know a device name and just want to confirm the UUID for it to later use it in /etc/fstab, here's how you can do it using vol_id command:# vol_id -u /dev/sdb1 c73a37c8-ef7f-40e4-b9de-8b2f81038441
See also UsingUUID - Community Ubuntu Documentation
Suse 10 SP3 uses UUID exclusivly for all partitions and converts exiting /dev/sda2 type references automatically to UUID scheme.
You can mount patition using it UUID by using the -U switch:
mount -U 0ef96300-36c0-4575-8a1d-2d36ff4cd585 /mnt/disk1
To assign a UUID to a disk, use tunefs. You can generate your own UUID with the command uuidgen. Then type:
tune2fs -U uuid /dev/sda2
|
|
|
|||
|
|
||||
| Bulletin | Latest | Past week | Past month | |
Where's the difference between mounting partitions by-ID and by-UUID?
Since version 10 of SLES/SLED and since 10.3 of OpenSUSE (IIRC), fstab and grub's menu.lst no longer contain device-names but device IDs (as pointed out in New default in SLES/SLED 10 SP1: mount "by Device ID").
This by-ID-way leads to persistent device names but also prevents booting a cloned system (e.g. a dd'ed system) out-of-the-box. Using by-UUID would solve this problem, but none of the docs I found about imaging+by-ID recommend this way. Almost all recommend using the old-fashioned /dev/sdX. Why not using UUID? Has anybody a clue?nibuild wrote:
> Where's the difference between mounting partitions by-ID and by-UUID?
>
> Since version 10 of SLES/SLED and since 10.3 of OpenSUSE (IIRC), fstab
> and grub's menu.lst no longer contain device-names but device IDs (as
> pointed out in 'New default in SLES/SLED 10 SP1: mount \"by Device ID\"'
> (http://tinyurl.com/5dmgf7)).
>
> This by-ID-way leads to persistent device names but also prevents
> booting a cloned system (e.g. a dd'ed system) out-of-the-box. Using
> by-UUID would solve this problem, but none of the docs I found about
> imaging+by-ID recommend this way. Almost all recommend using the
> old-fashioned /dev/sdX. Why not using UUID? Has anybody a clue?
>
>
In theory I suppose a uuid that is saved could be chunked forcing
the creation of a new uuid.
As you mentioned, by-id usually involves something more intrinsic
inside the drive itself (thus preventing "cloning").
My abstraction of choice where possible is using LVM.
On Linux Today's post is about something I think is pretty cool on Linux (since about kernel 2.1.x, when /proc/partitions was introduced, or made standard). It has to do with disk mounting (both on the command line or through the fstab) by UUID (Universal Unique Identifier). UUID notation, when used as a means to access disk, is just one more way that Linux has moved ahead of the pack to (depending on your way of thinking ;) either make disk management more accessible or make the fstab and disk identification even more confusing ;) NOTE: Skip the next paragraph if you don't care about Open Solaris' slight support for this functionality, to date. Skip to the numbered list if you just want to check out the commands and have had your fair share of my opinion ;)
For those of you who got here by catching the Solaris and Unix tags on this post, I want to address your concerns immediately, since you may no longer be concerned with this text after the next few sentences ;) Although Solaris does "understand" UUID addressing, the level on which Solaris addresses the issue (with regards to disk management) isn't user-friendly enough to fit in the scope of this post. Basically, and this is putting it very generically, the getting and setting of object UUID's on Solaris is still only resident at the code-base layer. I'm glad to see that Sun is addressing the issue with C functions like wsreg_set_id() and wsreg_get_id(), but, since the functionality provided by this layer of access hasn't been implemented in any relevant user tools, we won't be looking at Solaris' implementation of it for the remainder of this dialogue. Ok, I'll give Solaris 10 points for having expanded greatly upon the previous version's acceptance of the standard by implementing a lot of new C routines, a "makeuuid" binary and support for UUID's of zones, but, again, since we're going to be looking at mounting disk using the UUID (without re-writing the OS), Solaris (Open and Regular) is out for now (8/20/2008 just in case the future makes me incorrect, which it has a nasty habit of doing ;)
While Linux boasts most of the same C routines and headers as Solaris (which it must, of course, since the OS supports UUID identification), they're named slightly differently and - the biggest plus - Linux (RedHat and Ubuntu, at least) come with plenty of programs to work with disk UUID's and plenty of hooks to allow other programs to make use of the disk UUID's as well!
The most basic program (that Solaris has picked up on) is called "uuidgen." This program will generate a UUID for you based on the output from a decent randomness-generator (like /dev/random) or resort to time-and-MAC-based randomization ( Generally, the only random factor used is time, unless you have the privilege to view your ethernet adapter's MAC address). The program can be forced to use one or the other, if you have a specific preference (with the "-r" and "-t" flags, respectively). This seemingly extraneous program does have one very important area of application, which we'll look at below.
Where you really see the benefit with Linux is in how they've worked it into their basic hard disk management facilities. They've made it very simple for you to keep track of your disks by UUID using any number of methods. I'll be listing several different means to some "ends" you may want to achieve, as every command may not be available in your Linux distro, but at least one probably is.
One, often unmentioned (but highly valuable), benefit of using UUID's to deal with your disks is that you don't have to worry about system naming conventions and the hassles inherent with using them. For instance, if you have a disk with a specific UUID and a block device name of /dev/sda3, if you do all your work (and system/application customization) with that disk, as the name /dev/sda3, you might be in for a big headache if you have a system problem (or just install some new hardware and reconfigure) and Linux decides to rename /dev/sda3 as /dev/sdb3 (or "anything" else). If you're using UUID's, you can simply use the "tune2fs" command (shown below) to assign the original UUID back to the new logical device name, so /dev/sdb3 would function exactly as if it were /dev/sda3, without causing any issues with your Linux OS :):
1. If you don't know the UUID of your disk, you can find it by using one of the several commands below:
host # vol_id /dev/sda3
...
ID_FS_UUID=a1331d73-d640-4bac-97b4-cf33a375ae5b
...
or:
host # blkid /dev/sda3 <-- Leave blank to show all disks
/dev/sda3: LABEL="/" UUID="a1331d73-d640-4bac-97b4-cf33a375ae5b" SEC_TYPE="ext3" TYPE="ext2"
also:
host # ls -l /dev/disk/by-uuid|grep sda3
lrwxrwxrwx 1 root root 10 11. Okt 18:02 a1331d73-d640-4bac-97b4-cf33a375ae5b-> ../../sda3
2. If you prefer to generate your own UUID's (see above), you can use the uuidgen command and couple it with tune2fs to change the default UUID assigned to your disk by the system, like this:
host # uuidgen
1d721189-7b71-4315-95a7-1c3abc90d379
host # tune2fs -U 1d721189-7b71-4315-95a7-1c3abc90d379 /dev/sda3
3. Then again, if you already know the UUID, you might want to find out what disk it's associated with. You can generally get this information with the "findfs" command, like so:
host # findfs UUID=a1331d73-d640-4bac-97b4-cf33a375ae5b
/dev/sda3
Of course, using some of the commands above and grepping out part of the UUID will also get you your answer, like:
host # ls -l /dev/disk/by-uuid|grep a1331d73-d640-4bac-97b4-cf33a375ae5b
lrwxrwxrwx 1 root root 10 11. Okt 18:02 a1331d73-d640-4bac-97b4-cf33a375ae5b-> ../../sda3
or
host # blkid|grep a1331d73-d640-4bac-97b4-cf33a375ae5b <-- remember that blkid with no arguments returns all of the system disk
/dev/sda3: LABEL="/" UUID="a1331d73-d640-4bac-97b4-cf33a375ae5b" SEC_TYPE="ext3" TYPE="ext2"
4. And, lastly (for this post, at least ;), you can mount your disks using the UUID, and even incorporate that automated UUID mounting into your /etc/fstab. To mount directly from the command line, you can do something like this:
host # mount -U a1331d73-d640-4bac-97b4-cf33a375ae5b /directory/you/mount/this/disk/on
and you could instruct your system to mount this partition by UUID from within the fstab, as well. It works basically the same way that the LABEL keyword does:host # cat /etc/fstabAnd, at this point, you should be able to figure your way around using UUID's to manipulate your disk on Linux with no problem. Enjoy, and please "be careful" :)
...
UUID=a1331d73-d640-4bac-97b4-cf33a375ae5b /directory/you/mount/this/disk/on ext3fs defaults 1 1