答案1
答案2
未安装且未分区的硬盘驱动器,我需要获取它的 UUID
UUID 是文件系统或格式的属性,未格式化的硬盘没有 UUID。您可以获得分区的 PARTUUID 和分区表的 PTUUID,看到这个问题,但这也不适用于空磁盘。
磁盘的唯一标识符是WWID/WWN由磁盘本身提供。您可以从 sysfs 获取它
$ cat /sys/block/sda/device/wwid
naa.5002538e40aa0206
或来自符号链接/dev/disk/by-id
$ ls -la /dev/disk/by-id/ | grep sda
lrwxrwxrwx. 1 root root 9 Mar 10 07:21 wwn-0x5002538e40aa0206 -> ../../sda
或 UDev(负责创建符号链接)
$ udevadm info /dev/sda | grep ID_WWN
E: ID_WWN=0x5002538e40aa0206
E: ID_WWN_WITH_EXTENSION=0x5002538e40aa0206
答案3
blkid
应该适用于未安装的磁盘,但您必须确保磁盘已格式化。
列出磁盘:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1,7T 0 disk
sdb 8:16 0 300G 0 disk
sdc 8:32 0 64G 0 disk
├─sdc1 8:33 0 63G 0 part /
├─sdc2 8:34 0 1K 0 part
└─sdc5 8:37 0 975M 0 part [SWAP]
格式化前:
$ blkid -o list
device fs_type label mount point UUID
----------------------------------------------------------------------------------------------------------------------------
/dev/sdc1 ext4 / 9c49994f-6ffd-496a-945b-85e3b04a84ef
/dev/sdc5 swap [SWAP] f14ea985-e1e6-43a8-ba09-12a273604c96
注:/dev/sdb
未显示。
使用 ext4 格式化磁盘:
$ mkfs.ext4 /dev/sdb
mke2fs 1.46.2 (28-Feb-2021)
Discarding device blocks: done
Creating filesystem with 78643200 4k blocks and 19660800 inodes
Filesystem UUID: d4b71992-fbc3-4263-b974-e5933a1ebfe4
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616
Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done
现在blkid
再次运行:
$ blkid -o list
device fs_type label mount point UUID
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/dev/sdc1 ext4 / 9c49994f-6ffd-496a-945b-85e3b04a84ef
/dev/sdc5 swap [SWAP] f14ea985-e1e6-43a8-ba09-12a273604c96
/dev/sdb ext4 (not mounted) d4b71992-fbc3-4263-b974-e5933a1ebfe4