Redirecting the CentOS and Fedora Linux console to a serial port (virsh console edition)

During my KVM testing, I wanted to be able to use the virsh “console” command to access the console of my guests. This would make remote management a whole lot easier, since the default remote management interface (vnc) was a bit of overkill. To get virsh to allow me to console in, the first thing I did was update the menu.lst to get grub to write to the serial port:

serial –speed=115200 –unit=0 –word=8 –parity=no –stop=1
terminal –timeout=10 serial

In addition to the two items above, you also need to make sure you disable the splash screen. Next up, I had to adjust the kernel entries in the menu.lst to write to the serial port (ttyS0). Here is a sample entry that does just this:

title CentOS (2.6.18-128.1.10.el5)
	root (hd0,0)
	kernel /boot/vmlinuz-2.6.18-128.1.10.el5 ro root=LABEL=/ console=ttyS0
	initrd /boot/initrd-2.6.18-128.1.10.el5.img



The items listed above will configure grub and the kernel to write to the serial port, but you will not be able to login since a getty process isn’t configured to monitor the serial port. To fix this, you can add the serial device name to /etc/inittab (the entry below assumes you want to use agetty instead of one of the other getty implementations):

S0:12345:respawn:/sbin/agetty ttyS0 115200

After I configured init to spawn a getty process, I had to tell init that it was ok for root to login through ttyS0. Privileged logins are managed through /etc/securetty, which contains a list of devices that root is approved to log in on. To allow root logins over ttyS0, I appended it to the file:

echo “ttyS0″ >> /etc/securetty

Once the items listed above were in place, I was able to fire up virsh and access the console through SSH:

$ virsh

virsh # console kvmnode1
Connected to domain kvmnode1
Escape character is ^]

CentOS release 5.3 (Final)
Kernel 2.6.18-128.1.10.el5 on an x86_64

kvmnode1 login:

This is amazingly cool, and makes remote management super easy.

6 Comments

Jeff Schroeder  on June 17th, 2009

If you use cobbler + koan and build the virtual node with koan, it will do this for you fyi.

gp  on June 18th, 2009

This also works with almost all linux distros, except that a few distros already have ttyS0 in the /etc/securetty file (at least Debian and its sons). I use it to have serial console in my VMware server lab servers :)

Dude1  on June 26th, 2009

Thanks man this rocks.

If you looking for a good how to setup console for remote logins on unix and vmware esx server, look here.

khalid  on April 24th, 2010

Thanks a lot for your material.

Khalid.

Rahul Panwar  on May 24th, 2010

Hi,

I am also doing the same to configure the serial console on centos 5.4.

But my problem is that my computer ttyS0 (com1) is not working. I installed a PCI serial card & it is installed in Centos as ttyS1.

Now i want to do the same with ttyS1, my grub.conf is as follows:
**********************************************
default=0
timeout=5
#splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
serial –unit=1 –speed=115200
terminal –timeout=2 console serial
title CentOS (2.6.18-164.15.1.el5.centos.plusPAE)
root (hd0,0)
kernel /vmlinuz-2.6.18-164.15.1.el5.centos.plusPAE ro root=/dev/CoralVol00/CoralOS00 console=tty0 console=ttyS1,115200n8
initrd /initrd-2.6.18-164.15.1.el5.centos.plusPAE.img
title CentOS-base (2.6.18-164.15.1.el5.centos.plus)
root (hd0,0)
kernel /vmlinuz-2.6.18-164.15.1.el5.centos.plus ro root=/dev/CoralVol00/CoralOS00 rhgb quiet
initrd /initrd-2.6.18-164.15.1.el5.centos.plus.img
**********************************************

I also created an entry in inittab:
**********************************************
S1:12345:respawn:/sbin/agetty -L 115200 ttyS1 vt100
**********************************************

But i am receiving kernel panic after doing these setting. Can you help me, what i am doing wrong?

Regards,
Rahul Panwar

Boyan Boychev  on June 3rd, 2010

How do I set up a guest so that the virsh and xm console commands work for my KVM or Xen guests on RHEL5?
————————————————————————————————————————————–
http://kbase.redhat.com/faq/docs/DOC-25454

Leave a Comment