Go back to my diary list.

Some time, I need to do some kernel hacking on the network research, and I want to select the kernel boot
menu through a serial console connection. I guess most data center admins and network staff know this situation.
So I need to configure GRUB as well as the serial login in Linux. The following are Ubuntu version examples.
For other linux distributions, I will add them later.
A. For Ubuntu 9.10, 10.04 LTS or newer
1. Configure GRUB2 at /etc/default/grub. After the configuration, do remember to run "update-grub".
GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200n8"
GRUB_TERMINAL=serial
## I set the speed at 115200.
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
#GRUB_HIDDEN_TIMEOUT=0 ## comment the HIDDEN issue, or just delete it.
2. Create /etc/init/ttyS0.conf if it was not there, and paste the following:
# ttyS0 - getty
#
# This service maintains a getty on ttyS0 from the point the system is
# started until it is shut down again.
start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]
respawn
exec /sbin/getty -L 115200 ttyS0 vt102
3. Ask upstart (the /sbin/init daemon), to start the getty, then reboot will it be done!
root:/etc/init# start ttyS0
B. For Ubuntu 9.04 or older
1. Edit /boot/grub/menu.lst, and add the following lines to the top of the file:
# Enable console output via the serial port. unit 0 is /dev/ttyS0, unit 1 is /dev/ttyS1
serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
terminal --timeout=15 serial console
# When you next reboot, the output from grub will go to the normal console unless input
# is received from the serial port. Whichever receives input first becomes the default
# console. This gives you the best of both worlds.
2. Configuring the/boot/grub/menu.lst in case you want to see the booting information.
For example, change this
title Ubuntu, kernel 2.6.10-5-386
root (hd0,0)
kernel /boot/vmlinuz-2.6.10-5-386 root=/dev/hda1 ro quiet splash
initrd /boot/initrd.img-2.6.10-5-386
to
title Ubuntu, kernel 2.6.10-5-386
root (hd0,0)
kernel /boot/vmlinuz-2.6.10-5-386 root=/dev/hda1 ro quiet splash console=tty0 console=ttyS0,115200n8
initrd /boot/initrd.img-2.6.10-5-386
3. Create /etc/event.d/ttyS0, and paste the following, then reboot will it be done:
# ttyS0 - getty
#
# This service maintains a getty on ttyS0 from the point the system is
# started until it is shut down again.
start on runlevel 2
start on runlevel 3
start on runlevel 4
start on runlevel 5
stop on runlevel 0
stop on runlevel 1
stop on runlevel 6
respawn
exec /sbin/getty 115200 ttyS0
C. For FreeBSD
1. create boot.config for switching between serial console output and video output
#vim /boot.config add "-Dh" in boot.config and save.
2. edit /boot/loader.conf for the boot step 3 loading output:
boot_multicons="YES"
boot_serial="YES"
comconsole_speed="115200"
console="comconsole,vidconsole"
3. Add a listener for login to the system in /etc/ttys:
change
ttyd0 "/usr/libexec/getty std.9600" dialup off secure
to
ttyd0 "/usr/libexec/getty std.115200" vt102 on secure
Note: in FreeBSD8, they changed ttyd0 to ttyu0, so change the tty responsively.
After editing the file, you must kill -HUP 1 to make this change take effect.
Ubuntu: SerialConsoleHowto
FreeBSD: Setting Up the Serial Console
Unix Serial Howto
Go back to my diary list.