Inokinoki / QEFIEntryManager

A userspace cross-platform EFI boot entry management GUI App based on Qt.
GNU General Public License v3.0
272 stars 10 forks source link

Add boot entry from EFI #13

Open Inokinoki opened 2 years ago

Inokinoki commented 2 years ago

Need to read FAT filesystem and browse files in it.

Inokinoki commented 1 year ago

qtparted-0.5.0.zip

Inokinoki commented 12 months ago

EFI System partition: C12A7328-F81F-11D2-BA4B-00A0C93EC93B

Inokinoki commented 12 months ago

Partition table header (LBA 1):

Offset Length Contents
0 (0x00) 8 bytes Signature ("EFI PART", 45h 46h 49h 20h 50h 41h 52h 54h or 0x5452415020494645ULL[a] on little-endian machines)
8 (0x08) 4 bytes Revision number of header - 1.0 (00h 00h 01h 00h) for UEFI 2.10
12 (0x0C) 4 bytes Header size in little endian (in bytes, usually 5Ch 00h 00h 00h or 92 bytes)
16 (0x10) 4 bytes CRC32 of header (offset +0 to +0x5b) in little endian, with this field zeroed during calculation
20 (0x14) 4 bytes Reserved; must be zero
24 (0x18) 8 bytes Current LBA (location of this header copy)
32 (0x20) 8 bytes Backup LBA (location of the other header copy)
40 (0x28) 8 bytes First usable LBA for partitions (primary partition table last LBA + 1)
48 (0x30) 8 bytes Last usable LBA (secondary partition table first LBA − 1)
56 (0x38) 16 bytes Disk GUID in mixed endian[12]
72 (0x48) 8 bytes Starting LBA of array of partition entries (usually 2 for compatibility)
80 (0x50) 4 bytes Number of partition entries in array
84 (0x54) 4 bytes Size of a single partition entry (usually 80h or 128)
88 (0x58) 4 bytes CRC32 of partition entries array in little endian
92 (0x5C) * Reserved; must be zeroes for the rest of the block (420 bytes for a sector size of 512 bytes; but can be more with larger sector sizes)
Inokinoki commented 12 months ago

Partition entries (LBA 2–33):

Offset Length Contents
0 (0x00) 16 bytes Partition type GUID (mixed endian[12])
16 (0x10) 16 bytes Unique partition GUID (mixed endian)
32 (0x20) 8 bytes First LBA (little endian)
40 (0x28) 8 bytes Last LBA (inclusive, usually odd)
48 (0x30) 8 bytes Attribute flags (e.g. bit 60 denotes read-only)
56 (0x38) 72 bytes Partition name (36 UTF-16LE code units)
Inokinoki commented 12 months ago

Protective MBR (LBA 0)

For limited backward compatibility, the space of the legacy Master Boot Record (MBR) is still reserved in the GPT specification, but it is now used in a way that prevents MBR-based disk utilities from misrecognizing and possibly overwriting GPT disks. This is referred to as a protective MBR.[11]

A single partition of type EEh, encompassing the entire GPT drive (where "entire" actually means as much of the drive as can be represented in an MBR), is indicated and identifies it as GPT. Operating systems and tools which cannot read GPT disks will generally recognize the disk as containing one partition of unknown type and no empty space, and will typically refuse to modify the disk unless the user explicitly requests and confirms the deletion of this partition. This minimizes accidental erasures.[11] Furthermore, GPT-aware OSes may check the protective MBR and if the enclosed partition type is not of type EEh or if there are multiple partitions defined on the target device, the OS may refuse to manipulate the partition table.[12]

If the actual size of the disk exceeds the maximum partition size representable using the legacy 32-bit LBA entries in the MBR partition table, the recorded size of this partition is clipped at the maximum, thereby ignoring the rest of the disk. This amounts to a maximum reported size of 2 TiB, assuming a disk with 512 bytes per sector (see 512e). It would result in 16 TiB with 4 KiB sectors (4Kn), but since many older operating systems and tools are hard coded for a sector size of 512 bytes or are limited to 32-bit calculations, exceeding the 2 TiB limit could cause compatibility problems.[11]

Hybrid MBR (LBA 0 + GPT)

In operating systems that support GPT-based boot through BIOS services rather than EFI, the first sector may also still be used to store the first stage of the bootloader code, but modified to recognize GPT partitions. The bootloader in the MBR must not assume a sector size of 512 bytes.[11]

Inokinoki commented 12 months ago

image