commit:     b2f55a479ffbb07dc0abc36660f6cc12bc63eda6
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Sat Mar 13 18:35:19 2021 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Sun Mar 14 19:33:45 2021 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=b2f55a47

linuxrc: Determine active console

Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 defaults/initrd.defaults |  1 -
 defaults/initrd.scripts  | 15 +++++++++++++++
 defaults/linuxrc         |  1 +
 3 files changed, 16 insertions(+), 1 deletion(-)

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' ]

Reply via email to