原文地址:http://zhigang.org/wiki/XenSerialConsole 

Xen Serial Console

Some times it's necessary to get the booting log of Xen. Belows are some tips for setup the serial console.

System configuration

Add the following lines to /boot/grub/grub.conf:

1 serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
2 terminal --timeout=5 serial console
3 title xen serial console
4     root (hd0,0)
5     kernel /boot/xen.gz com1=115200,8n1 console=com1,vga
6     module /boot/vmlinuz-2.6.18 ro root=LABEL=/ 3 console=tty0 console=xvc0
7     module /boot/initrd-2.6.18.img

These lines setup serial console for grub, xen hypervisor and dom0 linux kernel separately. Although they are different from each other, but you'll find them sharing the same common concepts.

  • The first two lines are for grub.

    • serial tells grub to initialize a serial device.

    • --unit=0 tells grub to select the first serial device to use (COM1).

    • --speed=115200 --word=8 --parity=no --stop=1 sets parameters for the serial device.

    • terminal tells grub to select a terminal. When multiple terminals are specified, it will show up the following message:

      Press any key to continue.

      per second on both console and serial. The terminal to which you input a key first will be selected.

    • --timeout=5 tells grub to wait for 5 seconds until you input a key. If you input nothing within the limited time, grub will select the default console menu output.

    • The default console is determined by the sequence of "serial console" in line 2. The first one will be selected (the "serial" in this case).

  • Line 5 is for xen hypervisor:

    • com1=115200,8n1 sets parameters for the serial device driver in xen hypervisor.
    • console=com1,vga tells xen hypervisor to print booting logs on both com1 and vga.

    The sequence of "com1" and "vga" is not important.

    The default "console" value for xen-3.1.x are:

    arch    | value
    ------------------
    x86     | com1,vga
    x86_64  | com1,vga
    ia64    | com1
    powerpc | com1

    For xen-3.2+:

    arch    | value
    ------------------
    x86     | vga
    x86_64  | vga
    ia64    | com1
    powerpc | com1
  • Line 6 is for dom0 linux kernel:

    • console=xvc0 sets parameters for the serial device driver in Linux kernel.
    • console=tty0 tells linux kernel to also print kernel space logs on both tty0.

    The sequence of the two "console" statements is important. Kernel will look for a device that can be used as a system console and use that for /dev/console. In this case, all user space screen output will go to /dev/xvc0.

The settings of the serial device should the same among grub, xen hypervisor and dom0 linux kernel.

If you are using the second serial port, the configuration should be:

serial --unit=1 --speed=115200 --word=8 --parity=no --stop=1
terminal --timeout=5 serial console
title xen serial console
    root (hd0,0)
    kernel /boot/xen.gz com2=115200,8n1 console=com1,vga
    module /boot/vmlinuz-2.6.18 ro root=LABEL=/ 3 console=tty0 console=xvc0
    module /boot/initrd-2.6.18.img

In order to allow root to login on xvc0 in dom0, you should also do the followings:

  • Add ttyS0 to /etc/securetty in order to allow root to login on xvc0.

  • Add the following line to /etc/inittab to automatically start a login prompt over the serial port:

    co:2345:respawn:/sbin/agetty xvc0 115200 vt100-nav

Enable Serial Console for Fedora 15

  • Create file /etc/init/serial-console.conf:

    start on stopped rc RUNLEVEL=[2345]
    stop on runlevel [S016]
    instance ttyS0
    respawn
    pre-start exec /sbin/securetty ttyS0
    exec /sbin/agetty /dev/ttyS0 115200 vt100-nav

Log serial output with minicom

Enter the following command as root:

# minicom -s

Down arrow to Serial port setup and hit enter. The following settings should be entered:

A - Serial Device         : /dev/ttyS0
B - Lockfile Location     : /var/lock
C - Callin Program        :
D - Callout Program       :
E - Bps/Par/Bits          : 115200 8N1
F - Hardware Flow Control : No
G - Software Flow Control : No

Hit Esc to return to the main menu and select Save setup as dfl. The configure is stored in /etc/minirc.dfl, which looks like:

# Machine-generated file - use "minicom -s" to change parameters.
pu pname10          YUNYN
pr port             /dev/ttyS0
pu baudrate         115200
pu mautobaud        Yes
pu rtscts           No

Then exit, you'll get the login shell prompt.

Log serial output with ttywatch

After install ttywatch, a config file is placed to /etc/ttywatch.conf. Add the following lines:

--name localhost --port /dev/ttyS0 --bps 115200 --ipport 3001

Start ttywatch:

# service ttywatch start

Then the output is logged to /var/log/ttywatch/localhost.log.

You can also telnet to port 3000 to interact with /dev/ttyS0:

$ telnet localhost 3001

Log serial output with HyperTerminal on Windows

Launch HyperTerminal by: [Start] - [All Programs] - [Accessories] - [Communications] - [HyperTerminal].

Make a new connection using com1 and set BPS to 115200 then start call. You'll get the login shell prompt.

Useful commands

  • Change and print terminal line settings:

    # stty -F /dev/ttyS0
  • Get/Set Linux serial port information:

    # setserial -a /dev/ttyS0
  • Login to remote system by serial:

    # cu -l ttyS0 -s 115200