pmaports/main/postmarketos-mkinitfs-hook-netboot/netboot.sh
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

35 lines
936 B
Bash

#!/bin/sh
# shellcheck disable=SC1091
. ./init_functions.sh
. /usr/share/misc/source_deviceinfo
NBD_PORT=9999
NBD_BLOCK_SIZE=${deviceinfo_rootfs_image_sector_size:-512}
setup_usb_network
start_unudhcpd
show_splash "Waiting for netboot...\\nhttps://postmarketos.org/netboot"
# Attempt to load the kernel module if CONFIG_BLK_DEV_NBD=m
modprobe nbd
# Check that we actually have nbd0 available, otherwise show an error screen.
if [ ! -b /dev/nbd0 ]; then
echo "Failed to get /dev/nbd0, stopping."
show_splash "ERROR: Failed to initialise netboot\\nhttps://postmarketos.org/netboot"
fail_halt_boot
fi
client_ip="${unudhcpd_client_ip:-172.16.42.2}"
while ! busybox nbd-client "$client_ip" $NBD_PORT /dev/nbd0 -b "$NBD_BLOCK_SIZE"; do
echo "Connection attempt not successful, continuing..."
sleep 1
done
echo "Connected to $client_ip!"
# Show "Loading" splash again when continuing
show_splash "Loading..."
mount_subpartitions