Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mdhorn/3ca3afbdd79bbf9f5ec652f411b4f11a to your computer and use it in GitHub Desktop.
Save mdhorn/3ca3afbdd79bbf9f5ec652f411b4f11a to your computer and use it in GitHub Desktop.
From 1ea966fb315d99f33922ab1d8856f3708ba56663 Mon Sep 17 00:00:00 2001
From: Mark D Horn <mark.d.horn@intel.com>
Date: Tue, 26 May 2020 18:42:01 -0700
Subject: [PATCH] iso: Find usable tty for output
Signed-off-by: Mark D Horn <mark.d.horn@intel.com>
---
iso_templates/initrd_init_template | 42 +++++++++++++++++++++---------
1 file changed, 30 insertions(+), 12 deletions(-)
diff --git a/iso_templates/initrd_init_template b/iso_templates/initrd_init_template
index 5e15cfbb6663..5f49e119cf7f 100644
--- a/iso_templates/initrd_init_template
+++ b/iso_templates/initrd_init_template
@@ -8,14 +8,36 @@ WARNING="\\033[1;33m" # yellow
FAILURE="\\033[1;31m" # red
INFO="\\033[1;36m" # light cyan
+TTY_DEFAULT="/dev/console"
+TTYS="/dev/console /dev/tty0 /dev/ttyS0 /dev/tty1 /dev/ttyS1 /dev/tty2 /dev/ttyS2"
+TTY="${TTY_DEFAULT}"
+
+discover_tty() {
+ found=0
+ for tty in ${TTYS}
+ do
+ echo -e "" >> "${tty}" 2>/dev/null
+ if [ "$?" -eq 0 ] ; then
+ TTY="${tty}"
+ found=1
+ break
+ fi
+ done
+
+ if [ "${found}" -eq 1 ] ; then
+ echo_tty_kmsg "${INFO}Using ${TTY} for output${NORMAL}"
+ else
+ TTY="${TTY_DEFAULT}"
+ echo_tty_kmsg "${FAILURE}Defaulting to ${TTY} for output${NORMAL}"
+ fi
+}
+
# Prints msg to TTY and kmsg, stripping color codes for kmsg
# This echos twice - once for tty0 and once on kmsg for all others
# $1 - Message string to print
# Explicitly send boot messages to tty0, /dev/console is ttyS0
echo_tty_kmsg() {
- echo -e "$1" > /dev/tty0
- # This is required for messages to be seen while using qemu
- echo -e "$1" > /dev/ttyS0
+ echo -e "$1" > "${TTY}"
echo -e "$1" | sed 's/\x1b\[[0-9;]*m//g' > /dev/kmsg
}
@@ -107,12 +129,7 @@ mount_root() {
}
wait_for_keystrokes() {
- while [ true ] ; do
- read -t 2 -n 1
- if [ "$?" = 0 ] ; then
- break
- fi
- done
+ read -n 1
}
check_iso_verify() {
@@ -128,12 +145,11 @@ verify_media() {
local need="ISO integrity check"
if [ -n "${installer}" ]; then
- checkisomd5 --verbose ${installer}
+ checkisomd5 --verbose ${installer} |& tee -a "${TTY}"
+ check_iso_verify "${PIPESTATUS[0]}" "$need"
else
shell_trap "[${FAILURE} FAIL ${NORMAL}] Failed to verify installer media, failed to boot Clear Linux*."
fi
-
- check_iso_verify "$?" "$need"
}
# Finds the installer media
@@ -197,6 +213,8 @@ main() {
mount -t devtmpfs none /dev
mount -t tmpfs none /run
+ discover_tty
+
# Verify CPU features needed to run Clear exist
echo_tty_kmsg "Checking if system is capable of running Clear Linux*..."
have_64bit_cpu
--
2.26.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment