Partitions on Windows #477
Replies: 5 comments 11 replies
-
|
A successful run of the Shim: |
Beta Was this translation helpful? Give feedback.
-
|
OK so there is Which has the new Shim layer, so we can explore if it is useful enough, actually works? Stable? Reliable? and so on. It does not fix the Primary Partition Entry Array yet, if Windows has blown it away, but it can read the Backup Partition Entry Array. |
Beta Was this translation helpful? Give feedback.
-
|
Are you seeing that 9 partitions value on disk, or is this just a logical value after something has processed the header? I checked SteamOS(Arch), Rocky, a Google cloud shell VM (Ubuntu), and FreeBSD, and assuming I'm printing the right bytes, they all seem to have it set to 128 (0x80 at offset 0x50) for their boot disks. Your 9-partition GPT header may be an outlier. Example: That UEFI spec also says "A minimum of 16,384 bytes of space must be reserved for the GPT Partition Entry Array." It's weird to see NumPartitions less than 128 entries since you have to use at least 128*128 bytes on disk anyway. |
Beta Was this translation helpful? Give feedback.
-
|
Ah hmm it's not that useful unless I make it repair the Unix label too, so I'll make a new build |
Beta Was this translation helpful? Give feedback.
-
|
OK this is what we will do. The Shim layer was fun code to write, and as a proof-of-concept does work, but it will be a pain to maintain, and make sure it works in all situations, like that of running other low-disk programs (DiskGenius, PartitionManager etc) Linux already writes NumPart==128 by default, and they are the current biggest player. OpenZFS on Windows writes with numPart==128 by default, now. So, going forward, if I detect NumPart==9, which will involve deliberately reading the backup area, I will re-write it [1] with NumPart==128. [1] That is to say, if you do an import scan, But if you import the pool, |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
So I finally understand what the issue is with OpenZFS partitioned disks, why Windows will "break" them and what we can do.
Unix uses
gpt->NumPartitions == 9.According to the UEFI specification (specifically Chapter 5 on the GUID Partition Table Format), the CRC32 checksum of the Partition Entry Array is calculated over the byte range defined by NumberOfPartitionEntries * SizeOfPartitionEntry.
9×128=1152 bytes.
Windows always calculates the
Partition Entry Arraybased on the MAX_PARTITIONS==128. Even though they are all zero after partition 9, the CRC value will then differ. The GPT partition is considered invalid.New versions of Windows 11 with helpfully then wipe the
Partition Entry Arraywith all zeros, re-calculate the CRC and update the GPT header. The CRC will now match, so Windows considers it valid, if empty.OpenZFS will now consider the disk empty, as it has no partitions.
If you now corrupt the GPT header, ie by writing
_FI Partto it, OpenZFS will now consider the GPT partition label invalid.OpenZFS will now automatically go read the Backup GPT partition at the end of the disk. The Backup CRC will be valid for 9 partitions (Windows did not change it), and it can read the
Backup Partition Entry Array. Now it finds the OpenZFS partitions and can import it.Technically, Windows has not implemented EFI GPT partitions correctly, but even if they fix it today, it doesn't solve the problem for a few years, if ever.
A)
Options then. We could replace the GPT labels with
gpt->NumPartitions == 9to begpt->NumPartitions == 128automatically, and Windows would be happy. Presumably Unix would be as well, but how sure are we on that. Unix has a bunch of variants, 32bit, endianess, toasters and so on. Are we sure we aren't breaking something? I dislike the idea of modifying the partition table just because the/a disk was too close to Windows, and now it is different (but same).B)
I have been experimenting with a Shim driver in OpenZFS. That is, a barnacle inside the OpenZFS driver, which will check out any disks on the system (and new disks being attached), read in the partition label, and if it happens to be
gpt->NumPartitions == 9.it goes and attaches a Shim driver on top of disk.sys for that specific disk (for each disk applicable).The Shim will relay all the IRP communication as normal, except for
IOCTL_DISK_GET_DRIVE_LAYOUT_EX. When it getsIOCTL_DISK_GET_DRIVE_LAYOUT_EX, which will be returned as "empty disk" as Windows as described above, it can read the EFI partition label itself, and modify the result on the fly.We could even consider repairing a previous "Windows repair" by copying the Backup label back to Primary. As long as the Shim is active, Windows will not attempt to "repair" it again.
Beta Was this translation helpful? Give feedback.
All reactions