How does one set up a serial terminal and/or console in Red Hat Enterprise Linux?

Updated

Introduction

It is sometimes helpful to have a serial console for debugging purposes and a serial terminal for headless operation. A serial console will send all console output to the serial port. A serial terminal, if properly configured, also lets you log on to the system via the serial port as a remote terminal. You can set up both or just one. This article will cover the configuration of serial terminals in RHEL.

Contents


About Serial Console Kernel Option Configuration

First, to get the kernel to output all console messages to the serial port you need to pass the console=ttyS0 (please note that the trailing character is a zero, not the letter O) parameter to the kernel at boot time. This is usually done via the bootloader; we'll be using GRUB in our examples. The following example will configure the system to send the console output to the serial port ttyS0 at a baud rate of 115200 as well as sending the output to the regular console or "screen" tty0.

For example in case of rhel6:

default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux Server (2.6.32-754.17.1.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-754.17.1.el6.x86_64 ro root=/dev/mapper/VolGroup--
lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT==
latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root  KEYBOARDTYPE=pc KK
EYTABLE=us rd_NO_DM console=tty0 console=ttyS0,115200  <----------------------------------------------- add 
        initrd /initramfs-2.6.32-754.17.1.el6.x86_64.img
title Red Hat Enterprise Linux Server (2.6.32-696.3.2.el6.x86_64)

  • Note: Regarding the above documented baud rate 115200, the baud rate for a given configuration depends upon the hardware settings. Each server will have its own serial console settings, generally noted in the system BIOS. Before applying any such settings, it is recommended that you also check your server manual. Incorrectly configured baud rate settings might lead to junk character being displayed at login.

  • Note: The primary console for system output will be the last console listed in the kernel parameters. In the above example, the serial console is the primary and the VGA console tty0 is the secondary display. This means messages from init scripts, boot messages and critical warnings will go to the serial console, since it is the primary console, If init script messages don't need to be seen on the serial console, it should be made the secondary by swapping the order of the console parameters:

    console=ttyS0,115200 console=tty0 
    
  • Any settings altered in grub.conf will take effect on the next system reboot.

  • One will also have to add the serial port to the /etc/securetty file in Red Hat Enterprise Linux 4, 5, and 6 to allow root logins through the serial port. ttyS0 should be added to the bottom of the list on a new line:

    tty9
    tty10
    tty11
    ttyS0
    
  • Red Hat Enterprise Linux 7 has a ttyS0 entry in /etc/securetty by default.


Serial Terminal Configuration in RHEL 9

  1. Add, or update if already present, the following lines to /etc/default/grub:
GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200"
GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
  1. Rebuild the grub configuration file. For RHEL 9.0, 9.1, and 9.2:
# grub2-mkconfig -o /boot/grub2/grub.cfg

For RHEL 9.3 and later:

# grub2-mkconfig -o /boot/grub2/grub.cfg --update-bls-cmdline

Serial Terminal Configuration in RHEL 8

  1. Get the current kernel command line parameters:
# grub2-editenv - list | grep kernelopts
kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap
  1. Copy the kernelopts line above completely.
  2. Set the new kernel options by pasting the original options and appending the new ones like so:
# grub2-editenv - set "kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap console=tty0 console=ttyS0,115200"
  1. Check to see if the parameters were set properly:
# grub2-editenv - list | grep kernelopts
kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap console=tty0 console=ttyS0,115200 
  1. For an interactive console, you will need to edit /etc/default/grub to allow input and output to the serial console. We'll modify the GRUB_TERMINAL_OUTPUT to just GRUB_TERMINAL so we can set output AND input to both console and serial connections.
# sed -i 's/GRUB_TERMINAL_OUTPUT="console"/GRUB_TERMINAL="console serial"/g' /etc/default/grub
  1. Rebuild the grub configuration file.

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

  • Additional information on making kernel command line parameters persistent can be found in this solution

Serial Terminal Configuration in RHEL 7

  1. Add, or update if already present, the following lines to /etc/default/grub:
GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200"
GRUB_TERMINAL="console 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.
  1. This content is not included.Rebuild the 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
  2. Reboot


Serial Terminal Configuration in RHEL 6

  • Edit the file /boot/grub/grub.conf by adding the following kernel options to the kernel line:

    console=tty0 console=ttyS0,115200 
    

    For example, in grub.conf:

      default=0
      timeout=5
      splashimage=(hd0,0)/grub/splash.xpm.gz
      hiddenmenu
      title Red Hat Enterprise Linux Server (2.6.32-754.17.1.el6.x86_64)
              root (hd0,0)
              kernel /vmlinuz-2.6.32-754.17.1.el6.x86_64 ro root=/dev/mapper/VolGroup--
    lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT==
    latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root  KEYBOARDTYPE=pc KK
    EYTABLE=us rd_NO_DM console=tty0 console=ttyS0,115200  <----------------------------------------------- add
              initrd /initramfs-2.6.32-754.17.1.el6.x86_64.img
    title Red Hat Enterprise Linux Server (2.6.32-696.3.2.el6.x86_64)
    

    If you want to control GRUB from a Serial Console, please comment out the splashimage and hiddenmenu:

    default=0
    timeout=5
    #splashimage=(hd0,0)/grub/splash.xpm.gz   <------------------------------- comment out 
    #hiddenmenu                               <------------------------------- comment out
    :
    :
    
  • Reboot

    After rebooting, you can see the menu on the serial console and can set up grub parameters by pressing 'e'

       GNU GRUB  version 0.97  (631K lower / 1047540K upper memory)
    
     +-------------------------------------------------------------------------+
     | Red Hat Enterprise Linux Server (2.6.32-754.17.1.el6.x86_64)            |  
     | Red Hat Enterprise Linux Server (2.6.32-696.3.2.el6.x86_64)             |
     | Red Hat Enterprise Linux Server (2.6.32-754.3.5.el6.x86_64)             |
     |                                                                         |
     |                                                                         |
     |                                                                         |
     |                                                                         |
     |                                                                         |
     |                                                                         |
     |                                                                         |
     |                                                                         |
     |                                                                         |  
     +-------------------------------------------------------------------------+
          Use the ^ and v keys to select which entry is highlighted.
          Press enter to boot the selected OS, 'e' to edit the
          commands before booting, 'a' to modify the kernel arguments
          before booting, or 'c' for a command-line.
    
SBR
Category
Components
Article Type