为Linux系统配置serial console
为Linux系统配置serial console
1. 准备工作
1.1. 关于serial console
Console是一个输出系统管理信息的文本输出设备,这些信息来自于内核,系统启动和系统用户,serial console就是串口作为输出终端设备,是这些信息可以通过串口在远程的终端上显示。
配置一个serial console大致包括五项内容:
? 配置BIOS使用serial console(可选);
? 配置Bootloader使用serial console(可选);
? 配置内核使用serial console
? 在系统启动时运行一个支持serial console登录的程序
? 一些其他系统配置,使这些功能支持serial console,或者防止它们扰乱serial console
1.2. 串口线
使用RS232方式的DB9串口线,信号连接如下:
Signal ground ------------------ Signal ground
Receive data ------------------ Transmit data
Transmit data ------------------ Receive data
Ready to send ------------------ Clear to send
Clear to send ------------------ Ready to send
ata terminal ready -------------+--- Data carrier detect
|
+--- Data set ready
Data carrier detect ----+---------------- Data terminal ready
|
Data set ready -----+
1.3. 串口参数的设置
选择的串口是COM1,设备名为ttyS0,波特率为9600,8位数据位,无奇偶校验,1位停止位。
2. 配置BIOS
有些BIOS支持serial console,可以在serial console显示BIOS启动信息,这需要在BIOS中配置。
3. 配置Bootloader
LILO、GRUB和SYSLINUX都支持serial console。
3.1. GRUB的配置
GRUB的配置文件是/boot/grub目录下的grub.conf,在配置文件的开始处添加:
serial --unit=0 --speed=9600 --word=8 --parity=no --stop=1
terminal --timeout=10 serial console
Serial命令用于设置串口的参数:
--unit:串口设备,0就表示ttyS0,如果是ttyS1就要设为1;
--speed:波特率;
--work:数据位;
--parity:奇偶校验位;
--stop:停止位。
Terminal命令用于设置终端的类型
--timeout:等待时间,单位是秒
4. 配置Kernel
Kernel的console类型可以通过console参数选择,console配置的语法如下:
console=ttyS<serial_port>[,<mode>]
console=tty<virtual_terminal>
console=lp<parallel_port>
console=ttyUSB[<usb_port>[,<mode>]
其中的ttyS就是串口设备,mode表示串口的参数;tty表示虚拟终端。
每个console类型指南设置一个设备,例如,可以设置为console=tty0 console=lp0 console=ttyS0,但是设为 console=ttyS0 console=ttyS1就是错误的。
如果没有设置console参数,内核默认使用虚拟终端,即tty0,使用组合键Ctrl+Alt+F1可以切换到tty0。如果你的电脑有显示设备,最好将它设为console,即console=tty0。
根据我的设备情况可以设置为:
console=tty0 console=ttyS0,9600n8
Console参数需要用bootloader在内核启动时传递给内核,www.bkjia.com对于GRUB,需要修改grub.conf文件,将参数添加到kernel命令后面即可,例如;
- title Red Hat Linux (2.4.9-21)
- root (hd0,0)
- kernel /vmlinuz-2.4.9-21 ro root=/dev/hda6 console=tty0 console=ttyS0,9600n8
- initrd /initrd-2.4.9-21.img
5. 配置getty
getty会监控和等待一个连接,然后配置串口连接,发送/etc/issue的内容,并且要求输入登录名和密码,然后开始登录,如果登录失败,getty会返回等待状态。
getty的另一项工作是设置TERM变量的值,以指定所连接的终端的类型。
常用的getty有四个版本:
getty:传统的getty,需要配置文件/etc/gettydefs
agetty:无需配置文件,直接通过命令行传递参数
mgetty:支持modem的getty,需要配置文件
minigetty:精简版的getty,不支持serial console
RedHat9自带agetty和mgetty,在/etc/inittab文件中默认使用mgetty,在该文件中添加:
- co:2345:respawn:/sbin/agetty -h -t 60 ttyS0 9600 vt102
-t 60 : 60秒内无操作,agetty将会返回等待状态。
-h : 使用硬件流控制(CTS/RTS握手)
|
评论暂时关闭