在 UEFI 中获取分区的分区 uuid 的最简单方法是什么?

What is the easiest way to get the partition uuid of a partition in UEFI?

如何在我拥有 device_handle 的分区的 uefi 中获取 uuid? 例如,我正在遍历 uefi 中的分区,我想获取分区的 uuid。 (这是一个 gpt 磁盘。)

在 GPT header 中,偏移量 56 处是一个 16 字节的 DiskGUID,可用于唯一标识磁盘。 (Efi 规范 5.3.2)。

A "GPT Partition Entry" 有 2 个 GUID

PartitionTypeGUID Unique ID that defines the purpose and type of this Partition. A value of zero defines that this partition entry is not being used.

UniquePartitionGUID GUID that is unique for every partition entry. Every partition ever created will have a unique GUID. This GUID must be assigned when the GPT Partition Entry is created. The GPT Partition Entry is created whenever the NumberOfPartitionEntr ies in the GPT Header is increased to include a larger range of addresses.

我认为您正在寻找 UniquePartitionGUID

如果您有关联的分区 device_handle 那么您可以获得相应的设备路径,即使用 gnu-efi

DevicePath=DevicePathFromHandle(partition_handle);

接下来您解析 DevicePath 以查找节点,如下所示

-Generic Device Path Header- where

Type = Media Device Path (0x04)
Sub type = Hard Drive (0x01)
... 
Partition Signature = partition GUID  <<<<<<<<
Partition Format = GPT (0x02)

在此结构中,您将找到所需的 GUID

参考 UEFI 规范 2.5(第 9 章)