📄 ch39.htm
字号:
uses for communications. The format of each line in the <TT>gettydefs</TT> file is
as follows:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">label:initial flags: final flags: login prompt: next label
</FONT></PRE>
<P>The label is used to identify each line, so that when <TT>/sbin/getty</TT> is
started with an argument (as it usually is, transparent to the user), the argument
is used to match the label and provide the configuration information. The initial
and final flags are used to set any behavior for the connection before and after
the <TT>login</TT> program has executed.</P>
<P>The login prompt is the prompt to be displayed on the terminal. Usually it is
just <TT>login:</TT>, but it can be any string. Finally, the next label is used to
send <TT>getty</TT> to another line, in case it can't use the current one. This is
typically used with modem lines, which start at a high speed (such as 9600 baud)
and go to 4800, 2400, and 1200 in sequence, trying to connect at each step. For terminals,
the next label is usually a pointer back to the line's first label.</P>
<P>An extract from a sample <TT>/etc/gettydefs</TT> file looks like this:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">console# B19200 OPOST ONLCR TAB3 BRKINT IGNPAR ISTRIP IXON IXANY PARENB ECHO
ECHOE ECHOK ICANON ISIG CS8 CREAD # B19200 OPOST ONLCR TAB3 BRKINT IGNPAR ISTRIP
IXON IXANY PARENB ECHO ECHOE ECHOK ICANON ISIG CS8 CREAD #Console Login: #console
9600H# B9600 # B9600 SANE IXANY PARENB TAB3 HUPCL #login: #4800H
4800H# B4800 # B4800 SANE IXANY PARENB TAB3 HUPCL #login: #2400H
2400H# B2400 # B2400 SANE IXANY PARENB TAB3 HUPCL #login: #1200H
1200H# B1200 # B1200 SANE IXANY PARENB TAB3 HUPCL #login: #300H
300H# B300 # B300 SANE IXANY PARENB TAB3 HUPCL #login: #9600H
</FONT></PRE>
<P>If you look at the file that accompanies your Linux system, you see that there
are many more lines, but they all have the same format as the preceding samples.
The easiest lines to look at are the shorter ones (the last five lines in the preceding
extract), but they all have the same format as the preceding samples.</P>
<P>These lines are for a modem, starting at 9600 baud. The initial flag is set to
<TT>B9600</TT>, which sets the baud rate at 9600 baud. The final flags, used when
a connection has been established, set the characteristics of the line (such as a
<TT>TAB</TT> meaning three spaces). Finally, the field at the end points to the next
lower speed to provide checks for slower modems or poor lines that prevent fast logins.</P>
<P>The first line in the preceding extract is typical for a terminal. It sets many
initial and final flags that control how the terminal behaves. The reference at the
end of the line is back to the same definition, because the terminal is hardwired
to the system.
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading28<FONT COLOR="#000077"><B>NOTE:</B> </FONT>You shouldn't have
to change the entries in the <TT>gettydefs</TT> file, because the default file contains
many different configurations. You should examine the file carefully to find an entry
that will work with the terminal you are using. If you do make changes to the <TT>gettydefs</TT>
file, you should run the command <TT>getty -c</TT> <TT>gettydefs</TT> to make the
changes effective.
<HR>
</DL>
<CENTER>
<H4><A NAME="Heading29<FONT COLOR="#000077">Terminal Files: /etc/ttys and /etc/inittab</FONT></H4>
</CENTER>
<P>Terminal configuration information is stored in the files <TT>/etc/ttys</TT> and
<TT>/etc/inittab</TT>. These files can be modified by any editor. Some menu-driven
programs are now appearing that perform changes to the files for you.
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading30<FONT COLOR="#000077"><B>WARNING:</B> </FONT>Before making
any changes to the terminal configuration files, make a safe copy in case the changes
aren't effective and the file can't be returned to its original state easily. Simply
copy the two files to new names such as <TT>/etc/tty.original</TT> and <TT>/etc/inittab.original</TT>.
<HR>
</DL>
<P>The <TT>/etc/ttys</TT> file has two columns. The first shows the type of terminal,
and the second shows the device name. A typical <TT>/etc/ttys</TT> file from a new
installation of Linux looks like this:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">console tty1
console tty2
console tty3
console tty4
console tty5
console tty6
vt100 ttyp0
vt100 ttyp1
vt100 ttyp2
vt100 ttyp3
</FONT></PRE>
<P>The terminal type in the first column is used to set the <TT>TERM</TT> environment
variable when you log in, unless you override the value.</P>
<P>The <TT>/etc/inittab</TT> file is used to set the behavior of each terminal. The
format of the <TT>/etc/inittab</TT> file follows this pattern:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">ID:runlevel:action:process
</FONT></PRE>
<P>The ID is a one- or two-character string that uniquely identifies the entry. In
most cases, this corresponds to the device name, such as <TT>1</TT> for <TT>tty1</TT>.</P>
<P>The runlevel decides the capabilities of the terminal with the various states
that the Linux operating system can be in (run levels vary from <TT>0</TT> to <TT>6</TT>,
and <TT>A</TT>, <TT>B</TT>, and <TT>C</TT>). If no entry is provided, all runlevels
are supported. Multiple runlevels may be mentioned in the field.</P>
<P>The action section shows how to handle the process field. The action field has
several valid entries:
<TABLE BORDER="0">
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="74" ALIGN="LEFT"><TT>boot</TT> </TD>
<TD ALIGN="LEFT">Runs when <TT>inittab</TT> is first read. </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="74" ALIGN="LEFT"><TT>bootwait</TT> </TD>
<TD ALIGN="LEFT">Runs when <TT>inittab</TT> is first read. </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="74" ALIGN="LEFT"><TT>initdefault</TT> </TD>
<TD ALIGN="LEFT">Sets initial run level. </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="74" ALIGN="LEFT"><TT>off</TT> </TD>
<TD ALIGN="LEFT">Terminates the process if it is running. </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="74" ALIGN="LEFT"><TT>once</TT> </TD>
<TD ALIGN="LEFT">Starts the process once. </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="74" ALIGN="LEFT"><TT>ondemand</TT> </TD>
<TD ALIGN="LEFT">Always keeps the process running (the same as <TT>respawn</TT>). </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="74" ALIGN="LEFT"><TT>powerfail</TT> </TD>
<TD ALIGN="LEFT">Executes when <TT>init</TT> gets a power fail signal. </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="74" ALIGN="LEFT"><TT>powerwait</TT> </TD>
<TD ALIGN="LEFT">Executes when <TT>init</TT> gets a power fail signal. </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="74" ALIGN="LEFT"><TT>sysinit</TT> </TD>
<TD ALIGN="LEFT">Executes before accessing the console. </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="74" ALIGN="LEFT"><TT>respawn</TT> </TD>
<TD ALIGN="LEFT">Always keeps the process running. </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="74" ALIGN="LEFT"><TT>wait<BR>
</TT></TD>
<TD ALIGN="LEFT">Starts the process once.<BR>
</TD>
</TR>
</TABLE>
The action indicates the behavior of the terminal device when the system starts and
when a <TT>getty</TT> process is terminated on it.</P>
<P>A simple <TT>/etc/inittab</TT> file (taken from an earlier version of Linux for
clarity's sake because the latest version complicates the lines a little) looks like
this:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF"># inittab for Linux
id:1:initdefault:
rc::bootwait:/etc/rc
1:1:respawn:/etc/getty 9600 tty1
2:1:respawn:/etc/getty 9600 tty2
3:1:respawn:/etc/getty 9600 tty3
4:1:respawn:/etc/getty 9600 tty4
</FONT></PRE>
<P>The first two lines (after the comment) are used when the system boots. The second
line tells the system to run <TT>/etc/rc</TT> in order to boot. The rest of the lines
indicate that a <TT>getty</TT> process should be started for <TT>tty1</TT> through
<TT>tty4</TT> at 9600 baud.
<CENTER>
<H4><A NAME="Heading31<FONT COLOR="#000077">Terminal Definitions: The /etc/termcap
File</FONT></H4>
</CENTER>
<P>The <TT>/etc/termcap</TT> file holds the instructions for communicating with different
terminals. Most terminals that are supported by the operating system have an entry
inside this file. The <TT>termcap</TT> (terminal capabilities) file can be quite
large. If you are going to make changes, copy a version to a safe filename first.</P>
<P>The contents of the <TT>termcap</TT> file are similar to the printer definition
file <TT>/etc/printcap</TT>. Each entry in the <TT>termcap</TT> file has a name with
several variations, as well as a set of codes and values for different terminal characteristics.
Because terminals use many different codes for different actions, many codes can
be used with some of the more talented terminals.</P>
<P>An extract from a <TT>termcap</TT> file shows the definitions for two fairly simple
terminals, the Wyse 30 and Wyse 85:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">w0|wy30-vb|wyse30-vb|wyse 30 Visible bell:\
:vb=\E`8\E`\072\E`9:\
:tc=wy30:
wc|wy85|wyse85|Wyse 85 in 80 column mode, vt100 emulation:\
:is=\E[61"p\E[13l\E>\E[?1l\E[?3l\E[?7h\E[?16l\E[?5W:\
:co#80:li#24:am:cl=\E[;H\E[2J:bs:cm=\E[%i%d;%dH:nd=2\E[C:up=2\E[A:\
:ce=\E[0K:cd=\E[0J:so=2\E[7m:se=2\E[m:us=2\E[4m:ue=2\E[m:\
:ku=\E[A:kd=\E[B:kr=\E[C:kl=\E[D:\
:kh=\E[H:xn:\
:im=:CO=\E[?25h:CF=\E[?25l:ic=\E[1@:dc=\E[1P:\
:dl=\E[1M:al=\E[1L:GS=\EF:GE=\EG:pt:
</FONT></PRE>
<P>The meaning of each set of codes is not really of interest to most users and system
administrators. You have to start changing or rewriting terminal entries only if
you are adding a terminal type that doesn't exist in the <TT>termcap</TT> file already.
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading32<FONT COLOR="#000077"><B>NOTE:</B> </FONT>Most terminals
offer multiple emulations. If you can't find the terminal type in the <TT>termcap</TT>
file, look for an emulation that is supported. It's easier to emulate a different
terminal than to write a <TT>termcap</TT> entry for a new type.
<HR>
</DL>
<P>The terminal characteristics in the <TT>/etc/termcap</TT> file are used by the
<TT>/etc/ttys</TT> file. The first column of the <TT>ttys</TT> file gives the default
terminal type used to set the <TT>TERM</TT> environment variable. Essentially, the
startup routine uses a pattern-matching utility to find a matching line in the <TT>termcap</TT>
file, and then reads the codes that follow.
<CENTER>
<H4><A NAME="Heading33<FONT COLOR="#000077">Adding a Terminal</FONT></H4>
</CENTER>
<P>Terminals are added to Linux in much the same manner as printers: using the <TT>mknod</TT>
command. To add a terminal, you must decide which port the terminal will be connected
to. The serial ports on a PC are referred to by Linux as <TT>/dev/ttyS0</TT> (for
<TT>COM1</TT> in DOS terms), <TT>/dev/ttyS1</TT> (for <TT>COM2</TT>), and so on.</P>
<P>Most PC systems have one or two serial ports, although up to four can be accommodated
(<TT>ttyS0</TT> to <TT>ttyS3</TT>). Linux uses the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -