How to obtain the globally unique identifier UUID in Linux

Source: Internet
Author: User
Tags hash reserved time interval uuid

UUID (Universally unique IDentifiers), a globally unique identifier. It is a string that identifies the storage device in the system so that it determines all the storage devices in the system.

Why should I use UUID? Because the system automatically assigns device names that are not always consistent, they depend on the order in which the kernel loads the modules at startup. The same name may represent a different hard disk partition. If each partition has a unique UUID value, especially the kernel setting in grub, then there is no problem with partition recognition clutter.

Here are a few ways to get the UUID.

1. The simplest approach is to use the Blkid command, which is primarily used to query the file system type, Label,uuid, and so on for the system's block devices, including the swap partition. Use this command to install the E2fsprogs package.

The code is as follows:
root@10.1.1.200:~# Dpkg-l | grep e2fsprogs
II e2fsprogs 1.41.3-1 EXT2/EXT3/EXT4 file system utilities
II Libuuid-perl 0.02-4 perl extension for-using UUID interfaces as defined in E2fsprogs
root@10.1.1.200:~# Blkid
/dev/sda1:uuid= "b20e80f1-c88d-4918-9d9b-75cd7906629e" type= "ext3"
/dev/sda5:type= "swap" uuid= "1FB3D17B-B2FE-470D-B39C-F00C4A30EFBF"
/dev/sda6:uuid= "C7050200-7efb-468c-81d1-a3add309bee1" type= "ext3" sec_type= "ext2"
/dev/sda7:uuid= "934e4e22-3431-4707-8d47-dca47e76f448" type= "XFS"
/dev/hioa:uuid= "de0af117-ad92-4867-aa21-3e7d423e8864" type= "XFS"
root@10.1.1.200:~# blkid/dev/sda1
/dev/sda1:uuid= "b20e80f1-c88d-4918-9d9b-75cd7906629e" type= "ext3"
root@10.1.1.200:~# Cat/etc/blkid.tab
<device devno= "0x0801" time= "1364787338" uuid= "b20e80f1-c88d-4918-9d9b-75cd7906629e" TYPE= "ext3" >/dev/sda1 </device>
<device devno= "0x0805" time= "1364787338" type= "swap" uuid= "1FB3D17B-B2FE-470D-B39C-F00C4A30EFBF" >/dev/sda5 </device>
<device devno= "0x0806" time= "1364787338" uuid= "c7050200-7efb-468c-81d1-a3add309bee1" TYPE= "ext3" SEC_TYPE= "ext2" >/dev/sda6</device>
<device devno= "0x0807" time= "1364787338" uuid= "934e4e22-3431-4707-8d47-dca47e76f448" TYPE= "XFS" >/dev/sda7 </device>
<device devno= "0xfd00" time= "1364787338" uuid= "de0af117-ad92-4867-aa21-3e7d423e8864" TYPE= "XFS" >/dev/hioa </device>

2. Browse through the device file information under/dev/disk/by-uuid/.

The code is as follows:
root@10.1.1.200:~# ls-l/dev/disk/by-uuid/
Total 0
lrwxrwxrwx 1 root 2013-03-19 11:01 1fb3d17b-b2fe-470d-b39c-f00c4a30efbf->. /.. /sda5
lrwxrwxrwx 1 root 2013-03-19 11:01 934e4e22-3431-4707-8d47-dca47e76f448->. /.. /sda7
lrwxrwxrwx 1 root 2013-03-19 11:01 b20e80f1-c88d-4918-9d9b-75cd7906629e->. /.. /sda1
lrwxrwxrwx 1 root 2013-03-19 11:01 c7050200-7efb-468c-81d1-a3add309bee1->. /.. /sda6
lrwxrwxrwx 1 root 2013-03-19 11:02 de0af117-ad92-4867-aa21-3e7d423e8864->. /.. /hioa
root@10.1.1.200:~# Ls-l/dev/disk/by-uuid/| grep sda1 | awk ' {print $} '
b20e80f1-c88d-4918-9d9b-75cd7906629e

3. View by vol_id command

The code is as follows:
root@10.1.1.200:~# vol_id/dev/sda1
Id_fs_usage=filesystem
Id_fs_type=ext3
id_fs_version=1.0
id_fs_uuid=b20e80f1-c88d-4918-9d9b-75cd7906629e
id_fs_uuid_enc=b20e80f1-c88d-4918-9d9b-75cd7906629e
Id_fs_label=
Id_fs_label_enc=
Id_fs_label_safe=
root@10.1.1.200:~# vol_id/dev/sda1 | grep ' UUID '
id_fs_uuid=b20e80f1-c88d-4918-9d9b-75cd7906629e
id_fs_uuid_enc=b20e80f1-c88d-4918-9d9b-75cd7906629e,

4. Using TUNE2FS, it is the file System adjustment tool under Linux

The code is as follows:
root@10.1.1.200:~# tune2fs-l/dev/sda1
TUNE2FS 1.41.3 (12-oct-2008)
FileSystem Volume Name: <none>
Last mounted on: <not available>
FileSystem uuid:b20e80f1-c88d-4918-9d9b-75cd7906629e
FileSystem Magic Number:0xef53
FileSystem Revision #: 1 (dynamic)
FileSystem features:has_journal ext_attr resize_inode dir_index filetype needs_recovery sparse_super large_file
FileSystem Flags:signed_directory_hash
Default mount options: (None)
FileSystem State:clean
Errors behavior:continue
FileSystem OS Type:linux
Inode count:1864128
Block count:7442103
Reserved Block count:372105
Free blocks:6884819
Free inodes:1712582
The block:0
root@10.1.1.200:~# Tune2fs-l/dev/sda1 | grep ' UUID '
FileSystem uuid:b20e80f1-c88d-4918-9d9b-75cd7906629e

Here's an extra look at the TUNE2FS some common parameters:

The code is as follows:
root@192.168.2.80:~# TUNE2FS--help
TUNE2FS 1.41.3 (12-oct-2008)
Tune2fs:invalid option-'-'
USAGE:TUNE2FS [-E Errors_behavior] [G Group]

[i interval[d|m|w]] file system check interval, the system at the time interval, automatically check the file system.
[-j] [-j journal_options] Convert file system
[-l] Display file system parameters
[-M reserved_blocks_percent] set the percentage of space reserved
[-O [^]mount_options[,...]] Sets the default load parameters.
[-c Max_mounts_count] means that the file system needs to run the Fsck check file system after the mount Count reaches its set.
Typically, if you use the Ext3 file system, use-C 0 To turn off file system checks after the mount number is reached.
Prohibit forced file system checks:

The code is as follows:
root@10.1.1.200:~# tune2fs-i0-c0/dev/sda1
TUNE2FS 1.41.3 (12-oct-2008)
Setting Maximal mount Count to-1
Setting interval between checks to 0 seconds

There is also a dump2fs is also a tool for file system tuning.

DUMP2FS Displays the current disk status:

The code is as follows:
root@10.1.1.200:~# dumpe2fs/dev/sda1
FileSystem Volume Name: <none>
Last mounted on: <not available>
FileSystem uuid:b20e80f1-c88d-4918-9d9b-75cd7906629e
FileSystem Magic Number:0xef53
FileSystem Revision #: 1 (dynamic)
FileSystem features:has_journal ext_attr resize_inode dir_index filetype needs_recovery sparse_super large_file
FileSystem Flags:signed_directory_hash
Default mount options: (None)
FileSystem State:clean
Errors behavior:continue
FileSystem OS Type:linux
Inode count:1864128
Block count:7442103
Reserved Block count:372105
Free blocks:6884819
Free inodes:1712582
The block:0
Block size:4096
Fragment size:4096
Reserved GDT blocks:1022
Blocks per group:32768
Fragments per group:32768
Inodes per group:8176
Inode blocks per group:511
FileSystem Created:fri Nov 16 15:36:59 2012
Last Mount Time:tue Mar 19 11:02:58 2013
Last write time:wed Mar 27 14:09:25 2013
Mount count:17
Maximum Mount Count:-1
Last Checked:fri Nov 16 15:36:59 2012
Check interval:0 (<none>)
Reserved blocks uid:0 (user root)
Reserved blocks gid:0 (group root)
The Inode:11
Inode size:256
Required Extra isize:28
Desired extra isize:28
Journal Inode:8
Orphan inode:1618875
Default Directory HASH:HALF_MD4
Directory Hash Seed:3090ccf1-625c-4934-9ec4-be3f74767f98
Journal Backup:inode Blocks
Journal size:128m

The code is as follows:

Group 0: (Blocks 0-32767)
Primary superblock at 0, Group descriptors at 1-2
Reserved GDT blocks at 3-1024
Block bitmap at 1025 (+1025), Inode bitmap at 1026 (+1026)
Inode table at 1027-1537 (+1027)
0 Free blocks, 8152 free inodes, 2 directories
Free Blocks:
Free inodes:22, 25, 27-8176
Group 1: (Blocks 32768-65535)
Backup superblock at 32768, Group descriptors at 32769-32770
Reserved GDT blocks at 32771-33792
Block bitmap at 33793 (+1025), Inode bitmap at 33794 (+1026)
Inode table at 33795-34305 (+1027)
3 free blocks, 8176 free inodes, 0 directories
Free blocks:34309-34311
Free inodes:8177-16352
Group 2: (Blocks 65536-98303)
Block bitmap at 65536 (+0), Inode bitmap at 65537 (+1)
Inode table at 65538-66048 (+2)
7 Free blocks, 8176 free inodes, 0 directories
Free blocks:66049-66055
Free inodes:16353-24528
Group 3: (Blocks 98304-131071)
Backup superblock at 98304, Group descriptors at 98305-98306
Reserved GDT blocks at 98307-99328
Block bitmap at 99329 (+1025), Inode bitmap at 99330 (+1026)
Inode table at 99331-99841 (+1027)
6 free blocks, 8176 free inodes, 0 directories
Free blocks:99842-99847
Free inodes:24529-32704
Group 4: (Blocks 131072-163839)
Block bitmap at 131072 (+0), Inode bitmap at 131073 (+1)
Inode table at 131074-131584 (+2)
Free blocks, 0 free inodes, 0 directories
Free blocks:132074-132079, 133643-133647, 135671, 137739-137743, 139811-139815, 141814-141815, 143879, 145922-145927, 147933-147935, 150022-150023, 15207
1, 154107-154111, 156169-156175, 158202-158207, 160251-160255, 162293-162295
Free Inodes:
Group 5: (Blocks 163840-196607)
Backup superblock at 163840, Group descriptors at 163841-163842
Reserved GDT blocks at 163843-164864
Block bitmap at 164865 (+1025), Inode bitmap at 164866 (+1026)
Inode table at 164867-165377 (+1027)
0 Free blocks, 8130 free inodes, 0 directories
Free Blocks:
Free inodes:40881, 40928-49056

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.