Tutorial details | |
---|---|
Difficulty | Intermediate (rss) |
Root privileges | Yes |
Requirements | CentOS/RHEL with serial port |
Time | N/A |
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:- Device name : /dev/ttyS1
- Speed: 19200
- Word: 8
- Parity: No
- Grub config file : /etc/grub.conf or /boot/grub/grub.conf
- Secure tty config file : /etc/securetty
- 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.
🐧 19 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
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
Thanks a lot cuturrr, your with some changes worked on a xen env:
start on runlevel [1345]
stop on runlevel [S06]
respawn
instance /dev/hvc0
exec /sbin/agetty hvc0 115200 vt100-nav
Hi,
Thanks a lot
nice article…
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.
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.
This setup works much better for HP ILO 3…assuming you’ve done the preliminary work in the BIOS
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
FWIW: I found that serial-console access worked [on CentOS 6.6] after making the changes to grub.conf. i.e., No other changes were necessary.
HTH!
Actually, if /etc/grub.conf and /boot/grub/grub.conf (in CentOS 6.X) are both having the setting above (tested on ttyS0 and serial –unit=0), you don’t need the upstart configuration under /etc/init/ttyS0.conf
Grub will do the all job without it. and (the best thing) it will show the console from boot time.
Just FYI – I had to remove the line –
instance /dev/ttyS…
to get it to behave properly. With that in, after the first serial session was opened, it was respawning a parallel login prompt and overlaying it on the same login. So it was impossible to work on the serial session after that. Once removed, it works well.
On Centos 6.x, creating /etc/init/ttyS0.conf won’t do the job.
I just put line:
c0:2345:respawn:/sbin/agetty 9600 ttyS0 linux
in /etc/inittab and it worked.
Unfortunately, this procedure did not work for me RHEL6.0 64bit.
Looking for another way. Thank you
echo “ttyS0” >> /etc/securetty
cat >/etc/init/serial-ttyS0.conf <<HERE
stop on runlevel [016]
start on runlevel [345]
respawn
instance /dev/ttyS0
exec /sbin/mingetty /dev/ttyS0
HERE
initctl start serial-ttyS0
http://lost-and-found-narihiro.blogspot.ca/2012/07/kvm-centos6-set-up-serial-console-when.html
Morning,
I followed your procedure, serial over lan is working at the boot but then stuck at FS-Cache: Netfs ‘nfs’ registered for caching
Jul 18 10:58:49 cwo-774-tste kernel: FS-Cache: Netfs ‘nfs’ registered for caching
In the main screen, I can see the welcome screen, machine is ready, but still stuck on the serial console
As below the latest log
Jul 18 10:58:49 cwo-774-tste kernel: FS-Cache: Netfs ‘nfs’ registered for caching
Jul 18 10:58:50 cwo-774-tste polkitd[3341]: started daemon version 0.96 using authority implementation `local’ version `0.96′
Jul 18 10:58:50 cwo-774-tste rtkit-daemon[3345]: Sucessfully made thread 3343 of process 3343 (/usr/bin/pulseaudio) owned by ‘gdm’ high priority at nice level -11.
Jul 18 10:58:50 cwo-774-tste rtkit-daemon[3345]: Sucessfully made thread 3349 of process 3343 (/usr/bin/pulseaudio) owned by ‘gdm’ RT at priority 5.
Jul 18 10:58:50 cwo-774-tste rtkit-daemon[3345]: Sucessfully made thread 3350 of process 3343 (/usr/bin/pulseaudio) owned by ‘gdm’ RT at priority 5.
Jul 18 10:58:58 cwo-774-tste modem-manager: (ttyS1) closing serial device…
Jul 18 10:58:58 cwo-774-tste modem-manager: (ttyS1) opening serial device…
Jul 18 10:59:04 cwo-774-tste modem-manager: (ttyS1) closing serial device…
I removed modem-manager which is not closing serial device anymore, but still hanging at FS-Cache: Netfs nfs registered for caching. Not getting in login prompt. Is there another way to test getting a login prompt?
Boot into a single mode and disable NFS caching if not needed.
Change to full multiple user mode, as I don’t have the root password, I tried lookupcache=none in my fstab, with no luck still hanging at the boot via serial console, but booting ok on the screen attached to the PC.
I made some progress, no I’m getting the OS name after the boot has finished but still not the login.
FS-Cache: Netfs ‘nfs’ registered for caching
Scientific Linux
I only enabled /etc/inittab
c0:12345:respawn:/sbin/getty -L 115200 ttyS1 vt100-nav
initctl list return:
serial (ttyS1) start/running, process 3051