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.

Using yum to install the latest kernels on Fedora hosts

As you may surmise from several of my recent posts, I have been doing a ton of Linux virtualization (Xen, KVM, openvz) testing. In the case of KVM, numerous bug fixes are integrated into each kernel release, so it’s often beneficial to stick to the bleeding edge kernels (though great for testing, I wouldn’t feel comfortable running these in production). Fedora provides the latest and greatest kernels and virtualization packages (libvirt, qemu, etc.) in the rawhide repository, which you can access by setting the enabled flag to 1 in /etc/yum.repos.d/fedora-rawhide.repo:

[rawhide]
name=Fedora - Rawhide - Developmental packages for the next Fedora release
failovermethod=priority
#baseurl=http://download.fedoraproject.org/pub/fedora/linux/development/$basearch/os/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=rawhide&arch=$basearch
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch

[rawhide-debuginfo]
name=Fedora - Rawhide - Debug
failovermethod=priority
#baseurl=http://download.fedoraproject.org/pub/fedora/linux/development/$basearch/debug/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=rawhide-debug&arch=$basearch
enabled=1

Once you have the repository enabled, you can use yum to install the latest kernel:

$ yum update kernel

This will install the latest kernel, and allow you to take advantage of the latest Linux kernel features.