Enable Serial/SOL Output in GNU/Linux Systems
Serial cable, or SOL (serial over LAN), can be particularly useful in various scenarios, such as managing servers in data centers, remote troubleshooting. However, in some Linux distributions the serial output is not enabled by default. This tutorial will guide you through the steps to properly enable serial output for GNU/Linux systems, both temporarily and permanently. We'll also delve into the nuances of the commands and parameters involved, making sure you have a thorough understanding of the process.
Temporarily
When system boot to grub menu, press e to edit boot options, in the line starting with `linux
($root)/vmlinuz-
', append `console=ttyS0,115200n8 console=tty0
' to the end. Then press
Ctrl + x to continue to boot.
The parameters added will be explained in later sections.
Permanently
Below steps were tested in RHEL 8.2 and 9.0.
-
Enter directory `
/etc/default
' and make a backup of file `grub
'.cd /etc/default
sudo cp grub grub.bak
-
Edit file `
/etc/default/grub
', in line starting with `GRUB_CMDLINE_LINUX=
', append `console=ttyS0,115200n8 console=tty0
' within the quotation marks. -
Execute below commands (the path in the second command may be different, depending on the Linux distribution):
These commands will be explained in later sections.sudo grub2-editenv - unset kernelopts
sudo grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
If Something Is Wrong
In case that something was did mistakenly in above procedure and the system cannot boot, you can try to boot
into single-user mode and restore the file grub
from grub.bak
created in the first
step, and then redo step 3.
Parameters and Commands Explained
Grub Parameters
In above steps, we added 2 parts to grub options, `console=ttyS0,115200n8
' and
`console=tty0
'. The former is to direct the console output to the first serial port
(`ttyS0
') at a baud rate of 115200, with no parity (which is the meaning of
`n
'), and 8 data bits (meaning of `8
'). While the latter part is to specify the
system's main display. `tty0
' typically refers to the current virtual terminal on a standard
monitor attached to the machine.
The `console
' being specified twice is to configure the system to duplicate the console output,
sending it to both the serial port and the main display.
Commands
grub2-editenv - unset kernelopts
-
`
grub2-editenv
' is a utility to edit the GRUB2 environment block, which is a small, dedicated area where GRUB2 stores persistent data. The single dash `-
' means the command is going to operate on the default GRUB environment block instead of on a file. `unset kernelopts
' is to remove previous configured kernel parameters. grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
-
`
grub2-mkconfig
' is a utility to generate a new GRUB2 configuration file. `-o /boot/efi/EFI/redhat/grub.cfg
' specifies the output file for the new configuration, which is the typical location for Red Hat or Red Hat-based systems (like Fedora or CentOS) that use UEFI.