![]() | ![]() |
|
|
Remote Serial Console HOWTOGlen TurnerAustralian Academic and Research Network Mark F. Komarinskiv2.6 2003-03-31
An RS-232 serial console allows Linux to be controlled from a terminal or modem attached to an asynchronous serial port. The monitor, mouse and keyboard are no longer required for system administration. Serial consoles are useful where Linux systems are deployed at remote sites or are deployed in high-density racks. This HOWTO describes how to configure Linux to attach a serial console. DedicationGlen Turner would like to thank his family for allowing him to work on this project for the surprisingly large number of evenings which it took to write this HOWTO. Thank you Karen, Kayla and Ella.
Chapter 1. Introduction
1.1. What is a console?The console is the text output device for system administration messages. These messages come from the kernel, from the init system and from the system logger. On modern small computers the console is usually the computer's attached monitor and keyboard. On many older computers the console is an RS-232 link to a terminal such as a DEC VT100. This terminal is in a locked room and is continually observed by the minicomputer's operators. Large systems from Sun, Hewlett-Packard and IBM still use serial consoles. It is usually possible to login from the console. A login session from the console is treated by many parts of the operating system as being more trustworthy than a login session from other sources. Logging in as the root super-user from the console is the Command Line of Last Resort when faced with a misbehaving system. 1.2. Why use a serial console?For the average user a serial console has no advantage over a console offered by a directly attached keyboard and screen. Serial consoles are much slower, taking up to a second to fill a 80 column by 24 line screen. Serial consoles generally only support non-proportional ASCII text, with limited support for languages other than English. A new terminal can be more expensive than an old PC. There are some scenarios where serial consoles are useful. These are:
Unlike minicomputer systems, the IBM PC was not designed to use a serial console. This has two consequences. Firstly, Power On Self-Test messages and Basic Input/Output System (BIOS) messages are sent to the screen and received from the keyboard. This makes it difficult to use the serial port to reconfigure the BIOS and impossible to see Power On Self-Test errors. An increasing number of manufacturers of rackable server equipment are altering their BIOSs to optionally use the RS-232 port for BIOS configuration and test messages. If you are buying a machine specifically for use with serial console you should seek this feature. If you have an existing machine that definitely requires access to the BIOS from the serial port then there are hardware solutions such as PC Weasel 2000. Secondly, the RS-232 port on the IBM PC is designed for connecting to a modem. Thus a null modem cable is needed when connecting the PC's serial port to a terminal. 1.3. Alternative meanings of "console"Some authors use the word "console" to refer to the keyboard and monitor that are attached to the system unit. This is described as a "physical console" by some Linux documentation. The console where system messages appear is described as the "logical console" by that documentation. As an illustration of the difference, X Windows should start on the physical console but system messages issued by failures when starting X Windows should be written to the logical console. To avoid confusion this HOWTO uses the word "console" to describe the place where system messages are printed. This HOWTO uses the phrase "attached monitor and keyboard" rather than the confusing words "physical console". These distinctions are also made in the naming of devices. The device /dev/console is used to send messages to the console. The symbolic link /dev/systty points to the device which is used by the attached monitor and keyboard, often /dev/tty0. 1.4. Configuration overviewThere are five major steps to configuring a serial console.
Examples in this HOWTO are from Red Hat Linux versions 7.1 through to 7.3 (released 2001 through to 2002). The maintainer would appreciate updates when new versions of Red Hat Linux appear. The maintainer would very much appreciate examples for Linux distributions that are dissimilar to Red Hat Linux; particularly Debian GNU/Linux and Slackware Linux. All contributors are acknowledged in Section G.3. Chapter 2. PreparationThis chapter ensures that access the existing console can be restored should the serial console fail to start. This chapter then discusses the selection of the RS-232 port and its parameters. 2.1. Create fallback positionGood system administrators always have a viable fallback plan to cope with failures. A mistake configuring the serial console can make both the serial console and the attached monitor and keyboard unusable. A fallback plan is needed to retrieve console access. Many Linux distributions allow boot diskettes to be created. Writing a boot diskette before altering the console configuration results in a boot diskette that passes good parameters to the kernel rather than parameters that may contain an error. Under Red Hat Linux a boot diskette is created by determining the running kernel version and then using that version to create the boot diskette Under Debian GNU/Linux the boot diskette is created by determining the version of the running kernel and then using that version to write the boot diskette An alternative fallback position is have a rescue diskette with the machine. A common choice is Tom's root boot. 2.2. Select a serial port2.2.1. Serial port namesLinux names its serial ports in the UNIX tradition. The first serial port has the file name /dev/ttyS0, the second serial port has the file name /dev/ttyS1, and so on. This differs from the IBM PC tradition. The first serial port is named COM1:, the second serial port is named COM2:, and so on. Up to four serial ports can be present on a IBM PC/AT computer and its successors. Most boot loaders have yet another naming scheme. The first serial port is numbered 0, the second serial port is numbered 1, and so on. If your distribution of Linux uses the devfs device manager then the serial ports have yet another name. The first serial port is /dev/tts/0, the second serial port is /dev/tts/1, and so on. The result is that the first serial port is labeled COM1: on the chassis of the IBM PC; is known as /dev/ttyS0 to Linux; is known as /dev/tts/0 to Linux when configured with devfs; and is known as port 0 to many boot loaders. The examples in this HOWTO use this first serial port, as that is the serial port which most readers will wish to use. 2.2.2. Cannot share interrupt used for console's serial portWhen used for a console the serial port cannot share an interrupt with another device. The IBM PC devices are usually installed as shown in Table 2-2. If you use the serial port /dev/ttyS0 for the console then you should avoid sharing interrupt 4 by not installing a serial port /dev/ttyS2 in your PC. If /dev/ttyS2 cannot be physically removed then disable it using the setserial command, as shown in Figure 2-1. Table 2-2. Interrupts used for IBM PC/AT RS-232 ports
Figure 2-1. Using the setserial command in /etc/rc.serialto disable the serial port /dev/ttyS2
Reading the source code suggests that the interrupt-sharing constraint applies to all computer architectures, not just Intel Architecture-32. 2.3. Select a serial speed and parametersThis HOWTO does not discuss the RS-232 standard, which is formally known as ANSI/TIA/EIA-232-F-1997 Interface Between Data Terminal Equipment and Data Circuit-Terminating Equipment Employing Serial Data Interchange. For an explanation of "bits per second", "start bits", "data bits", "parity", "stop bits" and "flow control" refer to the Serial-HOWTO and the Modem-HOWTO. The description of the command syntax for setting the serial parameters in the kernel, boot loaders and login applications uses the following variables which describe RS-232 parameters.
At present the RS-232 status lines are ignored by the kernel. A kernel message will be printed even if Data Carrier Detect and Data Set Ready are not asserted. This leads to the kernel messages being sent to a modem which is idle and in command mode. The console's slack interpretation of CTS, DSR and DCD makes it impossible to connect a serial console to an RS-232 multi-drop circuit. Multi-drop circuits have more than two computers on the circuit; they are traditionally four-wire, satelite or wireless services. The Linux kernel uses the syntax in Figure 2-7 to describe the serial parameters. Many boot loaders use a variation of the syntax used by the Linux kernel. Figure 2-7. Syntax for kernel serial parameters, in extended Backus-Naur form <mode> ::= <speed><parity><data><flow_control> Note that <mode> does not include <stop>. The kernel assumes the number of stop bits to be one. This shortcoming needs to be considered when deploying long RS-232 cables. Most boot loaders default to 9600n8. A common default found on older terminals is 9600e7. Use 9600n8 if possible, as this is the default for most Linux software and modern devices. This HOWTO always configures the serial speed and parameters, even where not strictly necessary. This is so that people configuring parameters other than the recommended and common default value 9600n8 will know what to alter. 2.4. Configure the modem or the null-modem cableIf a modem is used, configure it to be a dumb modem at the port speed selected in Section 2.3. If the modem accepts Hayes AT commands see Chapter 12 to dumb-down the modem. Alternatively if a terminal and a null-modem cable are used see Section 11.3, which discusses the pinout of the null modem cable. 2.5. Configure the terminal or the terminal emulatorConfigure the terminal to match the serial parameters. The data bits, parity bits and stop bits must match. If a modern "smart" modem is used then the bit speeds need not match. If a dumb modem or a null modem cable is used then the bit speeds must match. Set CTS/RTS handshaking on, DTR/DSR handshaking off and XON/XOFF handshaking off. Your equipment may call CTS/RTS handshaking or DTR/DSR handshaking "hardware handshaking" and may call XON/XOFF handshaking "software handshaking". Set automatic line wrapping on. This allows all of a long console message to be read. Set the received end of line characters to CR LF (carriage return then line feed). Set the transmitted end of line characters to just CR (carriage return). If you are using a terminal emulator then it is best to choose to emulate the popular DEC VT100 or VT102 terminal. Later terminals in the DEC VT range are compatible with the VT100. If this terminal is not available then try to emulate another terminal that implements ANSI X3.64-1979 Additional Controls for Use with American National Standard Code for Information Interchange (or its successor ISO/IEC 6429:1992 ISO Information technology — Control functions for coded character sets). For example, many emulators have a terminal called ANSI BBS which uses the IBM PC character set, the 16 IBM PC colors, a 80 column by 25 line screen and a selection of X3.64-1979 control sequences. See the Text-Terminal-HOWTO for much more information on configuring terminals. Chapter 3. Optionally configure the BIOSSome BIOSs provide support for serial consoles. If your computer's BIOS is one of these you should investigate the extent of the support provided. Depending upon the extent of serial console support you may not need to explicitly configure the boot loader to use the serial port. The contributors to this HOWTO have encountered the following styles of BIOS support for serial consoles.
If you need to configure the boot loader to use the serial port then continue to Chapter 4. Otherwise go directly to Chapter 5 to configure the kernel; this is done by configuring the boot loader to pass boot parameters to the Linux kernel. Chapter 4. Configure the boot loaderWhen a PC boots the CPU it runs code from Read-Only Memory. This code is the Basic Input/Output System, or BIOS. The BIOS then loads a boot loader from the Master Boot Record of the first hard disk.[4] In turn, the boot loader reads the operating system into memory and then runs it.[5] Neither the BIOS nor the boot loader are strictly necessary. For example, there are versions of Linux that run directly from the flash memory which usually contains the BIOS. Linux was originally designed to run without an interactive boot loader, by placing the kernel at particular sectors of the disk. The benefits of using a boot loader are:
For these reasons systems administrators want to be able to interactively control the boot loader from the serial console. LILO, GRUB and SYSLINUX are popular boot loaders for IBM PCs. Find which of these boot loaders your Linux installation uses and then follow the instructions for your boot loader in the following section. 4.1. Configure the LILO boot loaderLILO is the Linux Boot Loader used on Intel machines. Other boot loaders for Intel machines exist, common alternatives are GRUB and SYSLINUX. Equivalents to LILO exist for other processor architectures, their names are usually some play upon "LILO". LILO is documented in the lilo(8) and lilo.conf(5) manual pages; the LILO Generic boot loader for Linux … User's Guide found in the file /usr/share/doc/lilo…/doc/User_Guide.ps; and the LILO mini-HOWTO. The LILO configuration is kept in the file /etc/lilo.conf. The first part of the file applies to all images. The following parts are image descriptions for each kernel. Set LILO to use the serial port. The syntax of the serial line parameters follows that used by the kernel. Where the variables are the same as used by the kernel (shown in Figure 2-7) and: Our examples use /dev/ttyS0, which LILO knows as port 0. Figure 4-3. LILO boot loader sample configuration
The parameters restricted and password are used to avoid someone dialing in, booting the machine, and stepping around the Linux access permissions by typing: The password should be good, as it can be used to gain root access. The LILO password is stored in plain text in the configuration file, so it should never be the same as any other password. The permissions on the configuration file should be set so that only root can read /etc/lilo.conf. LILO has an option to display a boot message. This does not work with serial consoles. Remove any lines like: LILO is now configured to use the serial console. The kernels booted from LILO are yet to be configured to use the serial console. 4.2. Configure the GRUB boot loaderGRUB is a boot loader designed to boot a wide range of operating systems from a wide range of filesystems. GRUB is becoming popular due to the increasing number of possible root filesystems that can Linux can reside upon. GRUB is documented in a GNU info file. Type info grub to view the documentation. The GRUB configuration file is /boot/grub/menu.lst. Some distributions use another configuration file; for example, Red Hat Linux uses the file /boot/grub/grub.conf. GRUB configuration files are interpreted. Syntax errors will not be detected until the machine is rebooted, so take care not to make typing errors. Edit the GRUB configuration file and remove any splashimage entries. If these entries are not removed GRUB 0.90 behaves very oddly, transferring control between the serial console and the attached monitor and keyboard. If there is not already a password command in the GRUB configuration file then create a hashed password, see Figure 4-4. The password should be good, as it can be used to gain root access. Figure 4-4. Using md5crypt to create a hashed password for GRUB
Use that hashed password in the GRUB configuration file, this is shown in Figure 4-5. Define the serial port and configure GRUB to use the serial port, as shown in Figure 4-6. Figure 4-6. GRUB configuration for serial console
--unit is the number of the serial port, counting from zero, unit 0 being COM1. Note that the values of --parity are spelt out in full: no, even and odd. The common abbreviations n, e and o are not accepted. If there is mysteriously no output on the serial port then suspect a syntax error in the serial or terminal commands. If you also want to use and attached monitor and keyboard as well as the serial port to control the GRUB boot loader then use the alternative configuration in Figure 4-7. Figure 4-7. GRUB configuration for serial console and attached monitor and keybaord console
When both the serial port and the attached monitor and keyboard are configured they will both ask for a key to be pressed until the timeout expires. If a key is pressed then the boot menu is displayed to that device. Disconcertingly, the other device sees nothing. If no key is pressed then the boot menu is displayed on the whichever of serial or console is listed first in the terminal command. After the timeout set by the timeout the default option set by default is booted. Figure 4-8. GRUB output to default device when configured for serial and attached monior output
If you are not using a VT100 terminal then the cursor keys may not work to select a GRUB menu item. The instructions shown in Figure 4-8 are literally correct: Use the ^ and v keys means that the caret key (Shift-6) moves the cursor up and letter vee key (V) moves the cursor down. Note when configuring GRUB that there are two timeouts involved. Press any key to continue is printed for terminal --timeout=10 seconds, waiting for someone on the keyboard or terminal to press a key to get the input focus. Then the menu is displayed for timeout 10 seconds before the default boot option is taken. If the terminal attached to the serial port is not a real or emulated VT100, then force GRUB to use it's command line interface. This interface is much more difficult to use than GRUB's menu interface; however, the command line interface does not assume the VT100's terminal language. Figure 4-9. GRUB configuration for command line interface for terminals other than VT100
This HOWTO does not discuss the use of GRUB's command line. It is far too complex and error-prone to recommend for use on production machines. Wizards will know to consult GRUB's info manual for the commands required to boot the kernel. GRUB's menu's can be edited interactively after P is pressed and the password supplied. A better approach is to add menu items to boot the machine into alternative run levels. A sample configuration showing a menu entry for the default run level and an alternative menu entry for single user mode (run level s) is shown in Figure 4-10. Remember to use the lock command to require a password for single user mode, as single user mode does not ask for a Linux password. Figure 4-10. Adding a single user mode option to the GRUB menu
File names in the kernel and initrd commands are relative to the GRUB installation directory, which is usually /boot/grub. So /vmlinuz-2.4.9-21 is actually the file /boot/grub/vmlinuz-2.4.9-21. GRUB is now configured to use the serial console. The kernels booted from GRUB are yet to be configured to use the serial console. 4.3. Configure the SYSLINUX boot loaderSYSLINUX is a boot loader that is installed on a MS-DOS floppy disk. As directed by it's configuration file \SYSLINUX.CFG it will load one of the files from the floppy disk as a Linux kernel. SYSLINUX presents a simple text interface that can be used to select between canned configurations defined in the configuration file and can be used to add parameters to the kernel. ISOLINUX and PXELINUX are variants of SYSLINUX for CD-ROMs and Intel's Preboot Execution Environment. SYSLINUX supports a variety of serial port speeds, but it only supports eight data bits, no parity and one stop bit. SYSLINUX supports the serial ports COM1: through to COM4:, as with most boot loaders these are written as port 0 through to port 3. For SYSLINUX to support a serial console add a new first line to \SYSLINUX.CFG: Figure 4-11. Syntax of SYSLINUX serial command, in EBNF serial <space> <serial_port> [ <space> <speed> [ <space> <syslinux_flow_control> ] ] The variables are the same as used by syntax descriptions in Figure 2-7 and Figure 4-2 plus those in Figure 4-12. Figure 4-12. SYSLINUX serial EBNF variables <space> ::= ‘ ’ The <syslinux_flow_control> variable controlling the RS-232 status and flow control signals is optional. If your null-modem cable does not present any status or handshaking signals then do not use it. The value of <syslinux_flow_control> is calculated by adding the hexadecimal values for the desired flow control behaviours listed in Table 4-1. The behaviours for a correctly-wired null-modem cable or a correctly configured modem are marked "Required for full RS-232 compliance" in the table. The sum of these values is 0xab3. Table 4-1. SYSLINUX flow control bitmap
Our preferred configuration of 9600bps, port 0, full RS-232 status signals and CTS/RTS flow control is written as:
If you have a null modem cable with no RS-232 status signals and no flow control then use: Remember that the serial command must be the first line in \SYSLINUX.CFG. Chapter 5. Configure Linux kernelThe Linux kernel is configured to select the console by passing it the console parameter. The console parameter can be given repeatedly, but the parameter can only be given once for each console technology. So console=tty0 console=lp0 console=ttyS0 is acceptable but console=ttyS0 console=ttyS1 will not work. When multiple consoles are listed output is sent to all consoles and input is taken from the last listed console. The last console is the one Linux uses as the /dev/console device. The syntax of the console parameter is given in Figure 5-1. Figure 5-1. Kernel console syntax, in EBNF console=ttyS<serial_port>[,<mode>] <serial_port> is the number of the serial port. This is defined in Figure 4-2 and discussed in Section 2.2. The examples in this HOWTO use the first serial port, giving <serial_port> the value 0, which in turn gives kernel parameter console=ttyS0. If you are using the devfs device filesystem with your Linux installation the kernel parameter for the first serial port is still ttyS0, even though the first serial device is no longer known as /dev/ttyS0 but as /dev/ttys/0. <mode> is defined in Figure 2-7 and is discussed in Section 2.3. The examples in this HOWTO use 9600 bits per second, one start bit, eight data bits, no parity, one stop bit, and no CTS/RTS flow control giving <mode> the value of 9600n8. When the current kernel flow control bugs are corrected this HOWTO will once again recommend the value 9600n8r. <usb_port> can specify the address of a USB dongle containing a serial port to be used as a serial console.[6] For example, the serial port console=ttyS0,9600n8 when moved to a USB serial dongle would be written as console=ttyUSB0,9600n8. The USB subsystem is started rather late in the boot process, console messages printed during boot before the USB subsystem is loaded will be lost. With no console parameter the kernel will use the first virtual terminal, which is /dev/tty0. A user at the keyboard uses this virtual terminal by pressing Ctrl-Alt-F1. If your computer contains a video card then we suggest that you also configure it as a console. This is done with the kernel parameter console=tty0. For computers with both a video card and a serial console in the port marked "COM1:" this HOWTO suggests the kernel parameters: Kernel messages will appear on both the first virtual terminal and the serial port. Messages from the init system and the system logger will appear only on the first serial port. This can be slightly confusing when looking at the attached monitor: the machine will appear to boot and then hang. Don't panic, the init system has started but is now printing messages to the serial port but is printing nothing to the screen. If a getty has been configured then a login: prompt will eventually appear on the attached monitor. For PCs without a video card, this HOWTO suggests the kernel parameters: These parameters are passed to the booting kernel by the boot loader. Next we will configure the boot loader used by your Linux installation to pass the console parameters to the kernel. 5.1. Configure Linux kernel using LILOFor each image entry in /etc/lilo.conf add the line: Figure 5-4. Recommended kernel parameters, LILO configuration
Sometimes the append line will already exist. For example In this case, the existing append line is modified to pass all the parameters. The result is: As a complete example, a typical /etc/lilo.conf configuration from Red Hat Linux 7.1 is: Example 5-1. Complete LILO configuration, as installed by vendor
This is modified to Example 5-2. Complete LILO configuration, modified for serial console
Now that we have finished configuring LILO, use the lilo command to install the new boot record onto the disk: 5.2. Configure Linux kernel using GRUBFind each title entry in the GRUB configuration file. It will be followed by a kernel line. For example
Modify each of the kernel lines to append the parameters that inform the kernel to use a serial console. Figure 5-5. Recommened kernel parameters, GRUB configuration
As a complete example, Example 5-3 is a typical GRUB configuration from Red Hat Linux 7.2. Example 5-3. Complete GRUB configuration, as installed by vendor
The modified configuration file is shown in Example 5-4. Example 5-4. Complete GRUB configuration, modified for serial console
5.3. Configure Linux kernel using SYSLINUXEdit each LABEL entry to add an APPEND line containing the serial console parameter to pass to the Linux kernel. Like LILO, if a kernel already has parameters, then add our parameters to the list after APPEND. For example: Figure 5-6. Recommended kernel parameters, SYSLINUX configuration
There are some traps for beginners in the differences between LILO and SYSLINUX. LILO uses append=, whereas SYSLINUX uses just append. lilo needs to be run after each change to /etc/lilo.conf, whereas syslinux does not need to be run after changing \SYSLINUX.CFG. Chapter 6. Configure gettygetty monitors serial lines, waiting for a connection. It then configures the serial link, sends the contents of /etc/issue, and asks the person connecting for their login name. getty then starts login and login asks the person for their password. If the user does nothing, getty or login hang up and getty goes back to waiting. The getty command has been re-implemented numerous times. There is a wide selection of getty clones, each with slight differences in behavior and syntax. We will describe the traditional getty, and then some popular alternatives. One of the jobs of a getty is to set the TERM environment variable to indicate the make and model of the terminal which is connecting. In this HOWTO we set the terminal to the commonly emulated DEC VT100. If you occassionally connect using a different terminal emulation then you can interactively change your choice of terminal by setting TERM to the appropiate terminal listed in /etc/termcap. Figure 6-1. Interactively altering the connecting terminal's make and model
A getty is also responsible for setting the time zone when a permanently-connected remote terminal is located beyond the machine's default time zone. The getty overrides the default timezone by setting the TZ environment variable. As with the TERM environment variable, a user connecting from a modem can interactively override the default time zone. Figure 6-2. Interactively altering the connecting terminal's time zone
If you do not know your time zone name, run the tzselect utility to generate the appropiate contents for TZ. But first, let's see how getty gets started in the first place. 6.1. init systemThe file /etc/inittab contains the background programs that used to keep the system running. One of these programs is one getty process per serial port. Figure 6-3. getty is started by init, based upon an entry in /etc/inittab
Each field in inittab is separated by a colon and contains:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||