Commit graph

49 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
Caleb Connolly
9fb29079cd
main/postmarketos-initramfs: get to splash faster (MR 4204)
With full-fat mdev supporting by-partlabel lookups, there is a small
delay during startup. As mdev and dynamic partitions aren't actually
needed for the framebuffer device, move show_splash earlier.

Furthermore, slightly rework setup_framebuffer to not dump the verbose
message about waiting for the framebuffer unless the framebuffer isn't
found.

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
2023-09-07 20:33:56 +01:00
Clayton Craft
97727c59cb
main/postmarketos-initramfs: use only one method to resize the root partition (MR 4204)
This removes the possibility that multiple resize root partition methods
could be invoked. I'm not sure how likely this is in practice, but it
seems like we should avoid the possiblity altogether.

This also adds some more helpful printing to stdout when the partition
resize is skipped / not done.
2023-09-07 20:33:56 +01:00
Caleb Connolly
6f44124c1b
main/postmarketos-initramfs: fixup device-mapper paths (MR 4204)
findfs might produce a block device path like /dev/dm-3, these can
change across boots and devices. Make things more readable and
consistent by mapping from the /dev/dm-* path to the equivalent
/dev/mapper/xyz path. Combined with invoking kpartx from a
/dev/disk/by-partlabel/abc symlink, this results in the final block
device having a name like /dev/mapper/userdata2 on an Android device.

Whilst this is just nicer to work with, this will be especially useful for
the upcoming ondev2 postmarketOS installer to make device-specific
configuration and detection easier.
2023-09-07 20:33:56 +01:00
Caleb Connolly
89fba12fbb
main/postmarketos-initramfs: optimise find_*_partition (MR 4204)
Save the root/boot partition paths once found, and optimise a few loops.

Additionally, fall-back to other search methods when the pmos_boot or
pmos_uuid_boot cmdline args are set but fail.

Co-authored-by: Clayton Craft <clayton@craftyguy.net>
2023-09-07 20:33:55 +01:00
Caleb Connolly
e0fcfb74e2
main/postmarketos-initramfs: use mdev properly (MR 4204)
Drop in mdev.conf and the /lib/mdev/persistent-storage script, these
cause /dev/disk/by-* to be populated in the ramdisk, making it
possible to do look up partition by-label and by-partlabel for free,
compared to findfs which can take some time.

As a first optimisation based on this, check for some partitions using
these paths and prioritise them when looking for subpartitions. Drop the
first find_boot_partition call as it doesn't really save time over the
call in the while loop.

The mdev config also handles setting up /dev/null, /dev/random, etc, so
these don't have to be done manually.
2023-09-07 20:33:55 +01:00
Caleb Connolly
73e05bf16d
main/postmarketos-initramfs: silence pbsplash (MR 4204) 2023-09-07 20:33:55 +01:00
Luca Weiss
5f820deefc
main/postmarketos-initramfs: switch_root with /dev (MR 3230) (MR 4204)
Mount /dev (and /run) in initramfs so util-linux switch_root can move
the mounts over to the new sysroot before changing root.
BusyBox switch_root doesn't even attempt to move anything so use
util-linux's switch_root for this.

Explicitly disable tests too...
2023-09-07 20:33:55 +01:00
bademux
80fff9242a
main/postmarketos-initramfs: support custom IP addresses for USB net (MR 3349)
[ci:skip-build] already built successfully in CI
2023-08-23 13:06:15 -07:00
Johannes Marbach
202b6e9435
main/postmarketos-initramfs: wait for splash to exit before unlocking (MR 3952)
[ci:skip-build]: already built successfully in CI
2023-08-08 09:36:17 +02:00
Steven Davies
1e4c8238c3
postmarketos-initramfs: Handle rootfsopts= on kernel cmdline (MR 4288)
This also removes redundant code and handles mount failure/no filesystem
separately.

fixes #2242
2023-08-02 11:33:47 -07:00
Pablo Correa Gómez
38ce112cdf
main/postmarketos-initramfs: load modules also from /lib/modules/initramfs.load (MR 4193)
Make it possible to load modules from the file installed by devicepkg-dev,
that will be there when extra modules are needed. This is coded in a
backwards-compatible way, so that it can be independent of the main modules
MR.

The code changes create a new function which takes a list of modules
and possibly a file (that should contain a list of modules too). The
idea is to be able to support also loading modules for initramfs-extra
in the future, and having a similar file would be more convenient than
extracting all the modules each time. In addition, the "[ -d /lib/modules]"
check has been removed. If there's no modules directory, as all
modules might be built-in, modprobe will fail, but that will not be
fatal. This will most likely only exclusively happen in some android
downstream kernel, so it should not be a big concern.
2023-07-10 11:07:51 -07:00
Newbyte
881dbc6a22
main/postmarketos-initramfs: use source_deviceinfo from devicepkg-utils (MR 4129)
See https://gitlab.com/postmarketOS/pmaports/-/issues/2086
2023-06-03 17:44:24 +02:00
Pablo Correa Gómez
b26ba8784c
main/postmarketos-initramfs: add function to source deviceinfo (MR 4037)
As a preparation for #1836, move the sourcing of deviceinfo to its own
function. This should allow to have a single point in the whole of the
initramfs for the sourcing of the deviceinfo, instead of every script
that needs it sourcing it. This allows to change the way deviceinfo is
sourced in the future with a lot less effort.
2023-04-26 18:13:52 +02:00
Caleb Connolly
e74ac08673
main/postmarketos-initramfs: fix splash newline (MR 3930)
POSIX sh dictates that newlines in strings are, newlines, so use printf
to format the splash strings and replace the "\\n" with an actual
newline.
2023-03-18 23:45:32 +00:00
Clayton Craft
82c02ea325
main/postmarketos-initramfs: support initramfs-extra as gzip (MR 3948)
This is a revert of the change introduced in 4eda0715 to support an
uncompressed initramfs-extra. osk-sdl support results in an initramfs-extra
that is too big for some devices with a small (traditional) /boot partition

Also see: https://gitlab.com/postmarketOS/pmaports/-/issues/2009

[ci:skip-build]: Already built successfully in CI
2023-03-12 19:36:49 +01:00
Clayton Craft
536264bac0
main/postmarketos-initramfs: new aport (MR 3895)
This package contains base file and module lists for the initramfs /
initramfs-extra archives, along with the init.sh

The primary reason for doing this is so that changes to these
files/lists can be properly versioned (in pkgver), and (re)building
mkinitfs itself is no longer required for these changes.

- Add base file list for initramfs. The dirs at path
  /usr/share/postmarketos-mkinitfs/* are "new" in mkinitfs 2.0

- Install default modules to /usr/share

- Install system config to /usr/share/mkinifs

- Add base files for -extra archive

- Create user config dirs

- Update hook dirs in init.sh, change from mkinitfs 2.0

- Remove splash images, obsolete since pbsplash

- Support uncompressed initramfs-extra
2023-03-08 21:34:37 -08:00