Serial Terminal Configuration in RHEL Distribution

Serial Terminal Configuration in RHEL 7

Add, or update if already present, the following lines to /etc/default/grub:

GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200n8"
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"

GRUB_CMDLINE_LINUX_DEFAULT applies this configuration only to the default menu entry, use GRUB_CMDLINE_LINUX to apply it to all the menu entries.
NOTE: each line type above should only appear once within the /etc/default/grub file. If the line already exists, then just modify it rather than add a second copy of same. That is, only one GRUB_CMDLINE_LINUX_DEFAULT line should exist in the file, etc.

Rebuild the /boot/grub2/grub.cfg file by running the grub2-mkconfig -o command as follows:

On BIOS-based machines: ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
On UEFI-based machines: ~]# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

Red Hat Enterprise Linux 8

GRUB boot parameters are edited via grub2-editenv command. First, retrieve the current parameters:

# grub2-editenv - list | grep kernelopts
kernelopts=root=/dev/mapper/rhel_example-root ro crashkernel=auto resume=/dev/mapper/rhel_example-swap
rd.lvm.lv=rhel_example/root rd.lvm.lv=rhel_example/swap

From here, copy the entire line and append the serial console parameters, and pass this into the noted command above;

grub2-editenv - set "kernelopts=root=/dev/mapper/rhel_example-root ro crashkernel=auto resume=/dev/mapper/rhel_example-swap rd.lvm.lv=rhel_example/root rd.lvm.lv=rhel_example/swap console=tty0 console=ttyS0,115200"\

The console parameter should now be set. A reboot will be required for the parameter to take effect. The parameters can be listed to confirm the parameter was set:

# grub2-editenv - list | grep kernelopts
kernelopts=root=/dev/mapper/rhel_example-root ro crashkernel=auto resume=/dev/mapper/rhel_example-swap
rd.lvm.lv=rhel_example/root rd.lvm.lv=rhel_example/swap console=tty0 console=ttyS0,115200

Red Hat Enterprise Linux 9

Modify the kernel parameters using grubby command . Retrieve the current parameters:

# grubby --info=ALL|grep -i args

# grubby --info=ALL|grep -i args
args="ro crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap

Update the parametrs “console=tty0 console=ttyS0,115200”

# grubby --update-kernel=ALL --args="console=tty0 console=ttyS0,115200"

The console parameter should now be set. A reboot will be required for the parameter to take effect. The parameters can be listed to confirm the parameter was set:

# grubby --info=ALL|grep -i args
args="ro crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap console=tty0 console=ttyS0,115200"
# reboot
# cat /proc/cmdline

Controlling GRUB from a Serial Console

One can also tell grub to use the serial console instead of the VGA console. This lets one interrupt the boot process and choose a different kernel or add kernel parameters, for example, to boot into single user mode.

To configure GRUB to use the serial console, comment out the splash image and add the serial and terminal options to grub.conf:

[root@localhost ~]# cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/hda2
# initrd /initrd-version.img
#boot=/dev/hda
default=0
timeout=10
#splashimage=(hd0,0)/grub/splash.xpm.gz
serial --unit=0 --speed=115200
terminal --timeout=5 serial console
title Red Hat Enterprise Linux AS (2.4.21-27.0.2.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.4.21-27.0.2.ELsmp ro root=LABEL=/ console=ttyS0,115200 console=tty0
initrd /initrd-2.4.21-27.0.2.ELsmp.img

Any settings altered in grub.conf will take effect on the next system reboot.

Src:
https://access.redhat.com/articles/3166931#config7

Share

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.