26.9. GRUB 2 over a Serial Console

This section describes how to configure GRUB 2 for serial communications on machines with no display or keyboard.
To access the GRUB 2 terminal over a serial connection, an additional option must be added to a kernel definition to make that particular kernel monitor a serial connection.
For example:
Where console=ttyS0 is the serial terminal to be used, 9600 is the baud rate, n is for no parity, and 8 is the word length in bits. A much higher baud rate, for example 115200, is preferable for tasks such as following log files.
For more information on serial console settings, see the section called “Installable and External Documentation”

26.9.1. Configuring GRUB 2 for a single boot

To set the system to use a serial terminal only during a single boot process, when the GRUB 2 boot menu appears, move the cursor to the kernel you want to start, and press the e key to edit the kernel parameters. Remove the rhgb and quiet parameters and add console parameters at the end of the linux16 line as follows:
linux16      /vmlinuz-3.10.0-0.rc4.59.el7.x86_64 root=/dev/mapper/rhel-root ro rd.md=0 rd.dm=0 rd.lvm.lv=rhel/swap crashkernel=auto rd.luks=0 vconsole.keymap=us rd.lvm.lv=rhel/root console=ttyS0,9600
These settings are not persistent and apply only for a single boot.

26.9.2. Configuring GRUB 2 for a persistent change

To make persistent changes to a menu entry on a system, use the grubby tool. For example, to update the entry for the default kernel, enter a command as follows:
~]# grubby --remove-args="rhgb quiet" --args=console=ttyS0,9600 --update-kernel=DEFAULT
The --update-kernel parameter also accepts the keyword ALL or a comma separated list of kernel index numbers. See the section called “Adding and Removing Arguments from a GRUB 2 Menu Entry” for more information on using grubby.

26.9.3. Configuring a new GRUB 2 file

If required to build a new GRUB 2 configuration file, add the following two lines in the /etc/default/grub file:
GRUB_SERIAL_COMMAND="serial --speed=9600 --unit=0 --word=8 --parity=no --stop=1"
The first line disables the graphical terminal. Note that specifying the GRUB_TERMINAL key overrides values of GRUB_TERMINAL_INPUT and GRUB_TERMINAL_OUTPUT. On the second line, adjust the baud rate, parity, and other values to fit your environment and hardware. A much higher baud rate, for example 115200, is preferable for tasks such as following log files. Once you have completed the changes in the /etc/default/grub file, it is necessary to update the GRUB 2 configuration file.
Rebuild the grub.cfg file by running the grub2-mkconfig -o command as follows:
  • On BIOS-based machines, issue the following command as root:
    ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
  • On UEFI-based machines, issue the following command as root:
    ~]# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

26.9.4. Using screen to Connect to the Serial Console

The screen tool serves as a capable serial terminal. To install it, run as root:
~]# yum install screen
To connect to your machine using the serial console, use a command in the follow format:
screen /dev/console_port baud_rate
By default, if no option is specified, screen uses the standard 9600 baud rate. To set a higher baud rate, enter:
~]$ screen /dev/console_port 115200
Where console_port is ttyS0, or ttyUSB0, and so on.
To end the session in screen, press Ctrl+a, type :quit and press Enter.
See the screen(1) manual page for additional options and detailed information.