您的位置:首页 > 其它

为GRUB引导程序安装串口输出

2010-10-02 22:08 239 查看
Redhat及很多Linux现在使用grub作为默认的引导程序。按照以下步骤建立串口控制台输出。

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You do not have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /, eg.
#          root (hd0,2)
#          kernel /boot/vmlinuz-version ro root=/dev/sda3
#          initrd /boot/initrd-version.img
#boot=/dev/sda
#
#default image is First(0) image from title list
default=0
#
#This is grub Menu timeout(sec)
timeout=30
#
###############################################
## Serial/Console setup
###############################################
# Avoid splashing any GUI!!
# splashimage=(hd0,2)/boot/grub/splash.xpm.gz
#
# Setup serial (COM1) here with baudrate 9600
# use --unit=1 (for COM2) and so on
serial --unit=0 --speed=9600
#
# Now setup terminal as both Serial Line(/dev/ttyS0) and
# Monitor Console(/dev/tty0) depending upon where you press key
# with in timeout (15 sec) period. Otherwise first entry
# (console(Monitor)=>tty0) is selected here.
terminal --timeout=15  console serial
# In images section below, we are selecting two consoles
# (Serial(ttyS0) and Monitor(tty0) here. But in case of single user mode,
# keyboard entry is allowed from last selected console in 'kernel' line below.
# So we need to setup two different images so that we should be able to
# login in single usermode from any console depending upon selection at boot time.
# But in both cases  kernel message (not OS message) will go to both consoles.
#
#Allow Single user mode from Console(Monitor)
title Red Hat Linux (2.4.17) !!! MONITOR !!!
root (hd0,2)
kernel /boot/vmlinuz-2.4.17 ro root=/dev/sda3 console=ttyS0 console=tty0
#Allow Single user mode from Serial Port(ttyS0).
title Red Hat Linux (2.4.17) !!! SERIAL CONSOLE !!!
root (hd0,2)
kernel /boot/vmlinuz-2.4.17 ro root=/dev/sda3 console=tty0 console=ttyS0
#Booting Windows through Grub.
title Win2000 Professional
root        (hd0,1)
makeactive
chainloader +1
# For loading DOS if Windows NT is installed
# chainload /bootsect.dos


为了取消splash image,所以注释掉了splash那一行。你需要kermit或者其他能够支持vt100的串口程序(例如Hypertermianl等)来支持此功能。如果你用的GUI(X11), 'xterm'支持此功能。其他GUI终端可能不支持vt100,你需要'Null Modem'电缆来连接电脑的串口

首先定义串口:

serial --unit=0 --speed=9600

这句只是简单定义了串口号,不会有实质性作用。其中定义了串口COM1,如果要使用串口COM2,要定义--unit=1。之后要定义终端显示:

terminal --timeout=15 console serial

这里定义了两个终端用于显示grub的菜单,显示器(console:tty0)和串口(serial:ttyS0)。用户有15秒的时间用于选择,选择的依据是用户在哪个终端按下任意键。否则,15秒过后,程序会自动选择第一个作为菜单输出。上面的例子中,显示器将作为首要输出设备用于显示可选择os的grub菜单。

接下来是内核选项行('kernel')。该行可以定义内核信息的输出设备。在上面的例子中,用户能选择显示器和终端作为信息输出端。

kernel /boot/vmlinuz-2.4.17 ro root=/dev/sda3 console=ttyS0 console=tty0

单用户模式(single)登陆:虽然你能够同时用显示器和串口获得内核信息,但是只有最后一个选项(console=??)能够在单人模式下作为输出和输入的设备。所以,这里设置了两个image选项,使得单人模式下能够用到合适的选项。注意:'console=??'参数项在两个内核选项中互换了位置,因为只有最后定义的'console=??'参数项才能被选作主要设备。

显示器的单人模式:

kernel /boot/vmlinuz-2.4.17 ro root=/dev/sda3 console=ttyS0 console=tty0

串口单人模式:

kernel /boot/vimlinuz-2.4.17 ro root=/dev/sda3 console=tty0 console=ttyS0

为了以单用户模式登陆,在grub选择菜单中,使用up,down按钮选择一个内核镜像,然后按'e'键进入编辑模式,在kernel行的最后加入'single',按Enter后,再按'b'键即能从该镜像启动,这次编辑编辑只是暂时的,不会保存到/boot/grub/menu.lst中。

菜单中最后一项是用于引导windows系统的

为串口控制台提供login提示输出:到目前为止,所有获得的信息都是grub和内核的。这些只是让你在单人模式下能够从串口登陆,但是在多用户模式下,将不能获得login程序的输出,也就是说没有用于用户登陆提示符出现。在此,应该使用mgetty程序 http://www.rpmfind.net,在/etc/inittab中加入如下一行:

# Add a tty to the serial console

s0:2345:respawn:/sbin/mgetty -b -r -s 9600 -p "Serial Console Login:" ttyS0

如果你按上面设置了mgetty,即使你选择了显示器作为显示控制台,你仍然能够在串口上登陆。这是因为在系统启动后,mgetty将作为一个独立的程序运行,并在ttyS0上等待登陆。

为了让root在串口上登陆,应该在/etc/seruretty上添加该串口(ttyS0),否则你只能先以普通用户登陆,并使用su成为root身份。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: