Linux 获取卷或文件系统唯一标识(UUID)的四种通用方法

【UUID】
  UUID stands for Universally Unique Identifier which helps Linux system to identify a hard drives partition instead of block device file. It’s a 128 bit number used to identify information in computer systems.


【通用命令】
  假设需要查询的设备名称为:/dev/sda2

  1. blkid – 输出块设备的属性信息
    # blkid
	/dev/sda4: LABEL="/" UUID="b6259d20-c9f1-4fb2-993c-67531525f57f" TYPE="ext3" SEC_TYPE="ext2"
	/dev/sda3: TYPE="swap" LABEL="SWAP-sda3"
	/dev/sda1: LABEL="/boot" UUID="aae1d246-a597-4b7f-ac61-f2565ebf7f91" SEC_TYPE="ext2" TYPE="ext3"
	/dev/sda2: LABEL="/tmp" UUID="42f53841-31e7-4e6e-8280-04914dfdea34" TYPE="ext2"
	/dev/sdb2: UUID="ff0e0c3d-5c1d-42aa-b03b-ddc4bd39dac6" TYPE="ext3" SEC_TYPE="ext2"
	/dev/vol_group/lvm_ext3_01: UUID="935482ac-7907-44b9-8c76-b9082f23d47d" SEC_TYPE="ext2" TYPE="ext3"
  1. by-uuid – 输出指向可用卷的链接,软链接名称为对应的UUID
	#ls -l  /dev/disk/by-uuid
	lrwxrwxrwx 1 root root 10 Jul  2 08:32 42f53841-31e7-4e6e-8280-04914dfdea34 -> ../../sda2
	lrwxrwxrwx 1 root root 10 Jul  2 08:32 aae1d246-a597-4b7f-ac61-f2565ebf7f91 -> ../../sda1
	lrwxrwxrwx 1 root root 10 Jul  2 08:32 b6259d20-c9f1-4fb2-993c-67531525f57f -> ../../sda4
	lrwxrwxrwx 1 root root 10 Jul  2 08:32 ff0e0c3d-5c1d-42aa-b03b-ddc4bd39dac6 -> ../../sdb2
  1. tune2fs – 目前仅仅适用于 ext2/ext3/ext4文件系统
	# tune2fs -l /dev/sda2 | grep UUID
	Filesystem UUID:          42f53841-31e7-4e6e-8280-04914dfdea34
  1. dumpe2fs – 目前仅仅适用于 ext2/ext3/ext4文件系统
	# dumpe2fs /dev/sda2 | grep UUID
	dumpe2fs 1.41.9 (22-Aug-2009)
	Filesystem UUID:          42f53841-31e7-4e6e-8280-04914dfdea34

【备注】
  上述命令获取到的UUID信息的最终数据源均来源于一个卷的Metadata数据,在Linux系统中我们称存放Metadata数据的区域为superblock,该区域位于一个卷的开始位置,占用一定长度的区域。详情可以参考链接:http://www.linfo.org/superblock
  查询一个卷的superblock信息的命令如下:dumpe2fs

	# dumpe2fs /dev/sda2 | grep superblock
	dumpe2fs 1.39 (29-May-2006)
	  Primary superblock at 0, Group descriptors at 1-1
	  Backup superblock at 32768, Group descriptors at 32769-32769
	  Backup superblock at 98304, Group descriptors at 98305-98305
	  Backup superblock at 163840, Group descriptors at 163841-163841
	  Backup superblock at 229376, Group descriptors at 229377-229377
	  Backup superblock at 294912, Group descriptors at 294913-294913

你可能感兴趣的:(云存储)