Commit graph

70 commits

Author SHA1 Message Date
Caleb Connolly
672224a813
postmarketos-initramfs: probe libcomposite + make myself maintainer (MR 5328)
This won't be loaded automatically, so let's modprobe it.

Additionally, make myself maintainer to reflect CODEOWNERS

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>

[ci:skip-build] already built successfully in CI
2024-07-23 17:15:06 -07:00
jane400
59fd336bbc
main/postmarketos-initramfs: run fsck and mount sysroot as rw (MR 5238)
This moves the responsibility to auto-repair filesystems to the
initramfs. (I think we don't do this at all right now).
We don't try to mount broken partitions at all, we tell the user
that the system is broken and fail_to_boot.

The flow is now:

1. mount the boot partition (read-only) for initramfs-extra
2. initramfs-extra is extracted (with the needed fsck executables)
3. fsck the root partition
4. mount root partition (read-write)
5. fsck the boot partition
6. mount the boot partition (read-write)

This helps with the systemd bringup, as we want to make use of
systemd-firstboot, which sets /etc and enabled services up. As
this service is responsible of setting up /etc, it is run before
/etc/fstab is read and before / is remounted read-write.
2024-07-09 15:49:26 -07:00
Richard Acayan
f3b649c3c0
main/postmarketos-initramfs: invalidate cached rootfs after unlock (MR 5288)
The referenced commit had surfaced a bug with the unlocking code, which
would attempt to change the output of find_root_partition while the
cached PMOS_ROOT is stale and active. Clear this variable to force
find_root_partition to find the new rootfs value.

Fixes: 7030e08e7b ("postmarketos-initramfs: check for root subpartition (MR 5048)")
[ci:skip-build]: already built successfully in CI
2024-06-27 10:49:33 -04:00
Caleb Connolly
1b19bd7367
postmarketos-initramfs: debug-shell: buffyboard (MR 5048)
Drop the console-shell hook in favour of stuffing buffyboard into the
initramfs. This makes it possible to get a debug shell directly on the
device without needing to use a computer.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
[ci:skip-build]: already built successfully in CI
2024-06-26 17:32:33 -07:00
Caleb Connolly
abca4acbe0
postmarketos-initramfs: better wait_[br]oot_partition (MR 5048)
Rework the messages and avoid re-spawning the splash on every check.
Additionally, add a call to check_keys, this lets users drop to a debug
shell or export logs to triage this failure (particularly useful for
hard-to-reproduce issues).

Finally, add a (liberal) 30 second timeout and dump logs at the end. If
we're just waiting for a device to show up and it doesn't after 30
seconds then it's probably never going to...

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-26 17:32:33 -07:00
Caleb Connolly
7030e08e7b
postmarketos-initramfs: check for root subpartition (MR 5048)
In mount_subpartition we currently try to look for the boot partition,
to see if we're done (either we aren't using subpartitions or we found
the right one). However it is possible that a device might have
originally used the subpartition scheme, but was later converted to have
a real boot partition (for EFI for example).

In this scenario, the boot partition would be found immediately, but the
root subpartition would not be.

Address this by making mount_subpartition check for success by calling
find_root_partition instead of find_boot_partition. For most
installations this has no impact.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-26 17:32:33 -07:00
Caleb Connolly
0cd613c8b0
postmarketos-initramfs: drop duplicate in initramfs-base.files (MR 5048)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-26 17:32:33 -07:00
jane400
48250d4ad2
main/postmarketos-initramfs*: prohibit installing multiple -initramfs packages (MR 5249)
Thanks to a good hint of Craftyguy, we just have too use versioned
provides.

Closes #2903
[ci:skip-build]: already built successfully in CI
2024-06-19 10:35:30 -07:00
Clayton Craft
5fffa17b06
main/postmarketos-initramfs: explicitly depend on libinput-libs (MR 5242)
pma!5000 added a new implicit dependency on libinput, because it
specified libinput files in the initramfs file hook. mkinitfs considers
it fatal if it cannot find files listed in a file hook.

Later this could be 'optimized' by adding a -libinput subpkg and an
`install_if=libinput-libs` to add this file hook so it's not installed
everywhere... but the size increase isn't too much for UIs.. someone can
do this later.

> libinput-libs-1.26.0-r0 installed size:
> 476 KiB

This fixes a missing dependency problem where a UI (e.g. "none") doesn't
normally depend on libinput, and mkinitfs would fail because these files
were missing.
2024-06-18 14:23:29 -07:00
Caleb Connolly
7c98127746
postmarketos-initramfs: switch to udev and kmod (MR 5000)
mdev is slow and missing features, it also requires that we load all the
modules that we include at once making the boot process slower.

udev is required for unl0kr (and buffyboard), it can also load modules
on demand (and asynchronously). Making the boot process considerably
faster on devices, especially for generic images where we have lots of
drivers for different display panels in the initramfs.

Additionally, import full fat modprobe from the kmod package, this is
required to support compressed modules.

This brings us more in line with other distros and generally improves
compatibility.

If devices use broken kernel modules which don't correctly define
modalias', these drivers may not be loaded by udev. This should be fixed
by defining the missing modalias statements in the driver.

This also runs udev earlier in the init, so that display drivers are
loaded before the splash in case they are needed.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
Co-authored-by: Clayton Craft <clayton@craftyguy.net>

[ci:ignore-count]
[ci:skip-build]: already built successfully in CI
2024-06-18 12:35:05 -07:00
Caleb Connolly
dd28314ba2
postmarketos-initramfs: debug-shell 3.0 (MR 5000)
This incorprates the debug-shell functionality directly into the
initramfs, so it's no longer necessary to build and boot a custom
initramfs in order to debug your device.

Additionally, the behaviour of the debug-shell is entirely reworked, It
now creates an ACM serial gadget which can be accessed via any normal
terminal emulator (picocom, minicom, etc; or PuTTY on windows). Rather
than just invoking sh, the debug-shell now creates a respawning getty on
both the new virtual console and the active console (this will either be
the UART console or tty0/1).

It is necessary to spawn these shells via getty since the logging rework
means we can no longer assume that stdin/out/err reference a TTY.

In addition to the above, it is now possible to trigger a log dump by
holding volume up during boot. This can be useful for helping users
debug their devices if the issue doesn't result in a failure that can be
detected in the initramfs.

With these changes, the console-shell and debug-shell hook packages are
reduced to only adding the additional tools/features. console-shell is
still required for fbkeyboard, and debug-shell for the setup_usb_storage
tool.

Co-Developed-by: Clayton Craft <craftyguy@postmarketos.org>
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-18 12:35:05 -07:00
Caleb Connolly
f66238f045
postmarketos-initramfs: handle empty hooks dir (MR 5000)
For some reason globbing doesn't work properly for empty directories,
adjust the check in run_hooks to ensure the directory both exists and
contains something, otherwise we get an error about
"/hooks-cleanup/*.sh" not existing.

/ # mkdir blah
/ # for x in blah/*; do echo $x; done
blah/*
/ # touch blah/beep
/ # for x in blah/*; do echo $x; done
blah/beep

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-18 12:35:05 -07:00
Caleb Connolly
5a27482c20
postmarketos-initramfs: depend on mdevd (MR 5000)
I somehow hit a case where this wasn't installed and
/lib/mdev/persistent-storage wasn't available. Let's just explicitly
depend on mdevd...

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-18 12:35:05 -07:00
Caleb Connolly
118a30935e
postmarketos-initramfs: mount subpartitions after hooks (MR 5000)
This step is the most likely to go wrong or have issues, and it has side
effects which can make it difficult to run multiple times on one boot.
Move it to after hooks so that e.g. when dropping to a debug shell, we
land before the first call.

This also makes booting to hooks a faster in many cases.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-18 12:35:05 -07:00
Caleb Connolly
5dcb7aab62
postmarketos-initramfs: use dd to allocate logs image (MR 5000)
fallocate seems to cause some strange behaviour where the logs.img file
is treated like it's empty. Given it's small and in a ramdisk let's just
create it with dd instead.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-18 12:35:04 -07:00
Caleb Connolly
709768214c
postmarketos-initramfs: check if UDC is configured before clearing (MR 5000)
This fixes the annoying "sh: write error" and "Couldn't write to clear
UDC" messages that happen on every single boot.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-18 12:35:04 -07:00
Caleb Connolly
75613d9f69
postmarketos-initramfs: make CONFIGFS global (MR 5000)
This variable is being used in more places, just make it global.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-18 12:35:04 -07:00
Caleb Connolly
95b22138c4
postmarketos-initramfs: log to kernel ringbuffer (MR 5000)
Rework logging to always log the initramfs output to the kernel
ringbuffer and deprecate PMOS_NO_OUTPUT_REDIRECT in favour of following
the kernel loglevel.

I know it seems silly to use syslogd for this, but it's necessary to
buffer writes to /dev/kmsg per-line if we want to correctly set the log
level, and "tee" does not do this (it will write multiple lines at once,
resulting in "<14>" prints in the ringbuffer). The main advantage to
this is that we won't have kernel logs cut in half by initramfs logs
anymore, everything will be nicely line buffered!

The previous logging solution of multiple "tail" commands would actually
fail to log up to the last few lines before a crash due to how tail
works (it polls the file and buffers lines).

I attempted something like this before, but I stopped after running into
ratelimiting issues. These are now resolved by configuring the
printk_devkmsg sysctl.

Dropping PMOS_NO_OUTPUT_REDIRECT:

The general motivations behind PMOS_NO_OUTPUT_REDIRECT was to avoid
cluttering up the console with initramfs logs when they aren't wanted;
this is now handled instead by the kernels logging facility. We log to
the ringbuffer at LOGLEVEL_INFO, so if "quiet" is specified on the
cmdline (or the loglevel is otherwise set above info) then initramfs
logs will also not be shown.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-18 12:35:04 -07:00
Caleb Connolly
6c799ac4f6
postmarketos-initramfs: fork -minimal variant (MR 5000)
We plan to make a lot of changes to the initramfs which will require
incresaing the size. There are some devices that have literally no free
space for this, so make a -minimal initramfs fork that can continue to
support those while we update the regular initramfs.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-18 12:34:59 -07:00
SSD
086078ded7
main/postmarketos-initramfs: fix stowaway (MR 5206)
I have noticed a bug. Because is some cases, uuid for the boot partition is set, it won't reach logic for the stowaway.

[ci:skip-build]: already built successfully in CI
2024-06-06 11:12:48 +02:00
mae
61133a23ae
main/msm-fb-refresher: move cleanup from initramfs into msm-fb-refresher (MR 5191)
[ci:skip-build]: already built successfully in CI
2024-06-04 20:46:50 +02:00
mae
25ad7892a1
main/postmarketos-mkinitfs-hook-debug-shell: Cleanup debug-shell telnet server (MR 5191)
Moved the cleanup code from initramfs
2024-06-04 20:46:50 +02:00
mae
ebd351c346
main/postmarketos-initramfs: Allow packages to define cleanup hooks (MR 5191) 2024-06-04 18:44:34 +00:00
Pablo Correa Gómez
28e58a9cda
main/postmarketos-initramfs: update comment on why we mount /boot (MR 5089) 2024-05-16 12:02:37 +02:00
Pablo Correa Gómez
bb6d7a05b3
main/postmarketos-initramfs: add options for charset to mount vfat /boot (MR 5089)
This charset is the default and the recommended value, since boot fat
partitions should be case insensitive. linux-lts and linux-edge in
alpine use "utf-8", that might change, but add the options regardless,
so we can be safe

Fixes https://gitlab.com/postmarketOS/pmaports/-/issues/2782
2024-05-16 12:02:37 +02:00
Pablo Correa Gómez
efc7ad99e4
main/postmarketos-initramfs: add some sane mount options to /boot (MR 5089)
We won't want executables, suid executables, devices. We neither want
symbolic links in fat partitions. These have been taken from
systemd (Ref #2782)
2024-05-16 12:02:37 +02:00
SSD
089d7cc987
main/postmarketos-initramfs: stowaway rootfs (MR 4386)
[ci:skip-build]: already built successfully in CI
2024-05-09 08:32:23 -07:00
Clayton Craft
d1ad0d8713
main/postmarketos-initramfs: add crc32_generic module for F2FS (MR 4973)
Apparently f2fs has a soft dependency on this driver, so if it's =m in
the kernel then let's make sure it's always in the initramfs since f2fs
is a supported filesystem.

Fixes https://gitlab.com/postmarketOS/pmaports/-/issues/2711
[ci:skip-build]: already built successfully in CI
2024-04-18 14:44:55 +02:00
Raymond Hackley
10eb68fe05
main/postmarketos-initramfs: add USB booting support (MR 4947)
How to boot from USB drives:
1. Make sure the extcon has OTG support and included in initramfs
2. Make sure the PMIC supports the power to OTG devices, and included in initramfs. Otherwise, a hub with external power supply is required.
3. Make sure module `usb-storage` is enabled in initramfs
4. `pmbootstrap install --sdcard=/dev/<usb_drive>`
    - postmarketOS/pmbootstrap@942ee20789 is required to ignore sdcard check. Thanks @ollieparanoid for the patch.
5. `pmbootstrap flasher flash_kernel`
6. Insert the USB drive to OTG and boot

[ci:skip-build]: already built successfully in CI
2024-03-19 09:28:32 +00:00
Arnav Singh
b0226839d4
main/postmarketos-initramfs: fix starting unudhcpd when no UDC configured (MR 4907)
Reading the `ifname` of a gadget that has not been configured with a UDC
succeeds with the content `(unnamed net_device)` instead of failing.
So we need to explicitly check that a UDC was configured before we read
the interface name.

Ref: #2648
2024-03-11 13:53:17 -07:00
Caleb Connolly
a65dc9b4c0
postmarketos-initramfs: bigger log image size (MR 4880)
Sometimes, there can be more than 10M of stuff collected for logging,
which breaks things.. bump the size to 32M which should still be small
enough for low end / old devices.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-03-10 16:10:13 +00:00
xtex
160c63f12c
main/postmarketos-initramfs: allow redirect logs to pmsg device (MR 4800)
/dev/pmsg0 may be created by pstore driver. When it is available,
write logs into it so logs can be recovered through pstore after
a failed boot. This is useful for devices without console or hard
to get console.
2024-02-16 09:39:37 -08:00
Caleb Connolly
070ae7566d
main/postmarketos-initramfs: depend on mdev-conf (MR 4807)
we need this, i think it was pulled in via some dependency before.

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
2024-02-07 22:41:29 +01:00
Clayton Craft
d3ed7fe428
main/postmarketos-initramfs: don't fallback looking for /boot when given uuid or path (MR 4775)
fixes #2562

[ci:skip-build] already built successfully in CI
2024-02-06 14:24:35 -08:00
Clayton Craft
2adefeb206
main/postmarketos-initramfs: tweak msg when boot or root not found (4775) 2024-02-06 14:24:15 -08:00
Anton Bambura
d2dec46275
main/postmarketos-initramfs: wait for boot partition (MR 4775)
Some devices take time to initialize storage, e.g. Qualcomm laptops
using ADSP need to load firmware firstly, and initramfs script does
not always manage to mount boot partition in time.

Unfortunately, there is no reliable way to reproduce the issue, but
this patch should fix cases like this.
2024-02-06 14:21:15 -08:00
Arnav Singh
2a0fab1a77
main/postmarketos-initramfs: support reading USB network UDC name from deviceinfo (MR 4750)
Before this change the script assumed that the device has only one UDC.
However it is possible for a device to have multiple UDCs, in which case
the deviceinfo is the appropriate place to specify which one should be used.
This change adds an optional deviceinfo variable `deviceinfo_usb_network_udc`
to specify the UDC that should be used.

Also, before this change the script assumed the USB network interface name is
"usb0". But other gadget drivers like `g_cdc` can claim USB interfaces
before the initramfs script gets around to creating one for USB networking,
so the interface might be "usb1" or something else. The configfs gadget itself
can provide the actual interface name, so this change makes the script
use that.
2024-01-23 12:21:24 -08:00
Caleb Connolly
57744b984e
postmarketos-initramfs: export logs on boot failure (MR 4646)
Currently, when postmarketOS fails to boot up, retrieving any
information necessary to root cause the issue is non-trivial, requiring
building a custom initramfs with debug-shell enabled and then manually
copying out data.

Let's improve the situation by exporting logs automatically on boot
failure. This is safer than just exposing a root shell but still
provides a whole lot of useful info that should make duplicating and
triaging issues much easier for developers.

This commit implements the functionality and includes some generally
useful data. We then generate a README and expose files for each command/log
as well as an archive that can be easily attached to a GitLab issue.

To help with triaging, also record the version of the postmarketos-initramfs
package and hash the init.sh and init_functions.sh files.

For testing purposes, you can trigger the log recovery mode on-time by
creating an empty file named ".pmos_export_logs" in the /boot partition.

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
2024-01-05 17:29:45 +00:00
Caleb Connolly
241ade087f
postmarketos-initramfs: always save logs (MR 4646)
Always write logs to the ramdisk, adjust setup_log() to spawn "tail" to
pipe the log to the console device when PMOS_NO_OUTPUT_REDIRECT is set.

This is necessary to ensure that the initramfs logs can be extracted on
a failed boot.

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
2024-01-05 16:36:18 +00:00
Luca Weiss
2a4320e16e
main/postmarketos-mkinitfs: use NCM instead of RNDIS (MR 3670)
As described in [0] let's switch away from RNDIS and use NCM instead.

Since we cannot force all kernels to switch at the same time, let's keep
a fallback to RNDIS in the setup function.

We can also remove usb_f_rndis from modprobe as the module gets loaded
automatically when needed, but instead we need to load libcomposite
manually so that $configfs/usb_gadget gets created.

[0] https://gitlab.com/postmarketOS/pmaports/-/issues/1797

[ci:skip-build] already built successfully in CI
2023-11-20 16:33:57 -08:00
Ion Agorria
5626781fca
main/postmarketos-initramfs: Separate code into setup_usb_configfs_udc (MR 4450)
This method is called from setup_usb_network_configfs and debug shell's
setup_usb_storage.sh
2023-11-19 10:27:41 -08:00
Clayton Craft
c9c4b492e4
main/postmarketos-initramfs: show OS version on splash screen (MR 4470)
This shows the OS version (from /etc/os-release), e.g. "edge", on the splash
screen. os-release is a tiny text file, adding it to the initramfs doesn't seem
too bad, and having this information on the splash screen can be helpful.

Note that this uses "VERSION" and not "PRETTY_NAME" from the os-release file,
since the splash already shows "postmarketOS" (and the pretty name includes
that too), it seemed redundant and took up valuable display space.

[ci:skip-build]: already built successfully in CI
2023-11-02 08:44:47 +01:00
Caleb Connolly
69832ab121
postmarketos-initramfs: support running in CI (MR 4420)
Enable using the postmarketOS initramfs for boot-testing devices, in
this scenario we don't care about some components like the splash, mdev,
or subpartitions, instead we want to run full udev (to load all devices)
and then run hooks. The ci hook will deadloop after running tests.

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
2023-10-31 19:53:22 +00:00
Caleb Connolly
78762563c2
postmarketos-initramfs: use blkid (MR 4487)
Explicitly pull in the blkid package (we already added it to
00-initramfs-base.files), and replace uses of busybox findfs. Full fat
blkid supports PARTLABEL (so the /dev/disk/by-partlabel symlinks will
work consistently now), and has some nice optimisations that make the
lookup times a lot faster than busybox findfs.

[ci:skip-build]: already built successfully in CI
2023-10-23 08:10:56 +02:00
Caleb Connolly
5c6f2dd0d9
postmarketos-initramfs: fix partition cmdline priority (MR 4487)
The "pmos_[br]oot(_uuid)?" kernel cmdline args can be used to specify
how to mount the root and boot partitions. During a previous rework, the
behaviour of these was made inconsistent (becoming dependent on the
order they were specified on the cmdline).

Undo the previous "optimisation" by splitting them back out into two
FOR loops, where the _uuid variants take precedence.
2023-10-23 08:10:50 +02:00
Pablo Correa Gómez
bdaf8ef02f
main/postmarketos-initramfs: support comments in modules.load file (MR 4490)
[ci:skip-build]: already built successfully in CI
2023-10-18 15:08:21 +00:00
Pablo Correa Gómez
34e2a3ddad
main/postmarketos-initramfs: add new deviceinfo path to initramfs (MR 4283)
Reorder alphabetically while in the process, and depend on the first
mkinitfs and devicepkg-utils that implemented deviceinfo in /usr/share
2023-09-25 09:20:32 +02:00
Clayton Craft
9198a2ad6e
main/postmarketos-initramfs: upgrade to 2.0.0 (MR 4204)
Updates this package's checksums for files modified in this patch
series, and bumps the pkgver
2023-09-08 17:14:59 +02:00
Clayton Craft
20e4eb495d
main/postmarketos-initramfs: hide cryptsetup not found error (MR 4204)
Hides this error when FDE is *not* enabled, and ultimately skips the
block of logic for detecting the luks partition:
        /init: line 437: cryptsetup: not found

This error has confused some users in the past, who were reporting
issues with the initramfs.

There's probably a minor speedup on non-FDE systems as well from
bailing early.
2023-09-07 20:33:56 +01:00
Clayton Craft
cfed09ca36
main/postmarketos-initramfs: overwrite dest when extracting initramfs-extra (MR 4204)
If a file exists in the initramfs at runtime, cpio won't overwrite it
by default when extracting the initramfs-extra archive. This adds the -u
option to cpio, to overwrite any existing files in the destination.

This is meant to fix issues where the -extra archive has an app that is
meant to replace a busybox app, busybox --install creates it in the
initramfs and gzip will skip it since it's newer than what is in the
archive.
2023-09-07 20:33:56 +01:00