zoukankan      html  css  js  c++  java
  • Linux Serial Console 配置小结

    为什么要使用Serial Console

    远程机器的系统管理

    通常情况,安装linux的服务器一般用来承载重要的服务,如DHCP,DNS等等。一般对于这些服务器的管理通过远程访问进行,如SSH,Telnet 等等。但是,有些时候,有些情况下,使用远程访问是无法解决问题的,如处理一些导致系统crash的错误或者bug,这是可以通过Serial console来访问这些主机就显得尤其重要。

    记录console信息

    对于内核开发者来说,有些重要的内核信息会系统出错的时候,启动的时候一闪而过。而通过Serial Console可以很方便的将这些重要的信息记录下,以供分析和排错使用。

    还要其他很多地方,如嵌入式软件开发,serial console也是必不可少的工具。

    配置Serial Console

    配置serial console一般主要有以下几个步骤

    [1] 设置BIOS, 打开serial port功能

    [2] 如果需要,需要配置bootloader(),使得bootloader可以使用serial port。

    [3] 配置kernel的启动命令行参数,通过设置console 选项。

    [4] 需要配置init进程,使其可以spawn一个进程来监控serial console上的login请求。(getty)

    [5] 其他系统工具需要配置后,使其可以同serial console以前正常工作。

    接下来,本文主要总结前4步的一般步骤。

    设置BIOS

    不同的机器BIOS配置不尽相同。但一般会有类似的选项,如:

    image

    image

    设置好相应的Port和Buad rate即可。

    设置Boot loader

    这里以grub (GNU GRUB 0.97)为例。

    serial --unit=0 --speed=115200
    terminal --timeout=10 serial console
     
    #splashimage=(hd0,0)/grub/splash.xpm.gz
    hiddenmenu
    title Red Hat Enterprise Linux Server (2.6.18-prep-yubo)
            root (hd0,0)
            kernel /vmlinuz-2.6.18-prep-yubo ro root=/dev/VolGroup00/LogVol00 rhgb quiet crashkernel=128M@16M console=tty0 console=ttyS0,115200
            initrd /initrd-2.6.18-prep-yubo.img
    title Red Hat Enterprise Linux Server (2.6.18-194.el5)
            root (hd0,0)
            kernel /vmlinuz-2.6.18-194.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet crashkernel=128M@16M console=tty0 console=ttyS0,115200
            initrd /initrd-2.6.18-194.el5.img

    在如上的例子配置文件当中,红字部分是需要注意的部分。

    serial --unit=0 --speed=115200
    terminal --timeout=10 serial console

    这两行配置文件来配置grub同时使用serial和console, 这里的使用的COM1(--unit=0,GRUB 里serial port是从0开始计数,所以--unit=0是使用com1),波特率为115200。所以,serial port和console(这是是连接的键盘和显示器)会同时等待最多—timeout ,以等待用户输入。

    配置kernel启动参数

    linux kernel通过console 参数,来配置选择哪个console, console参数可以重复出现,但是,对于每一种console技术,它仅能出现一次。

    如:

    console=tty0 console=lp0 console=ttyS0

    是有效的参数,

    但是

    console=ttyS0 console=ttyS1

    是不能接受的,因为ttyS0和ttyS1是同种console技术,都是serial。

    注意】当console参数出现多次时,最后一个console选项的值被linux kernel用来作为/dev/console设备。

    serial --unit=0 --speed=115200
    terminal --timeout=10 serial console
     
    #splashimage=(hd0,0)/grub/splash.xpm.gz
    hiddenmenu
    title Red Hat Enterprise Linux Server (2.6.18-prep-yubo)
            root (hd0,0)
            kernel /vmlinuz-2.6.18-prep-yubo ro root=/dev/VolGroup00/LogVol00 rhgb quiet crashkernel=128M@16M console=tty0 console=ttyS0,115200
            initrd /initrd-2.6.18-prep-yubo.img
    title Red Hat Enterprise Linux Server (2.6.18-194.el5)
            root (hd0,0)
            kernel /vmlinuz-2.6.18-194.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet crashkernel=128M@16M console=tty0 console=ttyS0,115200
            initrd /initrd-2.6.18-194.el5.img

    对于console=tty0 console=ttyS0,115200设置,kernel的信息会同时出现在tty0和ttyS0上,但是init进程的输出信息仅出现在ttyS0上,直到login: 提示信息出现在console和tty0上为止。

    配置getty

    需要配置inittab使得有getty进程监视ttySX, 从而可以从serial console登陆,进而对系统进行访问。

    # Run gettys in standard runlevels
    1:2345:respawn:/sbin/mingetty tty1
    2:2345:respawn:/sbin/mingetty tty2
    3:2345:respawn:/sbin/mingetty tty3
    4:2345:respawn:/sbin/mingetty tty4
    5:2345:respawn:/sbin/mingetty tty5
    6:2345:respawn:/sbin/mingetty tty6
    S0:2345:respawn:/sbin/agetty -L ttyS0 115200 vt100

    如上例红字部分,启动agetty –L 来对ttyS0(COM1)进行监视。

    如果系统使用root通过ttyS0来登陆系统,还需要对/etc/securetty进行修改。

    tty9
    tty10
    tty11
    ttyS0

    红字部分为添加的内容。

    到这里,serial console的配置就基本完成了。

    参考:

    【1】http://tldp.org/HOWTO/Remote-Serial-Console-HOWTO/

    【2】Linux kernel Documentaion “kernel-src/Documentation/serial-console.txt”

     

  • 相关阅读:
    Validation failed for one or more entities. See 'EntityValidationErrors' property for more details
    Visual Studio断点调试, 无法监视变量, 提示无法计算表达式
    ASP.NET MVC中MaxLength特性设置无效
    项目从.NET 4.5迁移到.NET 4.0遇到的问题
    发布网站时应该把debug设置false
    什么时候用var关键字
    扩展方法略好于帮助方法
    在基类构造器中调用虚方法需谨慎
    ASP.NET MVC中商品模块小样
    ASP.NET MVC中实现属性和属性值的组合,即笛卡尔乘积02, 在界面实现
  • 原文地址:https://www.cnblogs.com/yuboyue/p/2251288.html
Copyright © 2011-2022 走看看