Boot process: Difference between revisions
Line 11: | Line 11: | ||
== Early boot process == | == Early boot process == | ||
In the Early boot process, Device specific bootloaders would boot up.After that it would boot the os in different variant of way. (See Below) | In the Early boot process, Device specific bootloaders would boot up.After that it would boot the os in different variant of way. (See Below) | ||
See | See [[:Category:Bootloaders]] for learn more about how different bootloader work. | ||
=== UEFI === | === UEFI === | ||
On device that support UEFI , pmOS would boot via systemd-boot | On device that support UEFI , pmOS would boot via systemd-boot | ||
Line 18: | Line 18: | ||
==== isorec ==== | ==== isorec ==== | ||
Very few Android devices don't expect a <code>boot.img</code> file written to the Android boot partition, but rather just the Linux kernel, with an embedded initramfs. But we want the initramfs packaging to be independent of the kernel (not require a kernel rebuild to change the initramfs!). Therefore we use the so-called "isorec" trick here: the initramfs script built into the kernel is just a very small stub, that loads the real initramfs from the postmarketOS boot partition ([https://gitlab.com/postmarketOS/pmaports/-/blob/1d2b62a1094e77e50e1a52c48b07eecb1fbfd26a/device/testing/linux-samsung-i9100/APKBUILD#L31-50 example]). | Very few Android devices don't expect a <code>boot.img</code> file written to the Android boot partition, but rather just the Linux kernel, with an embedded initramfs. But we want the initramfs packaging to be independent of the kernel (not require a kernel rebuild to change the initramfs!). Therefore we use the so-called "isorec" trick here: the initramfs script built into the kernel is just a very small stub, that loads the real initramfs from the postmarketOS boot partition ([https://gitlab.com/postmarketOS/pmaports/-/blob/1d2b62a1094e77e50e1a52c48b07eecb1fbfd26a/device/testing/linux-samsung-i9100/APKBUILD#L31-50 example]). | ||
== postmarketOS initramfs == | == postmarketOS initramfs == |
Revision as of 11:37, 26 September 2024
Overview
Once you press the power button on your device with a postmarketOS installation, it goes through the following steps:
- Device specific bootloaders
- postmarketOS initramfs
- Init
- Display manager (if UI is not none, otherwise it stops at getty )
- User Interface of choice (Plasma Mobile, Phosh, ...)
Early boot process
In the Early boot process, Device specific bootloaders would boot up.After that it would boot the os in different variant of way. (See Below) See Category:Bootloaders for learn more about how different bootloader work.
UEFI
On device that support UEFI , pmOS would boot via systemd-boot
Andorid boot image
On most Andorid device , the bootloader on that device would boot the android image that is in the partition that labeled at boot
.that file contain initramfs and kerenl.pmOS would put its initramfs and kerenl into a Andorid boot image and flash it to the partition.However there are some android device that dont support andorid boot image.
isorec
Very few Android devices don't expect a boot.img
file written to the Android boot partition, but rather just the Linux kernel, with an embedded initramfs. But we want the initramfs packaging to be independent of the kernel (not require a kernel rebuild to change the initramfs!). Therefore we use the so-called "isorec" trick here: the initramfs script built into the kernel is just a very small stub, that loads the real initramfs from the postmarketOS boot partition (example).
postmarketOS initramfs
The postmarketOS initramfs consists of busybox, a shell script and very few other command-line programs.
postmarketos-mkinitfs generates the initramfs .
After then , postmarketos-mkinitfs would run boot-deploy and boot-deploy would pack kernel and initramfs into a suitable format and generate config for the bootloader if necessary.
The initramfs takes care of many things during the early booting phase, such as setting up USB networking, resizing the root partition, displaying a charging UI. Some of the tasks are listed in detail here, for others refer to the source code for now and consider expanding this article. Furthermore, the initramfs supports hooks (which may be used to work around device specific quirks, for example).
Here is a list of the boot process related to initramfs:
- Enable
set -x
if the verbose-initfs hook exists - Load deviceinfo data
- Create busybox symlinks
- Mount
/dev
,/proc
and/sys
- Redirect stdout to
/pmOS_init.log
and to the kernel log (dmesg) - Modprobe modules listed in deviceinfo
- Enable mdev (busybox replacement for udev)
- Map subpartitions to block device
- Wait for /dev/fb0 to appear (if not disabled in deviceinfo) and set the framebuffer mode
- Execute hooks
- Show loading splash
- Start usb networking
- Find and mount the partition with the
pmOS_boot
label if not show "Boot partition not found" splash - Unpack initramfs-extra from the boot partition if not show "Initramfs-extra not found" splash
- Search for a partition with the label
pmOS_root
- Try to resize the partition containing the root filesystem to the maximum size
- Start Unl0kr if the rootfs is a luks partition
- Resize the root filesystem to match the partition it is in
- Mount the root filesystem
- Kill all processes running in the initramfs and pivot root to the real rootfs
Find the boot and root partitions
Due to the various possible partition layouts, the initramfs script has to look in various places for the postmarketOS boot and root partitions.
boot partition:
pmos_boot
kernel parameter (from the device specific bootloader)- Any partition or subpartition with the
pmOS_boot
label
root partition:
pmos_root
kernel parameter (from the device specific bootloader)- Any partition or subpartition with the
pmOS_root
label - Any partition or subpartition that is encrypted
Load initramfs-extra
Some Android devices require a very small initramfs, because otherwise the resulting boot.img
file is too big for the Android boot partition. Therefore, we have split the initramfs into two parts, the tiny initramfs that is potentially placed in such a boot.img
file (depending on the bootloader). And the initramfs-extra, which can hold bigger binaries, such as the UI to unlock an encrypted root partition (Unl0kr).
Switch root
It will look like this, once pmaports#664 is resolved. |
At the end of the initramfs script, the root partition is mounted at /sysroot
, and the boot partition is mounted at /sysroot/boot
. The latter is done, so Init does not need to figure out the correct boot partition later on. Afterwards, the busybox command switch_root
is called to switch over and pass control to Init.
See also
- Inspecting_the_initramfs
- Partition Layout
- Category:Bootloaders
- Troubleshooting:boot
- Troubleshooting:boot:initfshooks
- pmaports#664: two postmarketOS installations: OpenRC may mount wrong partition as /boot
- postmarketOS low-level blog post (talks in part about liberating bootloaders)
- Deviceinfo: flash methods