Setup Serial Console with 'GRUB' bootloader
时间:2005-04-12 来源:wenzk
Last Updated: March/07/2002
Errors/Comments: [email protected] Setup Serial Console with 'GRUB' bootloader:
# 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
============================================================
This will only define serial port definition but won't do anything useful yet. Above is defining Serial port as (COM1), for COM2 specify --unit=1 and so on. After this define terminal for throwing display.
terminal --timeout=15 console serial
Here we are defining 15 seconds timeout and both console(Monitor or tty0) and serial port (ttyS0 or COM1) as display. For 15 seconds it will allow to select either Monitor or Serial port selection depending upon where you press key. Otherwise after 15 seconds it will select first entry ('console' ) in above example as primary display device and show grub menu of OS selection there.
:Single user mode for Monitor
kernel /boot/vmlinuz-2.4.17 ro root=/dev/sda3 console=ttyS0 console=tty0
^^^^^^^^^^
Last Entry
:Single user mode for Serial Port
kernel /boot/vmlinuz-2.4.17 ro root=/dev/sda3 console=tty0 console=ttyS0
^^^^^^^^^^^
Last Entry
In order to login as single user mode, at Grub boot selection menu, select kernel image by arrow (UP, DOWN keys) and then hit 'e' key to edit, which will show grub entry for image, select kernel line and append word 'single' and <Enter>,
kernel /boot/vmlinuz-2.4.17 ro root=/dev/sda3 console=tty0 console=ttyS0 single
press 'b' to boot this image now. This edit is only temporary and won't overwrite /etc/grub.conf. By this way you can always edit grub entries for boot time temporarily.
S0:2345:respawn:/sbin/mgetty -b -r -s 9600 -p "Serial Console Login: " ttyS0
This will run mgetty in as direct line (-r) (i.e no modem chat initiated), in block mode (-b), with speed as 9600 baud (-s 9600), login prompt as specified by -p option and device is ttyS0 (Serial port device /dev/ttyS0). Either reboot machine or type 'init q' to reread inittab file and that should start login process on Serial console.
Errors/Comments: [email protected] Setup Serial Console with 'GRUB' bootloader:
- Redhat 7.2 onwards and other Linux OS give grub (GRand Unified Boot Loader) as default boot loader. Follow steps below to setup serial console. Most likely grub is compiled with Serial console support for your distribution, if not compile with Serial port support.
- Example: /etc/grub.conf with Serial port support.
# 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
============================================================
- Avoid any splash image, so comment out splash line first. You need kermit or some other serial program (Hyperterminal etc) which supports vt100 emulation. If you are using GUI (X11), 'xterm' do support such. You other GUI terminals may not support true vt100. You will need 'Null Modem' cable to connect serial ports of computers.
- Define Serial port first:
This will only define serial port definition but won't do anything useful yet. Above is defining Serial port as (COM1), for COM2 specify --unit=1 and so on. After this define terminal for throwing display.
terminal --timeout=15 console serial
Here we are defining 15 seconds timeout and both console(Monitor or tty0) and serial port (ttyS0 or COM1) as display. For 15 seconds it will allow to select either Monitor or Serial port selection depending upon where you press key. Otherwise after 15 seconds it will select first entry ('console' ) in above example as primary display device and show grub menu of OS selection there.
- Now you can pass kernel option in 'kernel' line (console=??) to throw kernel messages to selected devices. You can select both Monitor and Serial port to get kernel messages as in above example.
- Single User Mode Login: Although you can select both Monitor & Serial port to get kernel message, but only last selected 'console=??' in kernel line will be available for OS messages and keyboard entry in single user mode. So it is desirable to set two images so that you can login as single user on either consoles. Notice:'console=??' entries sequence are swapped in two kernel entries in our example as last defined 'console=???' will be selected as primary console here.
:Single user mode for Monitor
kernel /boot/vmlinuz-2.4.17 ro root=/dev/sda3 console=ttyS0 console=tty0
^^^^^^^^^^
Last Entry
:Single user mode for Serial Port
kernel /boot/vmlinuz-2.4.17 ro root=/dev/sda3 console=tty0 console=ttyS0
^^^^^^^^^^^
Last Entry
In order to login as single user mode, at Grub boot selection menu, select kernel image by arrow (UP, DOWN keys) and then hit 'e' key to edit, which will show grub entry for image, select kernel line and append word 'single' and <Enter>,
kernel /boot/vmlinuz-2.4.17 ro root=/dev/sda3 console=tty0 console=ttyS0 single
press 'b' to boot this image now. This edit is only temporary and won't overwrite /etc/grub.conf. By this way you can always edit grub entries for boot time temporarily.
- Last entry allows Windows partition to boot from Grub loader.
- Attaching login: prompt for Serial console: So far all you got is kernel and OS messages on console (tty0{Monitor} or ttyS0{Serial Port}). This can allow only single user mode on Serial port. But when you go in multi-user mode, Serial line will appear blank till you attach login process to Serial line. You can use mgetty(8) program for this. See http://www.rpmfind.net for mgetty(8) program.
S0:2345:respawn:/sbin/mgetty -b -r -s 9600 -p "Serial Console Login: " ttyS0
This will run mgetty in as direct line (-r) (i.e no modem chat initiated), in block mode (-b), with speed as 9600 baud (-s 9600), login prompt as specified by -p option and device is ttyS0 (Serial port device /dev/ttyS0). Either reboot machine or type 'init q' to reread inittab file and that should start login process on Serial console.
- If you setup mgetty(8) process as above, even if you select Monitor as your display console (which allows single user and OS messages on Monitor) still you will get Serial port login: on serial line. This is because after OS boot, mgetty will run irrespective of any selection and wait for login.
- To allow root login on Serial console, add Serial device entry (ttyS0) in your /etc/securetty file. Otherwise you need to login as normal user and su for root.
相关阅读 更多 +