通过UUID方式挂载分区

UUID 全称是 Universally Unique Identifier,每个分区都有一个唯一的 UUID 值,可以通过UUID指挂载分区,避免出现分区混乱的问题。

1、使用blkid命令查看UUID值:

# blkid 
/dev/sdb1: UUID="5b7d6b6b-f19a-42dc-a363-45bddfe1e536" TYPE="ext4" 
/dev/sda1: UUID="18bbf4bf-e262-4684-9e65-ba38beca5c83" TYPE="xfs" 
/dev/sda2: UUID="88640353-c4cf-44ff-8fd9-9dbdcbf6c027" TYPE="xfs" 
/dev/sda3: UUID="c0450c68-f837-4551-b30b-a27f5d021ed3" TYPE="xfs" 
/dev/sda5: UUID="45c29147-04b3-4367-a6c5-44b8d80ae802" TYPE="swap" 
/dev/sda6: UUID="b82d2c77-a0ee-4cd1-822a-8ebcb93b3c5f" TYPE="xfs" 
/dev/loop0: UUID="f2873bbd-b0b9-41f5-a760-0e27f0464c0b" TYPE="xfs"

2、使用ll /dev/disk/by-uuid/命令查看UUID值:

# ll /dev/disk/by-uuid/
总用量 0
lrwxrwxrwx 1 root root 10 8月   9 16:02 18bbf4bf-e262-4684-9e65-ba38beca5c83 -> ../../sda1
lrwxrwxrwx 1 root root 10 8月   9 16:02 45c29147-04b3-4367-a6c5-44b8d80ae802 -> ../../sda5
lrwxrwxrwx 1 root root 10 8月   9 16:02 5b7d6b6b-f19a-42dc-a363-45bddfe1e536 -> ../../sdb1
lrwxrwxrwx 1 root root 10 8月   9 16:02 88640353-c4cf-44ff-8fd9-9dbdcbf6c027 -> ../../sda2
lrwxrwxrwx 1 root root 10 8月   9 16:02 b82d2c77-a0ee-4cd1-822a-8ebcb93b3c5f -> ../../sda6
lrwxrwxrwx 1 root root 10 8月   9 16:02 c0450c68-f837-4551-b30b-a27f5d021ed3 -> ../../sda3
lrwxrwxrwx 1 root root 11 8月  26 22:04 f2873bbd-b0b9-41f5-a760-0e27f0464c0b -> ../../dm-32

3、通过UUID值挂载分区:

# cat /etc/fstab 
UUID=b82d2c77-a0ee-4cd1-822a-8ebcb93b3c5f /                       xfs     defaults        0 0
UUID=18bbf4bf-e262-4684-9e65-ba38beca5c83 /boot                   xfs     defaults        0 0
UUID=c0450c68-f837-4551-b30b-a27f5d021ed3 /home                   xfs     defaults        0 0
UUID=88640353-c4cf-44ff-8fd9-9dbdcbf6c027 /usr                    xfs     defaults        0 0
UUID=45c29147-04b3-4367-a6c5-44b8d80ae802 swap                    swap    defaults        0 0
UUID=5b7d6b6b-f19a-42dc-a363-45bddfe1e536 /datadisk		  ext4	  defaults	  0 0