aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Deutschmann <whissi@gentoo.org>2021-03-13 19:35:19 +0100
committerThomas Deutschmann <whissi@gentoo.org>2021-03-14 20:33:45 +0100
commitb2f55a479ffbb07dc0abc36660f6cc12bc63eda6 (patch)
tree3937819c3d41e4e923a55192603d9df855976aab
parentinitrd.scripts: run_shell(): Reformat exec code (diff)
downloadgenkernel-b2f55a479ffbb07dc0abc36660f6cc12bc63eda6.tar.gz
genkernel-b2f55a479ffbb07dc0abc36660f6cc12bc63eda6.tar.bz2
genkernel-b2f55a479ffbb07dc0abc36660f6cc12bc63eda6.zip
linuxrc: Determine active console
Signed-off-by: Thomas Deutschmann <whissi@gentoo.org>
-rw-r--r--defaults/initrd.defaults1
-rw-r--r--defaults/initrd.scripts15
-rw-r--r--defaults/linuxrc1
3 files changed, 16 insertions, 1 deletions
diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults
index 7ee78e9..c9e956a 100644
--- a/defaults/initrd.defaults
+++ b/defaults/initrd.defaults
@@ -56,7 +56,6 @@ ROOT_LINKS='bin sbin lib lib32 lib64 boot usr opt emul'
ROOT_TREES='etc root home var'
REAL_ROOT=''
-CONSOLE='/dev/console'
NEW_ROOT='/newroot'
no_umounts='/newroot|/mnt/aufs-dev|/mnt/aufs-rw-branch|/mnt/livecd|/mnt/cdrom|/.unions/memory|/.unions/memory/xino'
ROOTDELAY=5
diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index c133282..505ca02 100644
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -2722,6 +2722,21 @@ setup_unionfs() {
fi
}
+get_active_console() {
+ local active_console=console
+
+ while [ -f /sys/class/tty/${active_console}/active ]
+ do
+ active_console=$(cat /sys/class/tty/${active_console}/active)
+
+ # last console will be the active one,
+ # see https://www.kernel.org/doc/html/latest/admin-guide/serial-console.html
+ active_console=${active_console##* }
+ done
+
+ echo ${active_console}
+}
+
get_mounts_list() {
awk '
/^[[:blank:]]*#/ { next }
diff --git a/defaults/linuxrc b/defaults/linuxrc
index f20d606..37a8dfa 100644
--- a/defaults/linuxrc
+++ b/defaults/linuxrc
@@ -21,6 +21,7 @@
[ ! -e /dev/zero ] && mknod /dev/zero c 1 5
# Take control
+CONSOLE="/dev/$(get_active_console)"
exec 0<>${CONSOLE} 1<>${CONSOLE} 2<>${CONSOLE}
if [ "$$" != '1' ]