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>
This commit is contained in:
Caleb Connolly 2023-12-18 23:50:56 +00:00
parent 190860eb5f
commit 241ade087f
No known key found for this signature in database
GPG key ID: 7930459FB9303217

View file

@ -7,20 +7,26 @@ PMOS_ROOT=""
# Redirect stdout and stderr to logfile
setup_log() {
# Bail out if PMOS_NO_OUTPUT_REDIRECT is set
local log_to_console=""
grep -q PMOS_NO_OUTPUT_REDIRECT /proc/cmdline && log_to_console="true"
echo "### postmarketOS initramfs ###"
grep -q PMOS_NO_OUTPUT_REDIRECT /proc/cmdline && return
# Print a message about what is going on to the normal output
echo "NOTE: All output from the initramfs gets redirected to:"
echo "/pmOS_init.log"
echo "If you want to disable this behavior (e.g. because you're"
echo "debugging over serial), please add this to your kernel"
echo "command line: PMOS_NO_OUTPUT_REDIRECT"
if [ -z "$log_to_console" ]; then
echo "Add PMOS_NO_OUTPUT_REDIRECT to your kernel command line"
echo "to enable initramfs logging to console (e.g. for serial)."
fi
# Start redirect, print the first line again
# Start redirect
exec >/pmOS_init.log 2>&1
echo "### postmarketOS initramfs ###"
# Pipe logs to console if PMOS_NO_OUTPUT_REDIRECT is set
if [ -n "$log_to_console" ]; then
tail -f /pmOS_init.log > /dev/console &
return
fi
}
mount_proc_sys_dev() {