There are various files to edit to set up the computer for terminals. If you're lucky, you'll only need to edit /etc/inittab. One does this by editing at the console (or from any working terminal).
In order to have a login process run on a serial port when the computer starts up (or switches run levels) a getty command must be put into the /etc/inittab file. Getty GETs a TTY (a terminal) going. Each terminal needs its own getty command. There is also at least one getty command for the console in every /etc/inittab file. Find this and put the getty commands for the real terminals next to it. This file may contain sample getty lines for text terminals that are commented out so that all you need to do is to uncomment them (remove the leading #) and change a few arguments.
The arguments which are permitted depend on which getty you
use:
The gettys best for directly connected terminals are:
If you don't have the getty you want, it may be downloaded from Serial Software.
If you are not using modem control lines (for example if you only use the minimum number of 3 conductors: transmit, receive, and common signal ground) you should let getty know this by using a "local" flag. The format of this depends on which getty you use.
An example line in /etc/inittab:
S1:23:respawn:/sbin/getty -L 19200 ttyS1 vt102
S1 is from ttyS1. 23 means that getty is run upon entering run levels
2 or 3. respawn means that if getty is killed, it will automatically
start up (respawn) again. /sbin/getty is the getty command. The -L
means Local (ignore modem control signals). 19200 is the baud rate.
ttyS1 means /dev/ttyS1 (COM2 in MS-DOS). vt102 is the type of
terminal and this getty will set the environment variable TERM to this
value. There are no configuration files. Type "init q" on the
command line after editing getty and you should see a login prompt.
The agetty program will auto-detect any parity set inside the terminal. If you use stty to set parity, agetty will automatically unset it since it doesn't want the serial driver stripping off the parity bit since it to see it as part of an 8-bit character in order to detect parity. Thus if you use parity, enable it only at the terminals and let agetty auto-detect it and set it at the computer. The login prompt will look garbled until you type something and getty sets the parity. Let me know if you find a way to get a clean-looking login prompt with parity using agetty. The garbled prompt will deter visitors, etc. from trying to login (if that's what you want).
(This is from the old Serial-HOWTO by Greg Hankins)
Add entries for getty
to use for your terminal in the
configuration file /etc/gettydefs
if there they aren't
already there:
# 38400 bps Dumb Terminal entry
DT38400# B38400 CS8 CLOCAL # B38400 SANE -ISTRIP CLOCAL #@S @L login: #DT38400
# 19200 bps Dumb Terminal entry
DT19200# B19200 CS8 CLOCAL # B19200 SANE -ISTRIP CLOCAL #@S @L login: #DT19200
# 9600 bps Dumb Terminal entry
DT9600# B9600 CS8 CLOCAL # B9600 SANE -ISTRIP CLOCAL #@S @L login: #DT9600
If you want, you can make getty
print interesting things in the
login banner. In my examples, I have the system name and the serial
line printed. You can add other things:
@B The current (evaluated at the time the @B is seen) bps rate.
@D The current date, in MM/DD/YY.
@L The serial line to which getty is attached.
@S The system name.
@T The current time, in HH:MM:SS (24-hour).
@U The number of currently signed-on users. This is a
count of the number of entries in the /etc/utmp file
that have a non-null ut_name field.
@V The value of VERSION, as given in the defaults file.
To display a single '@' character, use either '\@' or '@@'.
When you are done editing /etc/gettydefs
, you can verify that
the syntax is correct by doing:
linux# getty -c /etc/gettydefs
Make sure there is no getty
or uugetty
config file for the
serial port that your terminal is attached to
(/etc/default/{uu}getty.ttyS
N or
/etc/conf.{uu}getty.ttyS
N), as this will probably
interfere with running getty
on a terminal. Remove the file if
it exits.
Edit your /etc/inittab
file to run getty
on the serial
port (substituting in the correct information for your environment -
port, speed, and default terminal type):
S1:23:respawn:/sbin/getty ttyS1 DT9600 vt100
Restart init
:
linux# init q
At this point, you should see a login prompt on your terminal. You may have to hit return to get the terminal's attention.
The m stands for modem. This program is primarily for modems but it will work for text-terminals. It's poorly documented (as of mid 1998) for terminals and you may need to wade thru much documentation for modems in order to figure out how to use it for terminals. Look at /etc/mgetty/mgetty.config for an example of configuring a terminal.
There is both a "stty" command and a "setserial" command for
setting up the serial ports. Some (or all) of the needed stty
settings can be done via getty and there may be no need to use
setserial so you may not need to use either command. These two
commands (stty and setserial) set up different aspects of the serial
port. Stty does the most while setserial configures the low-level
stuff such as interrupts and port addresses. To "save" the settings,
these commands must be written in certain files (shell scripts) which
run each time the computer starts up. You may also use the stty
and setserial
commands on the command line but such settings will
be lost as soon at you turn off the computer.
Setserial can change both the interrupt (IRQ) number and the port address. It can tell you what type of UART chips you have. It can set the time that the port will keep operating after it's closed (in order to output any characters still in its buffer in main RAM). This is needed at slow baud rates of 1200 or lower. For setserial to work, the serial module (for the Linux kernel) must be loaded. If you use more than 2 serial ports and want to assign unique IRQ numbers, then you need to use setserial.
To modify (or add) a setserial command, edit the shell script that runs setserial. Where it resides depends on your distribution. It might be in a /etc/rc.d directory in a "rc.local" or "rc.serial" file. In the Debian distribution it was the 0setserial file in /etc/rc.boot but this eventually should change to a file in /etc/init.d.
You probably don't need to use the "stty" command to configure if you use one of the two suggested gettys to do the equivalent of stty ... You still may need to use the stty command to see how the serial port is configured and may need to consult the stty man page.
Stty does most of the configuration of the serial port (but the default plus what you change with getty should set things up OK). To see how it's now set for the terminal (or console) you're now at type at the shell prompt: stty -a. For other terminals (such as ttyS1) type: stty -a < /dev/ttyS1. Here are some of the items stty configures: speed (bits/sec), parity, bits/byte, # of stop bits, strip 8th bit?, modem control signals, flow control, break signal, end-of-line markers, change case, padding, beep if buffer overrun?, echo, allow background tasks to write to terminal?, define special (control) characters (such as what keys to press for interrupt). See the stty man or info page for more details. Also see the man page: termios which covers the same options set by stty but (as of mid 1998) covers features which the stty man page fails to mention. For use of some special characters see Special (Control) Characters
With some implementations of getty (getty_ps package), the commands that one would normally give to stty are typed into a getty configuration file: /etc/gettydefs. Even without this configuration file, the getty command line may be sufficient to set things up so that you don't need stty.
One may write C programs which change the stty configuration, etc. Looking at the documentation for this may help one better understand the use of the stty command (and its many possible arguments). Serial-Programming-HOWTO is useful. The manual page: termios contains a description of the C-language structure (of type termios) which stores the stty configuration in computer memory. Many of the flag names in this C-structure are almost the same (and do the same thing) as the arguments to the stty command.
If getty sets up things OK, then you may skip this sub-section. To have stty set up the terminal each time the computer starts up you need to put the stty command in a file that will be executed each time the computer is started up (Linux boots). This file should be run before getty starts. There are many possible places to put it. If it gets put in more than one place and you only know about (or remember) one of those places, then a conflict is likely. So make sure to document (perhaps in your terminal manual) where it's located.
One good place to put it would be in the same file that runs setserial when the system is booted. See Where to Run Setserial?. It would seem best to put it after the setserial command so that the low level stuff is done first. In the Debian distribution there is an /etc/init.d/bootmisc.sh script but it currently runs before 0setserial does.
See Terminfo and Termcap (detailed) for a more detailed discussion of termcap. Many application programs that you run use the terminfo (formerly termcap) data base. This has an entry for each model or type (such as vt100) of terminal and tells what the terminal can do, what codes to send for various actions, and what codes to send to the terminal to initialize it.
Since many terminals (and PC's also) can emulate other terminals and have various "modes" of operation, there may be several terminfo entries from which to choose for a given physical terminal. They usually will have similar names. The last parameter of getty (for both agetty and getty_ps) should be the terminfo name of the terminal (or terminal emulation) that you are using (such as vt100).
The terminfo does more than just specify what the terminal is capable of doing and disclose what codes to send to the terminal to get it to do those things. It also specifies what "bold" will look like (will it be reverse video or will it be high intensity, etc.), what the cursor will look like, if the letters will be black, white, or some other color, etc. In PC terminology these are called "preferences". It also specifies initialization codes to send to the terminal (analogous to the init strings sent to modems). Such strings are not automatically sent to the terminal by Linux. See Init String. If you don't like the way the display on the screen looks and behaves you may need to edit (and then update) the terminfo (or termcap) file. See Terminfo Compiler (tic) for how to update.
These are two environment variables for terminals, but you may not need to do anything about them. TERM must always be set to the name of the terminal you are using. TERMINFO contains the path to the terminfo data base, but may not be needed if the database is in a default location (or TERMINFO could be set automatically by a file that comes with your distribution of Linux).
Fortunately, the getty program usually sets TERM for you just before login. This permits application programs to find the name of your terminal and then look up the terminal capabilities in the terminfo data base. See TERM Variable for more details on TERM.
If your terminfo data base can't be found you may see an error message about it on your terminal. If this happens it's time to check out where terminfo resides and set TERMINFO if needed. You may find out where the terminfo database is by searching for a common terminfo file such as "vt100" using the "locate" command. Make sure that your terminal is in this database. An example of setting TERMINFO is: export TERMINFO=/usr/share/terminfo (put this in /etc/profile or the like). If the data for your terminal in this data base is not to your liking, you may need to edit it. See Terminfo & Termcap (brief).
The configuration file /etc/ttytype is used to map /dev/ttySn's to terminal names per terminfo. tset uses it, but if the TERM environment variable is already set correctly, then this file is not needed. Since the Linux getty sets TERM for each tty, you don't need this file. In other Unix-like systems such as FreeBSD, the file /etc/ttys maps ttys to much more, such as the appropriate getty command, and the category of connection (such as "dialup"). An example line of Linux ttytype: vt220 ttyS1
By default, the root user may not login from a terminal. To permit this you must create (or edit) the file /etc/securetty per the manual page "securetty". To restrict logins of certain users and/or certain terminals, etc. edit /etc/login.access (this replaces the old /etc/usertty file ??). /etc/login.def determines if /etc/securetty is to be used and could be edited so as to make /etc/securetty not needed (or not used). /etc/porttime restricts the times at which certain ttys and users may use the computer. If there are too many failed login attempt by a user, that user may be prohibited from ever logging in again. See the man page "faillog" for how to control this.
Sometimes there are commands that one wants to execute at start-up only for a certain type of terminal. To do this for the stty command is no problem since one uses the redirection operator < to specify which terminal the command is for. But what about shell aliases or functions? You may want to make a function for the ls command so it will color-code the listing of directories only on color terminals or consoles. For monochrome terminals you want the same function name (but a different function body) which will use symbols as a substitute for color-coding. Where to put such function definitions that are to be different for different terminals?
You may put them inside an "if" statement in /etc/profile which runs at startup each time one logs on. The conditional "if" statement defines certain functions, etc. only if the terminal is of a specified type.
While much of what this if statement does could be done in the configuration file for dircolors, here's an example for the case of the bash shell:
if [ $TERM = linux ]; then eval `dircolors`; elif [ $TERM = vt220 ]; then ls () { command ls -F $* ; } # to export the function ls(): declare -xf ls else echo "From /etc/profile: Unknown terminal type $TERM" fi