UUID详解

UUID详解

第一次看到UUID这个东西,是在Ubuntu系统中看到/boot/grub/grub.cfg中对kernel的配置:

linux   /boot/vmlinuz-2.6.31-14-generic root=UUID=c74288db-c35e-4d7e-a1e8-82d6e8eff5cf

后来在分区表/etc/fstab中也有出现UUID

所以简单学习了一下。对UUID做如下总结。

 

获取设备的UUID的方法(Linux系统中):

1# blkid /dev/sda1

/dev/sda1: LABEL="/axs3" UUID="298d198d-aa60-48af-a9f4-638f8f274afa" SEC_TYPE="ext2" TYPE="ext3"
2) # tune2fs -l /dev/sda1 |grep 'UUID'
298d198d-aa60-48af-a9f4-638f8f274afa
3)# ls -l /dev/disk/by-uuid/ |grep sda1 |awk '{print $8}'
298d198d-aa60-48af-a9f4-638f8f274afa
4
#scsi_id -p 0x80/0x83 -s /block/sda1    应该只对SCSI设备有效。
5
# dumpe2fs /dev/sda1 |grep 'UUID'
dumpe2fs 1.39 (29-May-2006)
Filesystem UUID:       298d198d-aa60-48af-a9f4-638f8f274afa

这个命令不建议使用,要是分区比较大,耗时还是比较长的
6)# vol_id /dev/sda1 |grep 'UUID'
ID_FS_UUID=298d198d-aa60-48af-a9f4-638f8f274afa
ID_FS_UUID_ENC=298d198d-aa60-48af-a9f4-638f8f274afa

 

UUID是什么?

UUID(Universally Unique Identifier)全局唯一标识符,是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的。按照开放软件基金会(OSF)制定的标准计算,用到了以太网卡地址、纳秒级时间、芯片ID码和许多可能的数字。由以下几部分的组合:当前日期和时间(UUID的第一个部分与时间有关,如果你在生成一个UUID之后,过几秒又生成一个UUID,则第一个部分不同,其余相同),时钟序列,全局唯一的IEEE机器识别号(如果有网卡,从网卡获得,没有网卡以其他方式获得),UUID的唯一缺陷在于生成的结果串会比较长。

A universally unique identifier (UUID) is an identifier standard used in software construction, standardized by the Open Software Foundation (OSF) as part of the Distributed Computing Environment (DCE). The intent of UUIDs is to enable distributed systems to uniquely identify information without significant central coordination. In this context the word unique should be taken to mean "practically unique" rather than "guaranteed unique". Since the identifiers have a finite size it is possible for two differing items to share the same identifier. The identifier size and generation process need to be selected so as to make this sufficiently improbable in practice. Anyone can create a UUID and use it to identify something with reasonable confidence that the same identifier will never be unintentionally created by anyone to identify something else. Information labeled with UUIDs can therefore be later combined into a single database without needing to resolve name conflicts.

A UUID is 128 bits long, and can guarantee uniqueness across space and time.  UUIDs were originally used in the Apollo Network Computing System and later in the Open Software Foundation's (OSF) Distributed Computing Environment (DCE), and then in Microsoft Windows platforms.

 

上面说的到在grub中写到的UUID的的好处是什么呢?

这样做和使用/dev/sda5这种直接引用分区的方法的一个优点就是,当硬盘中增加了新的分区,或者分区的顺序改变后,仍然能够保证系统加载分区到正确的加载点。

这对于swap分区尤为重要,如果硬盘分区顺序改变,而fstabswap分区编号做响应的调整,是不是会把其他分区给作为swap哪?结果是很可怕的,这个分区上的数据恐怕就要不保了。通过在/dev/disk/uuid,这里的uuid列表实际上是一些soft link文件,系统可以保证针对每一个分区生成一个唯一的编码,增加了系统的稳定性。

 

 

参考资料:

http://www.ietf.org/rfc/rfc4122.txt       UUIDRFC文档

http://hi.baidu.com/ikwen/blog/item/6490902fada90f3f1e3089fc.html

http://javag.iteye.com/blog/127753   Java生成UUID

master

Stay hungry, stay foolish.

发表评论

邮箱地址不会被公开。 必填项已用*标注

*