我有一个 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) ~]#
答案1
要通过 UUID 查找设备,您可以查看/dev/disk/by-uuid
。
例如:
# ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx. 1 root root 10 Dec 18 10:43 10156170545889643033 -> ../../dm-6
lrwxrwxrwx. 1 root root 9 Dec 18 10:43 2bcef3fa-e55c-4aaa-922b-9bc142de041f -> ../../sdc
lrwxrwxrwx. 1 root root 10 Dec 18 10:43 4fa98e08-de06-4baf-9e63-6c2bde67f75e -> ../../sda3
lrwxrwxrwx. 1 root root 10 Dec 18 10:43 5166-F80B -> ../../sda1
lrwxrwxrwx. 1 root root 9 Dec 18 10:43 608464c3-d505-4829-bce3-520a74883c22 -> ../../sdb
lrwxrwxrwx. 1 root root 9 Dec 18 10:43 6aebf7e8-55cc-4684-92bf-e17d8fc23dd6 -> ../../sdd
lrwxrwxrwx. 1 root root 10 Dec 18 10:43 825aa99c-a2ef-4d4a-b739-663b58b47da8 -> ../../dm-2
lrwxrwxrwx. 1 root root 10 Dec 18 10:43 8995619969489110662 -> ../../dm-5
lrwxrwxrwx. 1 root root 10 Dec 18 10:43 b738c1d5-eb9b-4468-bb0c-573ceaafe485 -> ../../sda2
lrwxrwxrwx. 1 root root 10 Dec 18 10:43 c9a0f6de-7ac5-4858-a8b3-d7312d35acbb -> ../../dm-1
lrwxrwxrwx. 1 root root 10 Dec 18 10:43 d4c56b9b-f99a-492d-a04d-749c35d556a7 -> ../../sda5
lrwxrwxrwx. 1 root root 10 Dec 18 10:43 d693f2b3-b9cf-42a6-9383-9bd62e70804c -> ../../sda4