Ubuntu 20.04: GRUB2 and Linux with serial console

This article will describe changing GRUB2 and Linux to serial console.

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.
#!/bin/sh

sudo cp /etc/default/grub /etc/default/grub.orig

cat <<EOF | sudo tee /etc/default/grub
GRUB_DEFAULT=0
GRUB_TIMEOUT=1
GRUB_RECORDFAIL_TIMEOUT=\${GRUB_TIMEOUT}
GRUB_DISTRIBUTOR=\`lsb_release -i -s 2> /dev/null || echo Debian\`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="console=tty1 console=ttyS0,115200"
GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no \
--stop=1"
EOF

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

2 Execution result

The left window is running virsh console and the right window is virt-manager.

0001_serial-console.png