Table of Contents
1 /etc/default/grub
Change /etc/default/grub as below.
- Change GRUB terminal to console and ttyS0. This will provide one GRUB to a monitor display and serial console.
- Change linux kernel console to tty1 and ttyS0. This setting will be taken over to userland, and there will be two login prompt for tty1 and ttyS0.
$ sudo cp /etc/default/grub /etc/default/grub.orig$ C=”resume=/dev/mapper/fedora-swap rd.lvm.lv=fedora/root rd.lvm.lv=fedora/swap”$ S=”serial –speed=115200 –unit=0 –word=8 –parity=no –stop=1″$ cat <<EOF | sudo tee /etc/default/grubGRUB_TIMEOUT=1GRUB_DISTRIBUTOR=”$(sed ‘s, release .*$,,g’ /etc/system-release)”GRUB_DEFAULT=savedGRUB_DISABLE_SUBMENU=trueGRUB_TERMINAL=”console serial”GRUB_CMDLINE_LINUX=”${C}”GRUB_CMDLINE_LINUX_DEFAULT=”console=tty1 console=ttyS0,115200″GRUB_SERIAL_COMMAND=”${S}”GRUB_DISABLE_RECOVERY=”true”EOF
2 grub2-mkconfig
Update /boot/grub2/grub.cfg with grub2-mkconfig.
$ sudo grub2-mkconfig -o /boot/grub2/grub.cfgGenerating grub configuration file …Found linux image: /boot/vmlinuz-4.16.7-300.fc28.x86_64Found initrd image: /boot/initramfs-4.16.7-300.fc28.x86_64.imgFound linux image: /boot/vmlinuz-4.16.3-301.fc28.x86_64Found initrd image: /boot/initramfs-4.16.3-301.fc28.x86_64.imgFound linux image: /boot/vmlinuz-0-rescue-3ba892070dae45849f0ccc5e362387a9Found initrd image:/boot/initramfs-0-rescue-3ba892070dae45849f0ccc5e362387a9.imgdone
Reboot system.
$ sudo reboot
3 Execution result
GRUB to monitor display is as below.
GRUB to serial console is as below. This article used “sudo virsh console <vmname>” for connecting serial console.
Login prompt to monitor display is as below. tty1 is displayed with press Ctrl + Alt + F1.
Login prompt to serial console is as below.
4 Change serial console window size
The default value of serial console window size is 80×24. This will effect emacs, tmux and screen.
$ echo $COLUMNS $LINES80 24
There are several ways for changing serial console window size. I think resize command in xterm package is the easiest way.
$ sudo dnf install -y xterm$ resizeCOLUMNS=90;LINES=36;export COLUMNS LINES;
Make resize command to be run after login.
$ cat <<EOF >> ~/.bashrccase “$(tty)” in /dev/ttyS*) resize > /dev/null 2>&1;;esacEOF
“trap ‘resize > /dev/null’ DEBUG” will call resize command many times. If you need to change serial console window size after ~/.bashrc, you had better call resize command manually.
$ trap ‘resize > /dev/null’ DEBUG$ for i in $(seq 0 9); do echo $i; done # resize will be called 10 times.