dortania / bugtracker

Dortania Bugtracker
108 stars 7 forks source link

[Suggestion] Multi-boot partitioning recommendations #311

Open wsy opened 1 year ago

wsy commented 1 year ago

Guide in question

TODO: some way of creating a separate windows Recovery, I cannot find any guide on how to do that so that Windows would recognize it natively, if you know of a guide or know how to do it, open a PR (opens new window)or an issue (opens new window)with your ideas.

Link to page with the issue

https://dortania.github.io/OpenCore-Multiboot/QUICK.html

Quick suggestion on how to create "Windows Recovery Partition" and get it recognized by Windows Installer

In diskpart.exe, the following commands will work.

create partition primary size=1024
format fs=ntfs quick label=Recovery
set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac
GPT ATTRIBUTES=0x8000000000000001

Explaination

Creating the partition

First, create a primary partition and format it as NTFS. You may adjust 'size' and 'label' parameter to meet your need. Recommended minimal size is 1024MiB. Real Windows-installer-created recovery partition have label 'WinRE Tools'

About the recommended size

Windows Installer by default creates recovery partition of size 350MiB(Win8) and 450MiB(Win10), which is just enough to put recovery image. However, upon Windows update (e.g. From 1909 to 2004), this partition is not big enough to put new recovery images and Windows will shrink system partition (Drive C) and create a new recovery partition with size of approximately 900+MiB. After Windows upgrade, you will ends up having two recovery partitions: One is empty 450MiB old one and the other one is 900+MiB new one. To avoid this, I recommend that you create this partition with 1024MiB size (or maybe 1536MiB or more).

About GPT Partition Attributes

This is a 64 bit (16 digit hex value) field for different flags. According to Microsoft, the preferable, 'user-friendly' way to modify this, is through the "attributes" command within diskpart.exe because you may use "Flag Name" which is very self-explaining so you may know what attribute you're setting and clearing. The 'attributes' command can set the following flags:

FlagName Value
Hidden 0x4000 0000 0000 0000
READONLY 0x1000 0000 0000 0000
NODEFAULTDRIVELETTER 0x8000 0000 0000 0000
SHADOWCOPY 0x2000 0000 0000 0000

We need flag 0x8000 0000 0000 0000 and flag 0x0000 0000 0000 0001. But from the table, we don't see any flag with value 0x0000 0000 0000 0001. So, we must use gpt attributes command to achieve this.

Other knowledge to share

Manually Windows recovery partition modification

Windows have a built-in command line tool named ReAgentc.exe. Years ago, I used to manually create Recovery partition and use this program to tell Windows to use that partition as Recovery partition. So, actually, it's not mandatory to create recovery partition before Windows installation if you want a standalone recovery partition.

# This command can lookup current configuration
ReAgentc.exe /info
# This command can set R drive as Recovery partition
ReAgentc.exe /SetReImage /path R:\Recovery\WindowsRE

Microsoft default partition layout and Apple's incompatibility with it

By default, on a blank disk, Windows installer creates partition in the following order:

Size Partition
450MiB Recovery partition
99MiB EFI partition
16MiB MSR partition
Remaining Windows partition

I don't know why Microsoft places EFI partition after Recovery partition. And I don't know why Apple thinks 'This GPT disk does not have EFI partition' if EFI partition is not the first partition.

While I was using Disk Utility app of macOS to operate on a disk with above partition layout, I encountered an error saying something about insufficient space. The actual cause was Apple tries to create 200M EFI partition before the first partition.

My partition layout habit/preference

Offset Size Partition
1MiB 2543MiB EFI partition
2544MiB 16MiB MSR partition
2.5GiB 1024MiB Recovery partition
3.5GiB Remaining All other partitions for one or more operating systems

The reason I'm using 2543MiB EFI partition:

My hackintosh partition layout

I got Lenovo K29 laptop with 250GB mSATA SSD + 500GB SATA HDD and I configured FusionDrive. Here's my layout:

Offset Size macOS DeviceName Partition
1MiB 2047MiB disk0s1 EFI partition
2.0GiB 120GiB disk0s2 APFS container
122GiB 100GiB disk0s3 Windows
222GiB 16GiB disk0s4 EXT4 Ubuntu
20KiB 200MiB disk1s1 EFI partition (Apple created)
200MiB20KiB 186.2GiB disk1s2 APFS container
186.4GiB 279.3GiB disk1s3 HFS+ TimeMachine Partition
465.7GiB 128MiB disk1s4 Apple Boot partition (Apple created)

APFS Fusion Drive will be disk2 upon boot and it uses disk0s2 and disk1s2. This demonstrates:

My EFI partition file layout

EFI Partition
|- EFI
|  |- BOOT
|  |  |- BOOTx64.efi
|  |  |- BOOTx64.windows.efi
|  |  |- BOOTx64.oc0.8.8.efi
|  |  |- BOOTx64.oc0.8.7.efi
|  |  |- BOOTx64.shim.efi
|  |
|  |- Apple
|  |  |- Apple's files
|  |
|  |- Microsoft
|  |  |- Windows boot loader files
|  |
|  |- ubuntu
|  |  |- GRUB files
|  |
|  |- OC
|     |- OpenCore files
|
|- WinPE
   |- WinPE.wim
   |- boot.sdi

This layout can fully utilize the design of 'EFI Spec': /EFI/<vendor>. In this case 'vendor' is 'Apple', 'Microsoft', 'OC', 'ubuntu'. In OC's UEFI shell, or under Windows/macOS/ubuntu, I can delete BOOTx64.efi and copy any other efi file as BOOTx64.efi.

Finally

I'm not so good at Markdown writing. Sorry for the formatting. Also, I'm sorry because I feel that I'm a little off topic for the latter part of the issue.