Initramfs/Development: Difference between revisions
Apollo3zehn (talk | contribs) Make link to initramfs debug shell page more visible |
|||
Line 86: | Line 86: | ||
==== No log output on serial! ==== | ==== No log output on serial! ==== | ||
By default, all output from the initramfs get redirected to <code>/pmOS_init.log</code>. If you want the output through the debug cable | By default, all output from the initramfs get redirected to <code>/pmOS_init.log</code>. If you want the output through the debug cable, make sure <code>quiet</code> is NOT on the [[Troubleshooting:kernel#How_can_I_boot_the_kernel_with_some_specific_arguments.3F | kernel command line]]. | ||
==== How do i show logs on the screen at boot? ==== | ==== How do i show logs on the screen at boot? ==== |
Revision as of 18:24, 18 June 2024
This article explains how to modify the postmarketOS initramfs scripts, for which the source can be found in the postmarketos-mkinitfs pmaport. There's another page about adding a device specific initramfs hook.
We have two initramfs files
After the installation, you will have two initramfs files in your device's /boot
folder.
% ls ~/.local/var/pmbootstrap/chroot_rootfs_samsung-i9100/boot initramfs initramfs-extra vmlinuz
Regular Linux distributions only have one initramfs file. We have split it into two to work around the size limitations that some devices have (see #126). The regular initramfs is relatively small (~1.5 mb, and we could make it smaller if necessary!) and loads the contents of the initramfs-extra from the pmOS boot partition during the boot process.
The pmOS boot partition is a subpartition of the system partition (SD cards: simply a real partition on the SD card), so we can make it almost as big as we want.
Recommended development workflow
- Only do one small change at a time
- Rebuild and test on device (
pmbootstrap initfs
,pmbootstrap flasher flash_kernel
) - When it works, version your change with git
- Repeat
When you change too much, it will simply not work and you most likely will have no idea why it does not work. Go back to the last working version and do smaller changes at a time.
Familiarize with inspecting the initramfs to learn more about available debugging options. |
Regenerating the two initramfs from the phone
You can regenerate both initramfs, even if the first is in a boot.img
by running as root
sudo mkinitfs
Tips and tricks
pmbootstrap initfs
can do more than rebuilding the initramfs:
% pmbootstrap initfs --help usage: pmbootstrap initfs [-h] {hook_ls,hook_add,hook_del,ls,build,extract} ... positional arguments: {hook_ls,hook_add,hook_del,ls,build,extract} hook_ls list available and installed hook packages hook_add add a hook package hook_del uninstall a hook package ls list initramfs contents build (re)build the initramfs extract extract the initramfs to a temporary folder optional arguments: -h, --help show this help message and exit
- Arbitrary files can be included from an
APKBUILD
by installing them to/usr/share/mkinitfs{-extra}/files
:
APKBUILD
:
package() { # ... install -Dm644 "$srcdir/30-my-custom-files.files" "$pkgdir/usr/share/mkinitfs/files/30-my-custom-files.files" }
30-my-custom-files.files
:
/lib/firmware/postmarketos/necessary-firmware.fw /lib/libnecessaryfirmware.so
WARNING: As of 2023-08-25, mkinitfs has a bug where if blank lines exist in any of these files, the initramfs will come out completely empty. |
Manual unpacking and repacking the initramfs file
$ zcat initfs.gz | sudo cpio -iv --make-directories # unpacks
$ find . | sudo cpio -ov --format=newc | gzip -c -1 > initfs-new.gz # packs; I've tested - this works. --format=newc is important!
Another way of unpacking
$ gzip -d initramfs.gz
$ sudo cpio -iv --file=initramfs
Troubleshooting
My device reboots with my customized init script
This is probably caused by a syntax error. Use shellcheck
to check your scripts for syntax errors. You could also loop forever or spawn a shell (if you have a hardware keyboard or serial cable connected) at some point for debugging (while true; do sleep 1; done
) and use the telnet shell to test the commands, that are failing, interactively.
No log output on serial!
By default, all output from the initramfs get redirected to /pmOS_init.log
. If you want the output through the debug cable, make sure quiet
is NOT on the kernel command line.
How do i show logs on the screen at boot?
In order to disable the postmarketOS splash add PMOS_NOSPLASH
to your kernel command line, in addition if you want the kernel logs to print to the screen make sure that console=tty0
is set in the kernel command line.