Centos

blkid 從哪裡獲取資訊?(/dev/block/ 出現在 blkid 輸出中)

  • December 18, 2015

我有一個行為很奇怪的 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.

例如:

# 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

引用自:https://serverfault.com/questions/743892