在启动时启用串行控制台

来自 Alpine Linux

Syslinux / Extlinux

如何在启动时启用串行控制台 (1.10.x)

当使用 syslinux 启动时,您需要修改启动设备的根目录下的 syslinux.cfg 文件。如果使用基于磁盘的 Alpine,请修改 /boot/extlinux.cfg 文件。

添加以下内容

  • serial 0 9600
  • 添加console=ttyS0,9600append参数
  • 可选地,移除quietappend参数

syslinux.cfg 示例

serial 0 9600
timeout 20
prompt 1
default grsec
label grsec
        kernel /boot/grsec
        append initrd=/boot/grsec.gz alpine_dev=sda1:vfat modules=sd-mod,usb-storage console=ttyS0,9600


extlinux.conf (3.0+)

/etc/update-extlinux.conf 由 update-extlinux 实用程序读取。

要这样做,请更改默认条目

default_kernel_opts="quiet"

使其看起来像这样

default_kernel_opts="console=ttyS0,9600 quiet"

设置串行端口和波特率以匹配上面的 default_kernel_opts 行

serial_port=0
serial_baud=9600

Xen

请注意,如果您想将此用于 Xen VM,则需要将速度配置为 115200 bps 并启用

serial="pty"

VM 配置文件中的设置。


可以通过编辑 /etc/update-extlinux.conf 以包含以下行来配置 Xen 以使用串行控制台并记录到串行控制台

default_kernel_opts="console=hvc0 earlyprintk=xen nomodeset"
xen_opts="dom0_mem=256M com1=115200,8n1 console=com1"

有关更多详细信息,请参阅 Xen wiki

qemu

与 Xen 类似,qemu 应该以 115200 的速度运行。

方便的是,alpine “virt” 镜像(但不是“standard”镜像)在默认 ISO 上配置了所有这些。

在 alpine-virt 上使用串行控制台运行 qemu 的示例命令

qemu-system-x86_64 -accel kvm -cdrom alpine-virt-3.16.0-x86_64.iso -display none -chardev stdio,id=char0,logfile=serial.log,signal=off -serial chardev:char0

请注意,此示例命令使用 logfile 选项来记录串行控制台的输出;如果不需要,您可以删除此选项。

/boot/extlinux.conf 示例

这是一个完整的文件,由 update-extlinux 命令编写。

DEFAULT menu.c32
PROMPT 0
MENU TITLE Alpine/Linux Boot Menu
MENU AUTOBOOT Alpine will be booted automatically in # seconds.
SERIAL 0 9600
TIMEOUT 100
LABEL grsec
  MENU DEFAULT
  MENU LABEL Linux 3.10.33-0-grsec
  LINUX vmlinuz-3.10.33-0-grsec
  INITRD initramfs-3.10.33-0-grsec
  APPEND root=UUID=re-mov-ed-uu-id modules=sd-mod,usb-storage,ext4 console=ttyS0,9600

MENU SEPARATOR

请:如果需要(Xen/qemu!!),请将 tty 速度调整为 115200。

超时以十分之一秒为单位给出,因此这将是 10 秒超时。[1] 超时值为 0 不会立即启动,而是无限期地等待用户。

如果该文件由 pygrub 读取,则相同的值将被解释为秒,从而导致每个 VM 启动延迟 100 秒。

Grub

如果您使用 Grub 作为引导加载程序,请按照本节操作。编辑/etc/default/grub并添加以下行(假设您正在使用波特率为 115200 的第一个串行端口)

GRUB_TERMINAL="serial console"
GRUB_SERIAL_COMMAND="serial --unit=0 --word=8 --parity=no --speed 115200 --stop=1"

也添加console=ttyS0,115200n8dGRUB_CMDLINE_LINUX_DEFAULT变量

你的/etc/default/grub现在应该看起来像这样

GRUB_TIMEOUT=2
GRUB_DISABLE_SUBMENU=y
GRUB_DISABLE_RECOVERY=true
GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200n8d modules=sd-mod,usb-storage,xfs quiet rootfstype=xfs"
GRUB_TERMINAL="serial console"
GRUB_SERIAL_COMMAND="serial --unit=0 --word=8 --parity=no --speed 115200 --stop=1"

现在,使用以下命令重新生成您的 grub.cfg

grub-mkconfig -o /boot/grub/grub.cfg

按照下面的最后 2 个步骤操作启用登录控制台将您的串行控制台添加到受信任的本地终端列表

启用登录控制台

这在 /etc/inittab 中完成。ttyS0 有注释条目。只需启用它即可。

# Put a getty on the serial port
ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100

要启动 getty,请重新加载 inittab

kill -HUP 1

在启动期间启用两个控制台

可以在系统启动期间输出到串行控制台和 vga 控制台。

append "quiet console=ttyS0,9600 console=tty0"

不知道如何在 extlinux 菜单中执行相同的操作。您可能会在此线程中找到一个起点:http://patchwork.openembedded.org/patch/45175/

将您的串行控制台添加到受信任的本地终端列表

如果您遇到登录提示始终拒绝您在使用串行控制台时的密码的问题,则您错过了此条目。

将此添加到/etc/securetty文件

ttyS0