我有一个行为很奇怪的 CentOS 7 机器。首次启动时,键入“blkid”会产生:
[BurnC7 (2015-12-17 22:00:25) ~]# blkid
/dev/block/8:3: UUID="c83f7479-4bc1-44e5-84ae-e38a83e75219" TYPE="ext4"
/dev/block/8:2: UUID="2a5bfdfb-2b1d-4748-96bd-fe919b132ce4" TYPE="ext4"
/dev/block/8:5: UUID="94be252f-51df-44cf-afde-57214a08d149" TYPE="swap"
[BurnC7 (2015-12-17 22:00:26) ~]#
我正在寻找 UUID -> /dev/sdX 设备名称联姻,这是正常输出。更令人费解的是,从 lsblk 指定一个我知道存在的分区,输入“blkid /dev/sda2”,例如,它现在显示在常规的“blkid”输出中:
[BurnC7 (2015-12-17 22:00:26) ~]# blkid /dev/sda2
/dev/sda2: UUID="2a5bfdfb-2b1d-4748-96bd-fe919b132ce4" TYPE="ext4"
[BurnC7 (2015-12-17 22:02:31) ~]# blkid
/dev/block/8:3: UUID="c83f7479-4bc1-44e5-84ae-e38a83e75219" TYPE="ext4"
/dev/block/8:2: UUID="2a5bfdfb-2b1d-4748-96bd-fe919b132ce4" TYPE="ext4"
/dev/block/8:5: UUID="94be252f-51df-44cf-afde-57214a08d149" TYPE="swap"
/dev/sda2: UUID="2a5bfdfb-2b1d-4748-96bd-fe919b132ce4" TYPE="ext4"
[BurnC7 (2015-12-17 22:02:33) ~]#
更奇怪的是,重启后,blkid 输出现在看起来很好:
[BurnC7 (2015-12-17 22:04:35) ~]# blkid
/dev/sda2: UUID="2a5bfdfb-2b1d-4748-96bd-fe919b132ce4" TYPE="ext4"
/dev/sda3: UUID="c83f7479-4bc1-44e5-84ae-e38a83e75219" TYPE="ext4"
/dev/sda5: UUID="94be252f-51df-44cf-afde-57214a08d149" TYPE="swap"
[BurnC7 (2015-12-17 22:04:37) ~]#
很明显,blkid 正在从某个地方获取流浪汉信息——但是在哪里呢?
是否有更可靠的方法来获取 UUID -> /dev/ 设备名称关系?
编辑:正如下面 Michael Hampton 所建议的,“ls -l /dev/disk/by-uuid/”可以工作,即使 blkid 没有(这与上面的例子不同):
[BurnC7 (2015-12-18 12:00:40) ~]# blkid
/dev/block/8:3: UUID="ac2e5bb8-76d9-47e1-b5f7-3b91fad9e35f" TYPE="ext4"
/dev/block/8:2: UUID="6de21dfd-956d-4593-a8f2-88eeed2198f8" TYPE="ext4"
/dev/block/8:5: UUID="f6c41a22-f962-4b71-b880-54c8afb49516" TYPE="swap"
[BurnC7 (2015-12-18 12:00:41) ~]# ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Dec 18 11:41 6de21dfd-956d-4593-a8f2-88eeed2198f8 -> ../../sda2
lrwxrwxrwx 1 root root 10 Dec 18 11:41 ac2e5bb8-76d9-47e1-b5f7-3b91fad9e35f -> ../../sda3
lrwxrwxrwx 1 root root 10 Dec 18 11:41 f6c41a22-f962-4b71-b880-54c8afb49516 -> ../../sda5
[BurnC7 (2015-12-18 12:00:47) ~]#
要按 UUID 查找设备,您可以在
/dev/disk/by-uuid
.例如: