How to obtain and view uuid in ubuntu

Source: Internet
Author: User
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)

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.