Skip to content

Commit 5fd251b

Browse files
committed
main
1 parent c2b8b3e commit 5fd251b

File tree

3 files changed

+287
-16
lines changed

3 files changed

+287
-16
lines changed
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
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+

docs/document/Articles/docs/Setup nix-on-droid.md

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,71 @@
55
- Root privilege on you android phone(it's not stable in devices without root)
66
- nix-on-droid installed.
77
- Optional: `adb`, `pwsh`
8-
You can use `adb` to type inputs from your computer connected with your android device.
8+
You can use `adb` to type inputs from your computer connected with your android device.
99
The following powershell function solves the escape problem of `adb shell input text`, so you don't have to escape manually.
1010
```ps1
1111
# Use -Enter to press enter after command input
12-
function adbin([string]$Str, [switch]$Enter) {
13-
$special = @( ' ', '\|', '\$', '&', '\(', '\)', '~','\*', "\'",'"','<','>')
14-
foreach ($char in $special) {
15-
$Str = $Str -replace $char, ($char.Length -gt 1 ? $char : "\$char")
12+
<#
13+
This script helps to input text for terminal like Termux on Android
14+
It may not function on input scenarios other than shell on Android
15+
It DOES NOT start shell on Android but simulate key press to input text.
16+
NOTE: if default port fails, try another port
17+
#>
18+
function Send-AdbShellInput {
19+
param(
20+
[Parameter(Mandatory)]
21+
[string]$InputText,
22+
[ushort]$Port = 5037,
23+
[string]$SerialNumber,
24+
[switch]$AcceptLine
25+
)
26+
27+
begin {
28+
& ./Assert-AdbServer.ps1 @PSBoundParameters
29+
30+
if (-not $SerialNumber) {
31+
$flags = @('-P', $Port)
32+
} else {
33+
$flags = @('-P', $Port, '-s', $SerialNumber)
34+
}
35+
36+
$specials = @'
37+
|$%;\&~*'"`<>()
38+
'@
39+
1640
}
17-
adb shell input text $Str
18-
if ($Enter) {
19-
adb shell input keyevent KEYCODE_ENTER
41+
42+
end {
43+
$InputText = $InputText -replace "[$([regex]::Escape($specials))]", '\$0'
44+
$InputText = $InputText -replace ' ', '%s'
45+
46+
adb @flags shell input text $InputText
47+
48+
if ($AcceptLine) {
49+
adb @flags shell input keyevent KEYCODE_ENTER
50+
}
2051
}
2152
}
53+
2254
```
2355
> [!NOTE]
2456
> You can wrap the same as bash function by `awk` or other text manipulation tools.
2557
2658
## Init
2759
28-
- nix-on-droid may ask for url for certain file, if the url is not accessible on your phone, download it and transfer to your phone. And replace the default url as `file:///sdcard/...`
60+
1. `nix-on-droid` may ask for url for certain file, if the url is not accessible on your phone, download it and transfer to your phone. And replace the default url as `file:///sdcard/...`
2961
> remember to allow file permision for nix-on-droid.
30-
- type `yes` when nix prompt for downloads for first init.
31-
- add and update channels:
62+
2. Type `yes` when nix prompt for downloads for first init.
63+
3. Add and update channels:
3264
```sh
3365
nix-channel --add https://nixos.org/channels/nixos-unstable nixpkgs && nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager && nix-channel --update
3466
```
3567
> [!TIP]
36-
> If you use the wrapper function mentioned above, would be like this:
68+
> If you use the wrapper function mentioned above, would much easier to input:
3769
>```ps1
38-
>adbin -Enter 'nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz home-manager'
70+
>Send-AdbShellInput -InputText 'nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz home-manager' -AcceptLine
3971
>```
40-
- Update nix: default nix is out-dated, might not work with your current config like home-manager or any other.
72+
4. Update `nix` cli: default nix is out-dated, might not work with your current config like home-manager.
4173
```sh
4274
nix profile install nixpkgs#nix --priority 4
4375
```
@@ -69,9 +101,9 @@ mkdir -p ~/.ssh/ && touch ~/.ssh/authorized_keys && echo <pub> >> ~/.ssh/authori
69101
```
70102

71103
> [!TIP]
72-
> Use this instead if you prefer pwsh, replace the pubkey name if needed.
104+
> Use this instead if you prefer pwsh wrapper function above, replace the pubkey name if necessary.
73105
>```ps1
74-
>adbin -Enter ('mkdir -p ~/.ssh/ && touch ~/.ssh/authorized_keys && echo ''{0}'' >> ~/.ssh/authorized_keys' -f (gc ~/.ssh/id_ed25519.pub))
106+
>Send-AdbShellInput -InputText ('mkdir -p ~/.ssh/ && touch ~/.ssh/authorized_keys && echo ''{0}'' >> ~/.ssh/authorized_keys' -f (gc ~/.ssh/id_ed25519.pub)) -AcceptLine
75107
>```
76108
77109
- start ssh daemon by `sshd`

docs/document/Skill/Git/docs/Submodule.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,13 @@ git submodule add <repository_url> <path_to_submodule>
1010
```
1111

1212
Details of submodules can be inspected from `.gitmodules`
13+
14+
## Remove Submodule
15+
16+
```sh
17+
git rm path/to/submodule
18+
```
19+
20+
This deletes both physical storage of the submodule and its info in `.gitmodules`.
21+
Note that its history would still be reserved in case you wanted to inspect the old commits.
22+
You can manually delete it from `.git/modules/<submodule>` if you want to wipe out completely.

0 commit comments

Comments
 (0)