Chinaunix首页 | 论坛 | 博客
  • 博客访问: 304173
  • 博文数量: 34
  • 博客积分: 1944
  • 博客等级: 上尉
  • 技术积分: 400
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-01 23:22
文章分类

全部博文(34)

文章存档

2010年(2)

2009年(4)

2008年(28)

分类: LINUX

2009-03-04 19:44:56

目的: 台机已经装好Linux,显示器有问题,平时一般都SSH控制,当Linux网络挂的时候,想通过串口来管理。


硬件:台机自带两个串口(上面的是COM1)[under Windows] or ttyS0[under Linux)),笔记本T61p没有串口,买了个USB转串口(具体见下图)。同时需要串口交叉线一根(NULL modem Cable),母对母(公的是针),都是凹口那种。


目标机器:安装的CentOS 5.2 Linux 内核2.6.18-92.1.22.el52.6.18-92.1.22.el5xen

客户端: Windows XP SP3 IBM OEM. 安装USB转串口驱动。


需要把输出定向到串口,一般有下面几处:

  1. BIOS中的设置

  2. GRUB设置

  3. /etc/inittab 设置

  4. /etc/securetty 设置


BIOS中的设置


BIOS设置的作用我没尝试过,如果是可以连BIOS设置都可以定向到串口,那个强大了。也不知道如何去掉机器需要连键盘的限制。没拿出显示器所以没看我台机的BIOS,不过这个功能一般只有服务器级别的机器有。【注1】台机一般没有串口重定向功能。


GRUB设置

这里的配置是为了把grub菜单定向到串口,这样你就可以在串口操作grub,选择启动项,使用single mode等等。

同时也要给kernel参数加上console选项。


[root@CentOS5 ~]# cat /boot/grub/menu.lst

# grub.conf generated by anaconda

#

# Note that you do not have to rerun grub after making changes to this file

# NOTICE: You have a /boot partition. This means that

# all kernel and initrd paths are relative to /boot/, eg.

# root (hd0,0)

# kernel /vmlinuz-version ro root=/dev/vg00/lv_root

# initrd /initrd-version.img

#boot=/dev/hdb1

serial --unit=0 --speed=9600 --word=8 --parity=no --stop=1

terminal --timeout=10 serial console

default=2

timeout=20

#splashimage=(hd0,0)/grub/splash.xpm.gz =>这些在console下会工作不正常,注释掉。

#hiddenmenu

title CentOS (2.6.18-92.1.22.el5)

root (hd0,0)

kernel /vmlinuz-2.6.18-92.1.22.el5 ro root=/dev/vg00/lv_root rhgb quiet

initrd /initrd-2.6.18-92.1.22.el5.img

title CentOS Serial[ttyS0] - Console (2.6.18-92.1.22.el5)

root (hd0,0)

kernel /vmlinuz-2.6.18-92.1.22.el5 ro root=/dev/vg00/lv_root console=ttyS0,9600 console=tty0

initrd /initrd-2.6.18-92.1.22.el5.img

title CentOS Console - serial[ttyS0] (2.6.18-92.1.22.el5) [get more output in serial console]

root (hd0,0)

kernel /vmlinuz-2.6.18-92.1.22.el5 ro root=/dev/vg00/lv_root console=tty0 console=ttyS0,9600

initrd /initrd-2.6.18-92.1.22.el5.img

title CentOS Xen (2.6.18-92.1.22.el5xen)

root (hd0,0)

kernel /xen.gz-2.6.18-92.1.22.el5

module /vmlinuz-2.6.18-92.1.22.el5xen ro root=/dev/vg00/lv_root rhgb quiet xencons=off

module /initrd-2.6.18-92.1.22.el5xen.img

title CentOS Xen Serial[ttyS0] - Console (2.6.18-92.1.22.el5xen)

root (hd0,0)

kernel /xen.gz-2.6.18-92.1.22.el5

module /vmlinuz-2.6.18-92.1.22.el5xen ro root=/dev/vg00/lv_root xencons=off console=ttyS0,9600 console=tty0

module /initrd-2.6.18-92.1.22.el5xen.img

title CentOS Xen Console - serial[ttyS0] (2.6.18-92.1.22.el5xen)

root (hd0,0)

kernel /xen.gz-2.6.18-92.1.22.el5

module /vmlinuz-2.6.18-92.1.22.el5xen ro root=/dev/vg00/lv_root xencons=off console=tty0 console=ttyS0,9600

module /initrd-2.6.18-92.1.22.el5xen.img

title Other

rootnoverify (hd0,0)

chainloader +1


后面的console有顺序关系,详见下文【注2】,我常用串口所以console=tty0 console=ttyS0,9600这个顺序的输出信息比较多。


因为我的机器有xen的内核,xen默认情况下会把串口做为xencons,所以这里设置xencons=off.

When multiple consoles are listed output is sent to all consoles and input is taken from the last listed console. The last console is the one Linux uses as the /dev/console device.

/etc/inittab 设置

系统系统后,需要在串口上监听请求,所以要有个类似服务器的程序(agetty, mgetty etc)

/etc/inittab中添加

s0:2345:respawn:/sbin/agetty -L -f /etc/issue.serial 9600 ttyS0 vt100

#s1:2345:respawn:/sbin/agetty -L -f /etc/issue.serial 9600 ttyS1 vt100

#S0:2345:respawn:/sbin/mgetty -r -x 9 ttyS0 ==> mgetty 用来调试比较好,log也丰富。

What is a getty?

A getty is is a program that opens a tty port, prompts for a login name, and runs the /bin/login command. It is normally invoked by init.

所以其他程序就不能再来占用ttyS0了,串口是独占模式的吧。


vt100:

vt100 is the terminal emulation. You can use others, but VT100 is the most common or "standard". Another widely used termial type is VT102.

OK都可以了,可以重启server了。这里如果想测试下串口线,推荐先在Linux启动下mgetty,因为他的debug信息和log比较丰富,适合排错和测试。

#mgetty –r –x 9 ttyS0

Log/var/log/mgetty*中。


/etc/securetty设置

因为一般我们都是使用root登陆串口来维护,所以需要设置root可以在COM1COM2登陆。

/etc/securetty中添加:

ttyS0

ttyS1


Windows客户端连接可以用超级终端或者Putty


注意启动server的时候,putty就应该去连接串口了,这样才可以看到所有信息。

Press any key to continue.

Grub menu

Booting.


本来正常情况下,接下去kernelboot信息应该也会打到串口的。但是没有,确定是Xen内核的关系。【注3】好像有人已经碰到这个问题了。

系统启动起来后,过了initagetty就起来了,这个时候就可以通过串口登陆了。(/etc/securetty中需要添加ttyS0)



后记:

在做这次实验的时候开始心里很没底,因为串口从来没搞过。虽然编程时涉及过串口编程,但到我这边已经只是网络编程了。买了一个USB转串口接口,两个串口交叉线。我想要NULL modem线,店主不知道(额…), 开始不工作时一度怀疑线有问题。


还有就是开始不理解串口工作原理,我知道串口是字符设备,有啥数据得当时就去读。曾经我连了串口并开了Putty去连,界面上没输出。1)因为当时就是没数据。 2)是有时候终端需要按键来激活(比如按几下回车)


还有就是可能终端设置问题。这块我现在还不太清楚。因为终端设置涉及到有些键盘操作,比如删除。我好几次发现Backspace键没反应而重启过好几次机器。后来发现我的终端设置需要先<= = 左箭头左移然后 delete



我的主板说明书上接口图:

【注1:

C.2. Configure the BIOS to use the serial port

Many servers allow the BIOS to be configured from the serial port, especially on systems designed for rack mounting. At the moment few machines designed to be used as desktop systems allow the BIOS to be accessed from the serial port.

【注2:

Chapter 5. Configure Linux kernel

The Linux kernel is configured to select the console by passing it the console parameter. The console parameter can be given repeatedly, but the parameter can only be given once for each console technology. So console=tty0 console=lp0 console=ttyS0 is acceptable but console=ttyS0 console=ttyS1 will not work.

When multiple consoles are listed output is sent to all consoles and input is taken from the last listed console. The last console is the one Linux uses as the /dev/console device.

【注3:

阅读(14196) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~