This article describes how to obtain and view uuid in ubuntu. For more information, see the following tag: Ubuntu.
1. using UUID to identify a hard disk has many advantages. it is the unique code of a hard disk, so when the position of the hard disk plug-in changes, although sda may become sdc, but this code will not change. Therefore, the hard disk ID such as/dev/sda1 in fstab may be messy. when one hard disk such as sdb fails, sdc will become sdb and mount it to the original position of sdb. Therefore, UUID should be used to write data to fstab.
You can use this command to obtain the UUID.
Copy codeThe code is as follows:
Sudo blkid
2. sometimes, after a partition is reformatted, the UUID changes. you can use this command to refresh the UUID.
Copy codeThe code is as follows:
Sudo blkid-s none
3. write a piece of code by yourself and obtain uuid based on/dev/sda. this is also the case for beginners of python.
Copy codeThe code is as follows:
Def get_disk_uuid (disk ):
Uuid =''
Cmd = 'sudo blkid'
Result = yitg_check_cmd_execute (cmd)
If (result [HEAD]! = 0 ):
Return 0 xACD
Res = result [BODY]
For I in range (0, len (res )):
Item = res [I]
Item_divide = item. split (':')
Item_zero = (item_divide [0])
If (disk! = Item_zero ):
Pass
Else:
Uuid_item = item_divide [1]
Uuid_divide = uuid_item.split ('"')
Uuid = uuid_divide [1]
Return uuid
Return uuid
One of the interface code is as follows:
Copy codeThe code is as follows:
Def yitg_check_cmd_execute (cmd ):
(OS _result) = OS. popen3 (cmd)
Res = OS _result [1]. readlines ()
Error_res = OS _result [2]. readlines ()
If (error_res ):
Return send_msg (res, 0 xABB)
Else:
Return send_msg (res, 0)