目的: 台机已经装好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.el5和2.6.18-92.1.22.el5xen 客户端: Win dows XP SP3 IBM OEM. 安装USB转串口驱动。 需要把输出定向到串口,一般有下面几处:
BIOS中的设置
GRUB设置
/etc/inittab 设置
/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可以在COM1和COM2登陆。 在/etc/securetty中添加: ttyS0 ttyS1 Windows客户端连接可以用超级终端或者Putty。
注意启动server的时候,putty就应该去连接串口了,这样才可以看到所有信息。 Press any key to continue.
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】: http://tldp.org/HOWTO/Remote-Serial-Console-HOWTO/configure-kernel.html
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】: https://vb.serverknecht.de/showthread.php ?t=129174