|
| 1 | +# How to Install System |
| 2 | + |
| 3 | +## Disk Partitioning & Formatting |
| 4 | + |
| 5 | +### Disk & Partition & Volume |
| 6 | + |
| 7 | +**Disk** is a physical storage device that can be logically recognized by operating system as a **whole**. |
| 8 | +A disk can be split into multiple **logical partition**, a partition means a address of address of the disk managed by certain **partition table**. |
| 9 | +A partition can have certain **file system format** which describes the advance abstraction of storage units, also instructs the system how to manipulate these storage. |
| 10 | +Such partition abstracted as file system format is so called **volume**. |
| 11 | + |
| 12 | +> [!NOTE] |
| 13 | +> Operating system lives in a disk, so you would probably need to run installer on a external storage(such as USB stick) when installing a new system. |
| 14 | +
|
| 15 | +### Partition Style(Scheme) |
| 16 | + |
| 17 | +The form of how a physical disk was partitioned is so called *Partition Style* or *Partition Scheme*. |
| 18 | + |
| 19 | +- GPT: GUID Partition Table |
| 20 | +- MBR: Master Boot Record |
| 21 | + |
| 22 | +Partition scheme is recognized by certain byte in partition table. |
| 23 | + |
| 24 | +> [!IMPORTANT] |
| 25 | +> Whether a partition scheme is supported depending on the **firmware** of your machine. |
| 26 | +> That is because firmware is the layer instructs the system how to read and write the disk. |
| 27 | +
|
| 28 | +> [!NOTE] |
| 29 | +> A uninitialized disk has partition scheme `RAW` which means no partition table available. |
| 30 | +
|
| 31 | +> [!NOTE] |
| 32 | +> You might have heard of *primary partition* and *extended partition*, those are only specific to MBR scheme. |
| 33 | +> MBR scheme only allow one partition to be file system, the one partition is so called *primary partition*. |
| 34 | +> GPT scheme doesn't have such limit, every partition in GPT scheme is equivalent of primary and can be formatted as file system. |
| 35 | +
|
| 36 | +### Mounting |
| 37 | + |
| 38 | +Mounting is simply to assign a starting point to the partition so that the file system can represent its content in absolute path. |
| 39 | +It's yet another abstraction over partition |
| 40 | + |
| 41 | +On Windows you assign the partition a drive letter(such as `C:`) to mount a partition. |
| 42 | +On Linux you should mount conventionally to `/mnt/...`. |
| 43 | + |
| 44 | +### Volume |
| 45 | + |
| 46 | +A volume is a system abstraction wrapping over **formatted** partition that describes something more than storage boundaries and offsets, |
| 47 | +such as *total size*, *remaining size*, *file system type* etc. |
| 48 | +So volume is not a real thing, but an aggregation over the partition, a logical presentation of partition. |
| 49 | + |
| 50 | +### File System Format |
| 51 | + |
| 52 | +File system formats are predefined rules for reading/writing chunks of storage, they're standards to be implemented by the operating system. |
| 53 | +The operating system can identify the format by reading the certain byte of certain sector, and then the system would know how to manipulate the storage, as long as the format standard is implemented. |
| 54 | + |
| 55 | +## What is Firmware |
| 56 | + |
| 57 | +Firmware is the most primitive layer built in the motherboard(hardware), it's specific to your machine. |
| 58 | + |
| 59 | +- **UEFI**: Unified Extensible Firmware Interface |
| 60 | +- **BIOS**: Basic Input/Output System |
| 61 | + |
| 62 | +Firmware also manages some fundamental drivers, such as keyboard driver so that you can use keyboard when no system was yet installed. |
| 63 | + |
| 64 | +> [!NOTE] |
| 65 | +> Note that extra drivers are still managed by the operating system you install. |
| 66 | +
|
| 67 | +### EFI System Partition |
| 68 | + |
| 69 | +**EFI System Partition(ESP)** is a *primary partition*(aka file system) to store critical files/executables to boot the system. |
| 70 | + |
| 71 | +- **EFI system partition**: |
| 72 | + - generally formatted as **FAT32** |
| 73 | + - has GUID `C12A7328-F81F-11D2-BA4B-00A0C93EC93B` as identifier in **GPT** |
| 74 | + |
| 75 | +> [!NOTE] |
| 76 | +> On windows you can mount EFI partition using `mountvol`, note that this is only temporarily accessible during current shell session. |
| 77 | +>```sh |
| 78 | +>mountvol z: /s # mount EFI partition to z: |
| 79 | +># now you can inspect what's inside EFI partition |
| 80 | +>mountvol z: /d # unmount z: |
| 81 | +>``` |
| 82 | +
|
| 83 | +#### How Large Should It Be? |
| 84 | +
|
| 85 | +If you inspect Windows EFI partition using the method noted above, you would find that the total is merely under 60MB for most cases. |
| 86 | +On Linux you might find it find it even smaller(probably under 30MB, depending on which bootloader you use). |
| 87 | +So it doesn't really matter much as long as you're not a cheapskate on storage, I would say 512MB is large enough to cover most system/bootloader. |
| 88 | +But that's only relevant when you only install one system on one disk, if you decided to share the same EFI partition with multiple systems, the size should be considered based on conditions. |
| 89 | +
|
| 90 | +### Firmware Boot Manager |
| 91 | +
|
| 92 | +As [UEFI specification](https://uefi.org/specs/UEFI/2.10/03_Boot_Manager.html#firmware-boot-manager) describes: |
| 93 | +
|
| 94 | +> The boot manager is a component in firmware conforming to this specification that determines which drivers and applications should be explicitly loaded and when. |
| 95 | +> Once compliant firmware is initialized, it passes control to the boot manager. |
| 96 | +> The boot manager is then responsible for determining what to load and any interactions with the user that may be required to make such a decision. |
| 97 | +
|
| 98 | +Firmware Boot Manager generally implemented by the hardware manufacturer. |
| 99 | +It is exactly the implementation of the UEFI boot menu, to manage the boot entry order, you may also manipulate the order from a system that harnesses certain UEFI interface. |
| 100 | +
|
| 101 | +### Firmware Application |
| 102 | +
|
| 103 | +If you inspect the EFI partition of you disk, you should see some `.efi` files. |
| 104 | +Those files are executable by the UEFI, more specifically, by the Firmware Boot Manager. |
| 105 | +The application can be *System Boot Manager* or *bootloader* etc. |
| 106 | +Firmware Boot Manager passes the control after launching the application. |
| 107 | +
|
| 108 | +### Firmware Boot Entries |
| 109 | +
|
| 110 | +A boot entry describes which Firmware Application to execute when UEFI triggers it. |
| 111 | +Such entries are stored in [NVRAM](https://en.wikipedia.org/wiki/Non-volatile_random-access_memory)which is managed by UEFI. |
| 112 | +
|
| 113 | +For example, on EFI partition for Windows you would find a `\EFI\Microsoft\Boot\bootmgfw.efi`, which is the *Windows Boot Manager* to be started on boot. |
| 114 | +You are able to inspect the default UEFI boot entry info object described by Windows using `bcdedit`: |
| 115 | +
|
| 116 | +```console |
| 117 | +PS> bcdedit /enum '{bootmgr}' |
| 118 | +
|
| 119 | +Windows Boot Manager |
| 120 | +-------------------- |
| 121 | +identifier {bootmgr} |
| 122 | +device partition=\Device\HarddiskVolume1 |
| 123 | +path \EFI\Microsoft\Boot\bootmgfw.efi |
| 124 | +description Windows Boot Manager |
| 125 | +locale zh-CN |
| 126 | +inherit {globalsettings} |
| 127 | +isolatedcontext Yes |
| 128 | +default {current} |
| 129 | +resumeobject {129c7077-f492-11eb-917c-f4378a725ae7} |
| 130 | +displayorder {current} |
| 131 | +toolsdisplayorder {memdiag} |
| 132 | +timeout 0 |
| 133 | +``` |
| 134 | +
|
| 135 | +> [!NOTE] |
| 136 | +> Note that *Windows Boot Manager* is listed as a special firmware application by `bcdedit`. Other applications are just simply listed as *Firmware Application* |
| 137 | +
|
| 138 | +And you should find that `{bootmgr}` is the first entry of firmware boot manager config(`{fwbootmgr}`), meaning that *Windows Boot Manager* is the first UEFI entry and `\EFI\Microsoft\Boot\bootmgfw.efi` will be launched. |
| 139 | +
|
| 140 | +```console |
| 141 | +PS> bcdedit /enum '{fwbootmgr}' |
| 142 | +
|
| 143 | +Firmware Boot Manager |
| 144 | +--------------------- |
| 145 | +identifier {fwbootmgr} |
| 146 | +displayorder {bootmgr} |
| 147 | + {e89044d4-c934-11ea-862e-806e6f6e6963} |
| 148 | + {e89044d5-c934-11ea-862e-806e6f6e6963} |
| 149 | + {e89044d6-c934-11ea-862e-806e6f6e6963} |
| 150 | +timeout 0 |
| 151 | +``` |
| 152 | +
|
| 153 | +Boot entries are managed by firmware as a **stack**, entries on top loads first, if previous one fails to boot, it **fallback** to next entry. |
| 154 | +
|
| 155 | +You can either manipulate boot entries in firmware or using specific command line utility. |
| 156 | +- Windows: `bcdedit` |
| 157 | + - can manage boot order/entries of Windows Boot Manager in `EFI/Microsoft/Boot/BCD` |
| 158 | + - can alter boot order/entries of Firmware Boot Manager in NVRAM <!-- TODO: examine it using ventoy USB drive --> |
| 159 | +- Linux: `efibootmgr` |
| 160 | + - alters firmware config in NVRAM |
| 161 | +
|
| 162 | +> [!NOTE] |
| 163 | +> You can always boot system from firmware but that requires moving up/down boot entries for each time you want to selectively boot. |
| 164 | +> This is exactly the pain point boot manager came to resolve. |
| 165 | +
|
| 166 | +### System Boot Manager |
| 167 | +
|
| 168 | +As aforementioned, *System Boot Manager* is a special kind of Firmware Application knows how to selectively and interactively enter a operating system. |
| 169 | +One EFI partition might contain multiple system boot managers, you should pick the favorite so that each time you launch the machine it will prompt to choose which system to boot. |
| 170 | +
|
| 171 | +#### Prioritize a Boot Manager |
| 172 | +
|
| 173 | +Different system can have their bootloaders in EFI partition, you can pick the favorite to use. |
| 174 | +
|
| 175 | +Windows has a `bcdedit` cli to manipulate UEFI entry order. |
| 176 | +For Windows `EFI/Microsoft/Boot/bootmgfw.efi` in EFI partition is the **Windows Boot Manager** to be recognized by UEFI. |
| 177 | +You can either override the target path of `{bootmgr}` or create a new entry object and add it to the top of `{fwbootmgr}` |
| 178 | +
|
| 179 | +::: code-group |
| 180 | +
|
| 181 | +```ps1 [Override {bootmgr}] |
| 182 | +# {bootmgr} is the identifier of boot manager entry object |
| 183 | +bcdedit /set '{bootmgr}' path \EFI\ubuntu\grubx64.efi |
| 184 | +``` |
| 185 | +
|
| 186 | +```ps1 [Add new entry] |
| 187 | +$guid = & { |
| 188 | + $null = (bcdedit /copy '{bootmgr}' /d "Ubuntu Secure Boot") -match |
| 189 | + '\{[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\}' |
| 190 | + $matches[0] |
| 191 | +} |
| 192 | +
|
| 193 | +bcdedit /set $guid path \EFI\ubuntu\grubx64.efi |
| 194 | +``` |
| 195 | +
|
| 196 | +::: |
| 197 | +
|
| 198 | +You should double check whether `{bootmgr}`/new entry is the topmost entry of firmware boot manager(`{fwbootmgr}`) |
| 199 | +
|
| 200 | +```ps1 |
| 201 | +PS> bcdedit /enum '{fwbootmgr}' |
| 202 | +
|
| 203 | +Firmware Boot Manager |
| 204 | +--------------------- |
| 205 | +identifier {fwbootmgr} |
| 206 | +displayorder {bootmgr} # [!code highlight] |
| 207 | + {e89044d4-c934-11ea-862e-806e6f6e6963} |
| 208 | + {e89044d5-c934-11ea-862e-806e6f6e6963} |
| 209 | + {e89044d6-c934-11ea-862e-806e6f6e6963} |
| 210 | +timeout 0 |
| 211 | +``` |
| 212 | +
|
| 213 | +**If not**, you should prepend it to `displayorder` of `{fwbootmgr}`. |
| 214 | +
|
| 215 | +```ps1 |
| 216 | +# prepend {bootmgr} as topmost entry of {fwbootmgr} |
| 217 | +bcdedit /set '{fwbootmgr}' displayorder '{bootmgr}' /addfirst |
| 218 | +``` |
| 219 | +
|
| 220 | +### Booting Process |
| 221 | +
|
| 222 | +1. UEFI started |
| 223 | +2. UEFI launch a bootloader(can be a boot manager) |
| 224 | +3. Initializing system kernel, mounting storages etc. |
| 225 | +
|
| 226 | +## How to Install a System |
| 227 | +
|
| 228 | +### Using Pre-installation Environment |
| 229 | +
|
0 commit comments