CentOS / RHEL v6.x: Install And Configure Serial Console

by on February 25, 2013 · 6 comments· LAST UPDATED February 25, 2013

in ,

How do I configure serial console under CentOS Linux or Red Hat Enterprise Linux 6.x running on HP or Dell server?

Tutorial details
DifficultyIntermediate (rss)
Root privilegesYes
RequirementsCentOS/RHEL
with serial port
Estimated completion timeN/A

You need to use setserial command. The command is designed to set and/or report the configuration information associated with a serial port.

setserial -g /dev/ttyS[0123]

Sample outputs:

/dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4
/dev/ttyS1, UART: 16550A, Port: 0x02f8, IRQ: 3
/dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
/dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3

Our sample setup

I am going to use the following configuration:

  1. Device name : /dev/ttyS1
  2. Speed: 19200
  3. Word: 8
  4. Parity: No
  5. Grub config file : /etc/grub.conf or /boot/grub/grub.conf
  6. Secure tty config file : /etc/securetty
  7. Upstart config file to start agetty on /dev/ttyS1: /etc/init/ttyS1.conf

Step #1: Grub configuration

Type the following command:
# vi /boot/grub/grub.conf
Add the following lines befor :hiddenmenu config options:

 
serial --unit=1 --speed=19200 --word=8 --parity=no --stop=1
terminal --timeout=5 serial console
 

Scroll down and find out kernel line and append the following config options:

console=tty0 console=ttyS1,19200n8

At the end your grub.conf should look as follows:

default=0
timeout=5
#splashimage=(hd0,0)/grub/splash.xpm.gz
serial --unit=1 --speed=19200 --word=8 --parity=no --stop=1
terminal --timeout=5 serial console
:hiddenmenu
title Red Hat Enterprise Linux Server (2.6.32-358.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=UUID=00f30f09-2bfb-4dde-8396-eea16c0ee21a nomodeset rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD  KEYTABLE=us SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_NO_LVM rd_NO_DM rhgb  pcie_aspm=off biosdevname=0 console=tty0 console=ttyS1,19200n8
        initrd /initramfs-2.6.32-358.el6.x86_64.img
title Red Hat Enterprise Linux (2.6.32-279.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-279.el6.x86_64 ro root=UUID=00f30f09-2bfb-4dde-8396-eea16c0ee21a nomodeset rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD  KEYTABLE=us SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_NO_LVM rd_NO_DM rhgb  pcie_aspm=off biosdevname=0 console=tty0 console=ttyS1,19200n8
        initrd /initramfs-2.6.32-279.el6.x86_64.img

Step #2: Secure tty configuration

Type the following command:
# vi /etc/securetty
Append the following entry:

ttyS1

Save and close the file.

Step #3: Upstart configuration

init is upstart process management daemon. init is the parent of all processes on the system, it is executed by the kernel and is responsible for starting all other processes; it is the parent of all processes whose natural parents have died and it is responsible for reaping those when they die. Processes managed by init are known as jobs and are defined by files in the /etc/init directory. Type the following command to create /etc/init/ttyS1.conf file, enter::
# vi /etc/init/ttyS1.conf
Append the following config options:

 
start on runlevel [345]
stop on runlevel [S016]
 
respawn
instance /dev/ttyS1
exec /sbin/agetty ttyS1 19200 vt100-nav
 

Save and close the file.

Step 4: Verify settings

Reboot the server:
# reboot
Connect to console using serial console utility.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 6 comments… read them below or add one }

1 cuturrr February 26, 2013 at 8:32 am

I tried this conf on centos vm(kvm), but if put the vm on single user mode, my console stop working
your config
================================================================
start on runlevel [345]
stop on runlevel [S016]

respawn
instance /dev/ttyS1
exec /sbin/agetty ttyS1 19200 vt100-nav
================================================================
my newconf
================================================================
start on runlevel [1345]
stop on runlevel [S06]

respawn
instance /dev/ttyS1
exec /sbin/agetty ttyS1 19200 vt100-nav
================================================================

Thanks

Reply

2 Jalal Hajigholamali March 10, 2013 at 10:11 am

Hi,
Thanks a lot
nice article…

Reply

3 Andy Logan May 31, 2013 at 12:39 pm

Thanks for the article.

I’m using Centos 6.4 and if I configured /etc/init/ttyS1.conf I couldn’t login via the console.

I saw errors like this in the /var/log/messages:
init: serial (ttyS1) main process (12879) terminated with status 1

When I commented out the config in /etc/init/ttyS1.conf I could login via the console.

Reply

4 Stefan Lasiewski May 31, 2013 at 11:50 pm

For most people with a single console, the work is much simpler. I appended the kernel parameters with this command:

grubby –update-kernel=ALL –args=’console=ttyS0,9600n8 console=tty0′

Reboot the system and the consoles worked. According to /etc/init/serial.conf , init will start the consoles automatically:

# On boot, a udev helper examines /dev/console. If a serial console is the
# primary console (last console on the commandline in grub), the event
# ‘fedora.serial-console-available ‘ is emitted, which
# triggers this script. It waits for the runlevel to finish, ensures
# the proper port is in /etc/securetty, and starts the getty.

Reply

5 Mariel October 29, 2013 at 3:04 am

This setup works much better for HP ILO 3…assuming you’ve done the preliminary work in the BIOS

Reply

6 Eric Pretorious December 3, 2014 at 11:28 pm

I had to change the second kernel parameter in grub.conf [console=ttyS1,19200n8] before I was able access the console:
…console=tty0 console=ttyS0,19200n8

Reply

Leave a Comment

Tagged as: , , ,

Previous Faq:

Next Faq: