硬盘分区的UUID

Universally Unique IDentifier, 是一种获取全局唯一命名的标准。

1 UUID的来历

要为一个对象进行命名,并要求这个名字在时间和空间上都是唯一的,这在计算机领域是一个很重要的问题。目前已经存在很多成熟的解决方案,例如IP地址,MAC地址,DNS域名等。但这些方案都存在一个问题,那就是需要一个中央管理机构来批准和统一管理。这样就会带来两个问题:(1)需要一定费用;(2)数量受限。

为了解决这个问题,UUID诞生了。它采用128位长度来表示一个名字,且同时考虑了时间和空间的唯一性,最重要的是它不需要申请注册,任何人都可以使用本地计算机运行程序自动生成。

UUID最早出现在Apollo Network Computing System,后来被用到了OSF的DCE环境,然后被微软拿去使用,并改名GUID。相信大家都记得微软注册表里的奇怪长串数字吧,还有COM组件的名字,都是GUID。

2 硬盘分区命名现状

2.1 卷标名存在的问题

大多数文件系统的元数据部分都会记录硬盘分区的名字。对于如何命名这个分区,也有很多方法,如采用卷标。

这里写图片描述

上面的“系统”,“软件”,“文档”就是分区的卷标名。几乎所有的文件系统类型都对卷标名进行支持。然而卷标名长度有限,并且重复的可能性比较大。可能很多人都给自己的系统分区命名为“系统”。

名字重复会导致一些问题,例如把当把一个硬盘HD1,转移到另外一台带有硬盘HD2的机器上时,如果HD1和HD2存在卷标名相同的分区,那么就会给依赖于卷标名的程序带来问题。

2.2 Linux对分区命名的问题

Linux系统对识别出的硬盘分区采用类似 /dev/sda1,/dev/sdb1这样的格式进行动态命名。假设机器装有两块串口硬盘,Linux会按照识别顺序对第一个识别出的硬盘命名为/dev/sda,对第二块识别出的硬盘命名为/dev/sdb。而问题是识别顺序是随机的,所以启动机器之前不能确定/dev/sda到底是哪块硬盘。

最常见的使用这种名称的地方就是/etc/fstab文件,它被用来设置自动挂载硬盘分区。下面是一个真实系统中的fstab文件中的一行:

/dev/sda1               /store                  ext4    defaults        0 0

如果系统有多块硬盘,那么下次启动的时候,/store就不能确定到底挂载了哪个硬盘的第一分区,如果这个挂载点对系统运行非常重要,那么就有可能出现问题。

2.3 GRUB对分区命名的问题

GRUB对分区命名与Linux类似,hd0表示发现的第一块硬盘,hd1表示第二块。存在的问题也与Linux相同。

2.4 UUID在文件系统中的使用

为解决上述问题,UUID被文件系统设计者采用,使其可以持久唯一标识一个硬盘分区。其实方式很简单,就是在文件系统的超级块中使用128位存放UUID。这个UUID是在使用文件系统格式化分区时计算生成的,例如Linux下的文件系统工具mkfs就在格式化分区的同时,生成UUID并把它记录到超级块的固定区域中。

下面是ext2文件系统超级块结构:

struct ext2_super_block
 { __u32   s_inodes_count;    /* 文件系统中索引节点总数 */
   __u32   s_blocks_count;    /*文件系统中总块数 */
   __u32   s_r_blocks_count;           /* 为超级用户保留的块数 */
   __u32   s_free_blocks_count;   /*文件系统中空闲块总数 */
   __u32   s_free_inodes_count;   /*文件系统中空闲索引节点总数*/
   __u32   s_first_data_block;              /* 文件系统中第一个数据块 */
   __u32   s_log_block_size;              /* 用于计算逻辑块大小 */
   __s32   s_log_frag_size;              /* 用于计算片大小 */
   __u32   s_blocks_per_group; /* 每组中块数 */
   __u32   s_frags_per_group;              /* 每组中片数 */
   __u32   s_inodes_per_group; /* 每组中索引节点数 */
   __u32   s_mtime;                      /*最后一次安装操作的时间 */
   __u32   s_wtime;             /*最后一次对该超级块进行写操作的时间 */
   __u16   s_mnt_count;       /* 安装计数 */
   __s16   s_max_mnt_count;                 /* 最大可安装计数 */
   __u16   s_magic;                    /* 用于确定文件系统版本的标志 */
   __u16   s_state;                      /* 文件系统的状态*/
   __u16   s_errors;                     /* 当检测到有错误时如何处理 */
   __u16   s_minor_rev_level;  /* 次版本号 */
   __u32   s_lastcheck;       /* 最后一次检测文件系统状态的时间 */
   __u32   s_checkinterval; /* 两次对文件系统状态进行检测的间隔时间 */
   __u32   s_rev_level;       /* 版本号 */
   __u16   s_def_resuid;      /* 保留块的默认用户标识号 */
   __u16   s_def_resgid;      /* 保留块的默认用户组标识号*/ 

 /*
  * These fields are for EXT2_DYNAMIC_REV superblocks only.
  *
  * Note: the difference between the compatible feature set and
  * the incompatible feature set is that if there is a bit set
  * in the incompatible feature set that the kernel doesn't
  * know about, it should refuse to mount the filesystem.
  *
  * e2fsck's requirements are more strict; if it doesn't know
  * about a feature in either the compatible or incompatible
  * feature set, it must abort and not try to meddle with
  * things it doesn't understand...
  */
__u32   s_first_ino;            /* 第一个非保留的索引节点 */
__u16   s_inode_size;           /* 索引节点的大小 */
  __u16   s_block_group_nr;       /* 该超级块的块组号 */
  __u32   s_feature_compat;       /* 兼容特点的位图*/
  __u32   s_feature_incompat;     /* 非兼容特点的位图 */
  __u32   s_feature_ro_compat;    /* 只读兼容特点的位图*/
  __u8    s_uuid[16];             /* 128位的文件系统标识号*/
  char    s_volume_name[16];      /* 卷名 */
  char    s_last_mounted[64];     /* 最后一个安装点的路径名 */
  __u32   s_algorithm_usage_bitmap; /* 用于压缩*/
   /*
   * Performance hints.  Directory preallocation should only
   * happen if the EXT2_COMPAT_PREALLOC flag is on.
   */
  __u8    s_prealloc_blocks;      /* 预分配的块数*/
  __u8    s_prealloc_dir_blocks;  /* 给目录预分配的块数 */
  __u16   s_padding1;         
  __u32   s_reserved[204];        /* 用null填充块的末尾 */
 };

可以看到s_uuid[16]就是存放分区UUID的地方。

这样,无论硬盘分区的标识就永远不会重复,而且只要分区没有被重新格式化,那么标识此分区的UUID永远不变。

当然并不是所有的文件系统类型都支持UUID,例如微软的NTFS就不支持,而是采用了一个类似的其他机制。微软永远不走正路,真拿他没办法。

3 GRUB, Linux对硬盘分区UUID的支持

3.1 实例

目前最新版本的GRUB和Linux系统都对硬盘分区的UUID机制提供了良好的支持。
下面是CentOS6系统中/boot/grub/grub.conf配置文件的一部分:

title CentOS (2.6.32-504.el6.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=ec2c1241-2c17-46ea-8cc6-a6a850df3e94 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
        initrd /boot/initramfs-2.6.32-504.el6.x86_64.img

可以看出,GRUB本身仍采用(hd0,0)的传统方式寻找分区,而为其启动的linux提供了UUID的方式。

下面是CentOS7系统中/boot/grub2/grub.cfg配置文件一部分:

menuentry 'CentOS Linux, with Linux 3.10.0-123.el7.x86_64' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-123.el7.x86_64-advanced-b1e99de2-d388-4882-9b3a-5ced68992ee0' {
    load_video
    set gfxpayload=keep
    insmod gzio
    insmod part_msdos
    insmod xfs
    set root='hd0,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  49224d20-43a6-44f2-8cf5-cfa11758a3a7
    else
      search --no-floppy --fs-uuid --set=root 49224d20-43a6-44f2-8cf5-cfa11758a3a7
    fi
    linux16 /vmlinuz-3.10.0-123.el7.x86_64 root=UUID=b1e99de2-d388-4882-9b3a-5ced68992ee0 ro rd.lvm.lv=centos/swap vconsole.font=latarcyrheb-sun16 rd.lvm.lv=centos/root crashkernel=auto  vconsole.keymap=us rhgb quiet LANG=en_US.UTF-8
    initrd16 /initramfs-3.10.0-123.el7.x86_64.img

}

可见,GRUB和LINUX均采用了UUID来寻找硬盘分区。

下面是fstab的一部分:
UUID=49224d20-43a6-44f2-8cf5-cfa11758a3a7 /boot xfs defaults 1 2

显然也是采用了UUID来定位硬盘分区。

3.2 注意事项

  • 重新格式化分区时,分区的UUID会变更
    所以格式化分区后,需要修改对应的配置文件,更新其UUID。

  • NTFS文件系统不支持UUID
    虽然NTFS不支持UUID,但是其支持一种较短的ID,也可以拿来凑合用。

既然UUID有这么多优势,毫无疑问只要系统支持,就要充分使用它。

4 UUID工具程序

  • 如何查看硬盘分区的UUID

分区的UUID是mkfs工具自动写入的,我们可以使用blkid来查看之。

[root@db001 ~]# blkid
/dev/sda1: UUID="33141ba9-acd3-4021-9de3-bf7460f7c77c" TYPE="ext3"
/dev/sdc1: UUID="ec2c1241-2c17-46ea-8cc6-a6a850df3e94" TYPE="ext4"
/dev/sdc2: UUID="a1dc0e52-777e-450a-8fac-62d7966ff619" TYPE="swap"
  • 生成UUID和分析UUID

为方便大家学习和理解UUID,uuid这个工具提供了很好的实践。它不仅可以用来生成UUID,而且可以对已有的UUID进行分析。

[root@db001 ~]# uuid
3f3418ce-0e79-11e5-b477-00e081de9b4a
[root@db001 ~]# blkid
/dev/sda1: UUID="33141ba9-acd3-4021-9de3-bf7460f7c77c" TYPE="ext3"
/dev/sdc1: UUID="ec2c1241-2c17-46ea-8cc6-a6a850df3e94" TYPE="ext4"
/dev/sdc2: UUID="a1dc0e52-777e-450a-8fac-62d7966ff619" TYPE="swap"
[root@db001 ~]# uuid -d 33141ba9-acd3-4021-9de3-bf7460f7c77c
encode: STR:     33141ba9-acd3-4021-9de3-bf7460f7c77c
        SIV:     67895034790306977465223914142060496764
decode: variant: DCE 1.1, ISO/IEC 11578:1996
        version: 4 (random data based)
        content: 33:14:1B:A9:AC:D3:00:21:1D:E3:BF:74:60:F7:C7:7C
                 (no semantics: random data only)

附录 UUID指导文档 RFC4122


                                                                        [Docs] [txt|pdf] [draft-mealling-uu...] [Diff1] [Diff2] [Errata]        

                                                       PROPOSED STANDARD
                                                            Errata Exist
Network Working Group                                           P. Leach
Request for Comments: 4122                                     Microsoft
Category: Standards Track                                    M. Mealling
                                                Refactored Networks, LLC
                                                                 R. Salz
                                              DataPower Technology, Inc.
                                                               July 2005


          A Universally Unique IDentifier (UUID) URN Namespace

Status of This Memo

   This document specifies an Internet standards track protocol for the
   Internet community, and requests discussion and suggestions for
   improvements.  Please refer to the current edition of the "Internet
   Official Protocol Standards" (STD 1) for the standardization state
   and status of this protocol.  Distribution of this memo is unlimited.

Copyright Notice

   Copyright (C) The Internet Society (2005).

Abstract

   This specification defines a Uniform Resource Name namespace for
   UUIDs (Universally Unique IDentifier), also known as GUIDs (Globally
   Unique IDentifier).  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.

   This specification is derived from the DCE specification with the
   kind permission of the OSF (now known as The Open Group).
   Information from earlier versions of the DCE specification have been
   incorporated into this document.














Leach, et al.               Standards Track                     [Page 1]

RFC 4122                  A UUID URN Namespace                 July 2005


Table of Contents

   1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . .  2
   2. Motivation . . . . . . . . . . . . . . . . . . . . . . . . . .  3
   3. Namespace Registration Template  . . . . . . . . . . . . . . .  3
   4. Specification  . . . . . . . . . . . . . . . . . . . . . . . .  5
      4.1. Format. . . . . . . . . . . . . . . . . . . . . . . . . .  5
           4.1.1. Variant. . . . . . . . . . . . . . . . . . . . . .  6
           4.1.2. Layout and Byte Order. . . . . . . . . . . . . . .  6
           4.1.3. Version. . . . . . . . . . . . . . . . . . . . . .  7
           4.1.4. Timestamp. . . . . . . . . . . . . . . . . . . . .  8
           4.1.5. Clock Sequence . . . . . . . . . . . . . . . . . .  8
           4.1.6. Node . . . . . . . . . . . . . . . . . . . . . . .  9
           4.1.7. Nil UUID . . . . . . . . . . . . . . . . . . . . .  9
      4.2. Algorithms for Creating a Time-Based UUID . . . . . . . .  9
           4.2.1. Basic Algorithm. . . . . . . . . . . . . . . . . . 10
           4.2.2. Generation Details . . . . . . . . . . . . . . . . 12
      4.3. Algorithm for Creating a Name-Based UUID. . . . . . . . . 13
      4.4. Algorithms for Creating a UUID from Truly Random or
           Pseudo-Random Numbers . . . . . . . . . . . . . . . . . . 14
      4.5. Node IDs that Do Not Identify the Host. . . . . . . . . . 15
   5. Community Considerations . . . . . . . . . . . . . . . . . . . 15
   6. Security Considerations  . . . . . . . . . . . . . . . . . . . 16
   7. Acknowledgments  . . . . . . . . . . . . . . . . . . . . . . . 16
   8. Normative References . . . . . . . . . . . . . . . . . . . . . 16
   A. Appendix A - Sample Implementation . . . . . . . . . . . . . . 18
   B. Appendix B - Sample Output of utest  . . . . . . . . . . . . . 29
   C. Appendix C - Some Name Space IDs . . . . . . . . . . . . . . . 30

1.  Introduction

   This specification defines a Uniform Resource Name namespace for
   UUIDs (Universally Unique IDentifier), also known as GUIDs (Globally
   Unique IDentifier).  A UUID is 128 bits long, and requires no central
   registration process.

   The information here is meant to be a concise guide for those wishing
   to implement services using UUIDs as URNs.  Nothing in this document
   should be construed to override the DCE standards that defined UUIDs.

   There is an ITU-T Recommendation and ISO/IEC Standard [3] that are
   derived from earlier versions of this document.  Both sets of
   specifications have been aligned, and are fully technically
   compatible.  In addition, a global registration function is being
   provided by the Telecommunications Standardisation Bureau of ITU-T;
   for details see <http://www.itu.int/ITU-T/asn1/uuid.html>.





Leach, et al.               Standards Track                     [Page 2]

RFC 4122                  A UUID URN Namespace                 July 2005


2.  Motivation

   One of the main reasons for using UUIDs is that no centralized
   authority is required to administer them (although one format uses
   IEEE 802 node identifiers, others do not).  As a result, generation
   on demand can be completely automated, and used for a variety of
   purposes.  The UUID generation algorithm described here supports very
   high allocation rates of up to 10 million per second per machine if
   necessary, so that they could even be used as transaction IDs.

   UUIDs are of a fixed size (128 bits) which is reasonably small
   compared to other alternatives.  This lends itself well to sorting,
   ordering, and hashing of all sorts, storing in databases, simple
   allocation, and ease of programming in general.

   Since UUIDs are unique and persistent, they make excellent Uniform
   Resource Names.  The unique ability to generate a new UUID without a
   registration process allows for UUIDs to be one of the URNs with the
   lowest minting cost.

3.  Namespace Registration Template

   Namespace ID:  UUID
   Registration Information:
      Registration date: 2003-10-01

   Declared registrant of the namespace:
      JTC 1/SC6 (ASN.1 Rapporteur 
  • 3
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一键GHOST v2013.01.23 硬盘版/光盘版/优盘版 v2013.01.23 正式版 支持Windows8正式版 替换GHOST8.3为11.5.1(主力内核仍为11.0.2) 更新DISKGEN为4.2版(无损调整分区功能超越PQ) 增加HDDREG硬盘再生器(无损修复坏道工具) 更改启用UMBPCI驱动为默认,以节省出更多常规内存 更换SHSURDRV为默认,以解决XMSDSK出错问题 允许加载USB2.0驱动,以提高其速度(设置->驱动) 设置默认禁用清除autorun.inf,以避免意外重启 设置默认禁用诊断报告回写,以避免C盘磁盘错误 优化卸载程序,提高卸载速度,无需重启即可完全卸载 修正"热键模式"无法使用和卸载不干净的BUG 增强对光盘及其中的GHO映像的识别率 增强对USB磁盘及其中的GHO映像的识别率 增加"修复"功能对BCD菜单的自动修复 允许"修复"功能开机无条件自动修复磁盘错误 修正少数环境下一键备份提示"-1天"的BUG 屏蔽诊断报告中的UUID等BIOS个人信息 添加主程序超大图标,解决高分辨率环境有锯齿问题 优盘版安装程序可识别"引导设置"已成功的移动硬盘 修正了其它一些BUG 安装环境:WINXP/2000/2003/WIN7/VISTA/2008/WIN8 (32位、64位) 运行环境:WINDOWS/DOS 软件类别:系统备份 授权形式:免费 官方网站:http://doshome.com 软件作者:葛明阳(gmy) 软件简介: 一键GHOST是"DOS之家"首创的4种版本(硬盘版/光盘版/优盘版/软盘版)同步发布的启动盘, 适应各种用户需要,既可独立使用,又能相互配合.主要功能包括:一键备份系统,一键恢复系统, 中文向导,GHOST,DOS工具箱. 一键GHOST,高智能的GHOST,只需按一个键,就能实现全自动无人值守操作,让你一爽到底! 主要特点: 1,GHOST内核11.2/11.5及硬盘接口IDE/SATA任意切换,分区格式FAT/NTFS自动识别. 2,硬盘版特别适于无软驱/无光驱/无USB接口/无人值守的台式机/笔记本/服务器使用. 3,支持WIN7/WIN8等新系统,以及GRUB4DOS菜单的DOS/Windows全系列多系统引导. 4,支持压缩/分及GHOST辅助性参数自定义,以满足光盘刻录和其它需要. 5,安装快速,只需1-2分钟;卸载彻底,不留垃圾文件,安全绿色无公害. 6,不破坏系统原有结构,不向BIOS和硬盘保留扇区写入任何数据,无需划分隐藏分区. 7,WINDOWS下(鼠标)/开机菜单(方向键)/开机热键(K键)多种启动方案任由你选择. 8,安装程序即便被误删除,也可使用同一版本的光盘版/优盘版进行恢复. 9,一键备份系统的映像FAT下深度隐藏,NTFS下能有效防止误删除或病毒恶意删除. 10,GHOST运行之前自动删除auto类病毒引导文件,避免返回WIN后被病毒二次感染. 11,界面友好,全中文操作,无需英语和计算机专业知识. 12,危险操作之前贴心提示,明明白白放心使用. 13,附带GHOST浏览器,能打开GHO映像,任意添加/删除/提取其中的文件. 14,映像导入/导出/移动等功能,便于GHO映像传播交流和多次备份. 15,密码设置功能,让多人共用一台电脑情况下,不被非法用户侵入. 16,多种引导模式,以兼容各种型号电脑,让特殊机型也能正常启动本软件. 17,诊断报告功能可自动收集系统信息,为作者对软件的日后改进提供线索. 18,帮助文档,图文并茂,易学易会,网上论坛,在线答疑. 更详细的说明请阅读 HELP.CHM DOS之家 http://doshome.com 官方站: http://doshome.com/yj 论坛站: http://doshome.net/bbs/index.asp?boardid=4

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值