From e2ca64a2556a22b1170049dbcf88e3ab78f74e02 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Sun, 3 Sep 2023 19:35:01 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E5=AE=8C=E5=96=84=20tty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- redhat.cfg | 18 ++---------------- reinstall.sh | 12 +++++++++++- trans.sh | 24 +++++++++--------------- ttys.sh | 32 ++++++++++++++++++++++++-------- 4 files changed, 46 insertions(+), 40 deletions(-) diff --git a/redhat.cfg b/redhat.cfg index aacb6c0..7df818e 100644 --- a/redhat.cfg +++ b/redhat.cfg @@ -46,22 +46,8 @@ done # 设置 tty include=/tmp/include-bootloader -str= -for tty in tty0 ttyS0 ttyAMA0; do - dev_tty=/dev/$tty - if [ -e $dev_tty ] && echo >$dev_tty 2>/dev/null; then - if [ -z "$str" ]; then - str="console=$tty" - else - str="$str console=$tty" - fi - fi -done -if [ -n "$str" ]; then - echo "bootloader --append=\"$str\"" >$include -else - echo "bootloader" >$include -fi +console_cmdline=$(wget $confhome/ttys.sh -O- | sh -s console=) +echo "bootloader --append=\"$console_cmdline\"" >$include # 有 installer 分区,表示用了两步安装 include=/tmp/include-packages-for-resize diff --git a/reinstall.sh b/reinstall.sh index f70abe0..2417c13 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -882,6 +882,16 @@ build_extra_cmdline() { fi } +echo_tmp_ttys() { + # 由于 windows 下无法测试各tty是否有效 + # 这里的 tty 只临时使用,非最终系统的 tty + if is_in_windows; then + echo "console=ttyS0,115200n8 console=tty0" + else + curl -L $confhome/ttys.sh | sh -s "console=" + fi +} + # shellcheck disable=SC2154 build_cmdline() { if [ -n "$finalos_cmdline" ]; then @@ -1064,7 +1074,7 @@ menuentry "reinstall" { insmod lvm insmod xfs search --no-floppy --file --set=root /reinstall-vmlinuz - linux$efi /reinstall-vmlinuz $cmdline + linux$efi /reinstall-vmlinuz $(echo_tmp_ttys) $cmdline initrd$efi /reinstall-initrd } EOF diff --git a/trans.sh b/trans.sh index 44b76cc..2775cdf 100644 --- a/trans.sh +++ b/trans.sh @@ -141,20 +141,12 @@ setup_lighttpd() { rc-service lighttpd start } +# 最后一个 tty 是主tty,显示的信息最多 +# 有些平台例如 aws/gcp 只能截图,不能输入(没有鼠标) +# 所以如果有显示器且有鼠标,tty0 放最后面,否则 tty0 放前面 get_ttys() { prefix=$1 - str= - for tty in tty0 ttyS0 ttyAMA0; do - dev_tty=/dev/$tty - if [ -e $dev_tty ] && echo >$dev_tty 2>/dev/null; then - if [ -z "$str" ]; then - str="$prefix$tty" - else - str="$str $prefix$tty" - fi - fi - done - echo $str + wget $confhome/ttys.sh -O- | sh -s $prefix } setup_tty_and_log() { @@ -390,9 +382,9 @@ EOF # 如果是 vm 就用 virt 内核 if is_virt; then - kernel_opt="-k virt" + kernel_flavor="virt" else - kernel_opt="-k lts" + kernel_flavor="lts" fi # 重置为官方仓库配置 @@ -405,8 +397,10 @@ EOF # 安装到硬盘 # alpine默认使用 syslinux (efi 环境除外),这里强制使用 grub,方便用脚本再次重装 + KERNELOPTS="$(get_ttys console=)" + export KERNELOPTS export BOOTLOADER="grub" - printf 'y' | setup-disk -m sys $kernel_opt -s 0 /dev/$xda + printf 'y' | setup-disk -m sys -k $kernel_flavor -s 0 /dev/$xda } # shellcheck disable=SC2154 diff --git a/ttys.sh b/ttys.sh index ab572ac..d9f75c0 100644 --- a/ttys.sh +++ b/ttys.sh @@ -1,13 +1,29 @@ #!/bin/sh prefix=$1 -for tty in tty0 ttyS0 ttyAMA0; do - dev_tty=/dev/$tty - if [ -e $dev_tty ] && echo >$dev_tty 2>/dev/null; then - if [ -z "$str" ]; then - str="$prefix$tty" - else - str="$str $prefix$tty" + +# 最后一个 tty 是主 tty,显示的信息最全 +# 有些平台例如 aws/gcp 后台vnc只能截图,不能输入,用有没有鼠标判断 +# 因此如果有显示器且有鼠标,tty0 放最后面,否则 tty0 放前面 +ttys="ttyS0 ttyAMA0" +if [ -e /dev/fb0 ] && [ -e /dev/input/mouse0 ]; then + ttys="$ttys tty0" +else + ttys="tty0 $ttys" +fi + +is_first=true +for tty in $ttys; do + if [ -e /dev/$tty ] && echo >/dev/$tty 2>/dev/null; then + if ! $is_first; then + printf " " + fi + + is_first=false + + printf "%s" "$prefix$tty" + + if [ "$prefix" = "console=" ] && [ "$tty" = ttyS0 ]; then + printf ",115200n8" fi fi done -echo $str