zoukankan      html  css  js  c++  java
  • Linux知识点拾遗-磁盘UUID

    查看磁盘UUID

    • 方法1
    ls -l /dev/disk/by-uuid
    

    example:

    [root@dplinux ~]# ll /dev/disk/by-uuid/
    total 0
    lrwxrwxrwx 1 root root 10 Jun 23  2016 2063e5ae-7091-4a89-9bc2-d6ec2a3b8965 -> ../../sda1
    lrwxrwxrwx 1 root root 10 Jun 23  2016 5196cb6b-468d-487b-8a59-f83fd0a01027 -> ../../sdb1
    lrwxrwxrwx 1 root root 10 Jun 23  2016 59847c94-f39c-4215-81c6-bc5da34152e7 -> ../../sda3
    lrwxrwxrwx 1 root root 10 Jun 23  2016 880d7411-cc22-4fdc-bb48-0ea212f3f296 -> ../../sda2
    [root@dplinux ~]#
    
    • 方法2
    blkid
    blkid /dev/sda5
    

    example:

    [root@dplinux ~]# blkid
    /dev/sda3: UUID="59847c94-f39c-4215-81c6-bc5da34152e7" TYPE="ext4"
    /dev/sdb1: UUID="5196cb6b-468d-487b-8a59-f83fd0a01027" TYPE="xfs"
    /dev/sda1: UUID="2063e5ae-7091-4a89-9bc2-d6ec2a3b8965" TYPE="ext4"
    /dev/sda2: UUID="880d7411-cc22-4fdc-bb48-0ea212f3f296" TYPE="swap"
    [root@dplinux ~]#
    [root@dplinux ~]# blkid /dev/sda1
    /dev/sda1: UUID="2063e5ae-7091-4a89-9bc2-d6ec2a3b8965" TYPE="ext4"
    [root@dplinux ~]#
    

    修改磁盘UUID

    • 生成UUID
    uuidgen
    

    examlple:

    [root@dplinux ~]# uuidgen
    0c8f2bce-66b2-4c79-a819-77ef37b932c2
    [root@dplinux ~]#
    
    • 将UUID写到分区
    # 成成一个UUID,并写通过tune2fs -U写入到分区
    uuidgen | xargs tune2fs /dev/sda5 -U
    
    # 使用tune2fs -U写入指定的UUID
    tune2fs -U c1b9d5a2-f162-11cf-9ece-0020afc76f16 /dev/sda5
    

    example:

    # 查看分区UUID
    [root(0)@dplinux-node1 09:50:53 ~]# blkid /dev/vdb
    /dev/vdb: UUID="eca8d8b9-ba2c-40d7-a32b-7f475f054cca" TYPE="ext4"
    [root(0)@dplinux-node1 09:51:02 ~]#
    
    # 生成一个UUID
    [root(0)@dplinux-node1 09:51:12 ~]# uuidgen
    fd730d2d-4c3d-4851-b436-d3b3e49a5286
    [root(0)@dplinux-node1 09:51:31 ~]#
    
    # 将生成的UUID写入磁盘分区
    [root(0)@dplinux-node1 09:51:17 ~]# tune2fs -U fd730d2d-4c3d-4851-b436-d3b3e49a5286 /dev/vdb
    tune2fs 1.41.12 (17-May-2010)
    [root(0)@dplinux-node1 09:51:31 ~]#
    
    # 确认修改结果
    [root(0)@dplinux-node1 09:51:34 ~]# blkid /dev/vdb
    /dev/vdb: UUID="fd730d2d-4c3d-4851-b436-d3b3e49a5286" TYPE="ext4"
    [root(0)@dplinux-node1 09:51:42 ~]#
    

    Linux UUID的作用及意义

    原因1:它是真正的唯一标志符

    UUID为系统中的存储设备提供唯一的标识字符串,不管这个设备是什么类型的。如果你在系统中添加了新的存储设备如硬盘,很可能会造成一些麻烦,比如说启动的时候因为找不到设备而失败,而使用UUID则不会有这样的问题。

    原因2:设备名并非总是不变的

    自动分配的设备名称并非总是一致的,它们依赖于启动时内核加载模块的顺序。如果你在插入了USB盘时启动了系统,而下次启动时又把它拔掉了,就有可能导致设备名分配不一致。

    使用UUID对于挂载移动设备也非常有好处──例如我有一个24合一的读卡器,它支持各种各样的卡,而使用UUID总可以使同一块卡挂载在同一个地方。

    原因3:ubuntu中的许多关键功能现在开始依赖于UUID

    例如grub──系统引导程序,现在可以识别UUID,打开你的/boot/grub/menu.lst,你可以看到类似如下的语句root=UUID=2063e5ae-7091-4a89-9bc2-d6ec2a3b8965

    example:

    [root@dplinux ~]# tail -4 /boot/grub/menu.lst
    title CentOS 6 (2.6.32-573.el6.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.32-573.el6.x86_64 ro root=UUID=2063e5ae-7091-4a89-9bc2-d6ec2a3b8965 rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD  KEYTABLE=us SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_NO_LVM rd_NO_DM rhgb quiet console=tty1 console=ttyS1,115200
        initrd /boot/initramfs-2.6.32-573.el6.x86_64.img
    [root@dplinux ~]#
    
  • 相关阅读:
    高斯消元法
    DP:Making the Grade(POJ 3666)
    Heap:Sunscreen(POJ 3614)
    ShortestPath:Silver Cow Party(POJ 3268)
    ShortestPath:Wormholes(POJ 3259)
    ShortestPath:Six Degrees of Cowvin Bacon(POJ 2139)
    DP:Bridging Signals(POJ 1631)
    DP:Wooden Sticks(POJ 1065)
    Greedy:Protecting the Flowers(POJ 3262)
    Greedy:Stripes(POJ 1826)
  • 原文地址:https://www.cnblogs.com/thatsit/p/linux-zhi-shi-dian-shi-yici-panuuid.html
Copyright © 2011-2022 走看看