使用串口管理linux
本文可自由转载,但请遵循“署名-非商业用途-保持一致”的创作共用协议。 永久链接:JoeCen's 小猫窝-----------------------------
家里有一台主机打算用来作网关,但又不想为其配显示器,使用ssh又有很大局限,于是便想到了用serial口控制该网关。
使用串口管理比起ssh来说有几个好处:
第一,不需ip,即网络断掉或服务停了也可以进行管理。
第二,可以显示linux开机时的信息,让我们可以知道能力出了错。
第三,一个串口只能登陆一个用户,可以在无干扰下进行工作。
当然,我并不是说ssh不好,只不过对于一台就在身旁的机器来说,使用串口是方便一点的!
好了,闲话少说:
第一步:让串口可以登陆。
在/etc/inittab中的
"# Run gettys in standard runlevels"项加上
"co:2345:respawn:/sbin/agetty ttyS0 9600 vt100"一行。
目的是能开放一个ttyS0,让其能登陆本机。
第二步:让root可以在串口登陆。
在/etc/securetty的末尾加上"ttyS0"。
这样就可以让root通过串口登陆。
第三步:让串口显示开机信息。
如果是用lilo的话,在/etc/lilo.conf中加入:
serial=1,9600n8
append="console=ttyS0,9600"
两句。这样,在开机的时候,开机的信息就会定向到串口中来。
如果是用grub,那我这里有一个示例:
| # 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/hda2 # initrd /initrd-version.img #boot=/dev/hda default=0 timeout=3 serial --unit=0 --speed=9600 terminal --timeout=3 serial console title Red Hat Linux (2.4.20-8) root (hd0,0) kernel /vmlinuz-2.4.20-8 ro root=LABEL=/ console=ttyS0,9600n81 initrd /initrd-2.4.20-8.img |
然后,我们还要找些工具来连接串口,一条串口线是不可少的。
最后要找一个软件来进行连接,当然,我们可以用windows自带的超级终端,但一般我是用SecureCRT。
如果是在linux下管理:
执行: #xminicom
xminicom是minicom的图形界面,跟minicom几乎一样,作用跟windows下的HyperTerminal很接近
首先设置xminicom
依次进入 cOfigure minicom(alt+o)
Serial Port Setup
修改 A:Serial Device -->在本次实例中为/dev/ttyS0
E:Bps/Par/Bits/ -->这里主要是设置波特率,本例为115200
Save Setup as df1
Exit