📄 lsg11.htm
字号:
<BR>
</UL>
<P>A simple /etc/inittab file showing terminal startup commands (taken from an earlier version of Linux for clarity's sake, as the latest version complicates the lines a little) looks like the following:
<BR>
<PRE>
<FONT COLOR="#000080"># inittab for Linux
S1:1:respawn:/etc/getty 9600 ttyS0
S2:1:respawn:/etc/getty 9600 ttyS1</FONT></PRE>
<P>The lines indicate that a getty process should be started for ttyS0 (first COM port) and ttyS1 (second COM port) at 9600 baud and should be respawned (restarted) if the getty process terminates. You can use lines like these when you add terminals to serial ports. Multiport boards usually use commands in different files to start their getty processes.
<BR>
<BR>
<A NAME="E69E101"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B> /etc/getty and /etc/gettydefs</B></FONT></CENTER></H4>
<BR>
<P>The /etc/getty program is referred to quite a lot when dealing with terminals. Basically, /etc/getty is a program that sets the communications parameters between Linux and a terminal, including the speed, protocol, and any special handling of the cable.
<BR>
<P>The /etc/getty program is called by /etc/init when the system boots or when the process terminates. When called, /etc/getty opens the serial port or other connection to the terminal and sets the communications parameters based on information in the file /etc/gettydefs (getty definitions). The getty process then generates the login prompt on the remote terminal. Many special handling and command options are available with the getty process, but most of them are of little interest to users and casual system administrators.
<BR>
<P>The /etc/gettydefs file supplies the settings getty uses for communications. The format of each line in the gettydefs file is as follows:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">label:initial flags: final flags: login prompt: next label</FONT></PRE>
<P>you use the label to identify each line so that when /etc/getty 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. You use initial flags and final flags to set any behavior for the connection before and after the login program has executed. The login prompt is the prompt to be displayed on the terminal. Usually it is just login:, but it can be any string unique to that terminal.
<BR>
<P>Finally, you use the next label to send getty to another line in case it can't use the current one. This parameter is typically used with modem lines that start at a high speed (such as 9600 baud), and then 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.
<BR>
<P>An extract from a sample /etc/gettydefs file looks like the following:
<BR>
<PRE>
<FONT COLOR="#000080">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 will see that there are many more lines, but they all have the same format as the preceding examples. The easier lines to look at are the shorter ones (the last five lines in the preceding extract).
<BR>
<P>These lines are for a modem starting at 9600 baud. The initial flag is set to B9600, 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 tab 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.
<BR>
<P>The first lines in the preceding extract are typical for the system console. They set many initial and final flags that control how the console behaves. The reference at the end of the line is back to the same definition, as the terminal is hard-wired to the system. Terminals are defined in much the same manner, although their entries don't have to be as complex as the console's. A few simple terminal definitions are as follows:
<BR>
<PRE>
<FONT COLOR="#000080"># 38400 fixed baud Dumb Terminal entry
DT38400# B38400 CS8 CLOCAL CRTSCTS # B38400 SANE -ISTRIP CLOCAL CRTSCTS # login: #DT38400
# 19200 fixed baud Dumb Terminal entry
DT19200# B19200 CS8 CLOCAL # B19200 SANE -ISTRIP CLOCAL # login: #DT19200
# 9600 baud Dumb Terminal entry
DT9600# B9600 CS8 CLOCAL # B9600 SANE -ISTRIP CLOCAL # login: #DT9600</FONT></PRE>
<P>In each definition line, the baud rate is set with 8 bits (CS8) used. The flags are used to set initial behavior. The login is a simple prompt, and the end of the definition points back to the same line. These simple definitions in an /etc/gettydefs file suffice for all dumb terminals, once you select the proper speed. If you are using a terminal with more advanced capabilities, you can add those to the gettydefs file, too.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>You may not have to change the entries in the default gettydefs file as it usually contains many different configurations. Examine the file carefully to find an entry that will work with the terminal you are using. If you do make changes to the gettydefs file, issue the command getty -c gettydefs to make the changes effective without rebooting.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E69E102"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B> The /etc/termcap File</B></FONT></CENTER></H4>
<BR>
<P>The /etc/termcap file holds the instruction codes for the Linux kernel and getty to communicate with different terminals. Most terminals that are supported by the Linux operating system have an entry inside this file, so the file can be quite large. If you are going to make changes, copy a version to a safe filename first.
<BR>
<P>Each entry in the termcap file has a name or label to identify the terminal it refers to, along with several variations on the name, and then a set of codes and values for different terminal characteristics. Because terminals use many different codes for different actions, some of the more talented terminals use many codes.
<BR>
<P>An extract from a termcap file shows the definitions for two fairly simple terminals, the Wyse 30 and Wyse 85:
<BR>
<PRE>
<FONT COLOR="#000080">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 only have to start changing or rewriting terminal entries if you are adding a terminal type that does not exist in the termcap file already.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>Most terminals offer multiple emulations. If you can't find the terminal type you need in the termcap file, look for an emulation that is supported (usually a Qume, VT, or Wyse type). It is easier to emulate a different terminal than write a termcap entry for a new type.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>The /etc/ttys file uses the terminal characteristics in the /etc/termcap file. The first column of the ttys file gives the default terminal type used to set the TERM environment variable. The startup routine uses a pattern-matching utility to find a matching line in the termcap file, and then reads the codes that follow and uses those for all communications.
<BR>
<BR>
<A NAME="E68E62"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Adding a Terminal</B></FONT></CENTER></H3>
<BR>
<P>Terminals are added to Linux in much the same manner as other devices, though the mknod command. To add a terminal, you must know name of the port to which the terminal will be connected. Linux refers to the serial ports on a PC as /dev/ttyS0 (for COM1), /dev/ttyS1 (for COM2), and so on.
<BR>
<P>Most PC systems have one or two serial ports, although up to four can be accommodated on a PC (/dev/ttyS0 to /dev/ttyS3). Linux uses the serial ports based on their addresses in the BIOS. The usual addresses for the serial ports are as follows:
<BR>
<TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
ttyS0 (COM1)
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
0x03f8</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
ttyS1 (COM2)
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
0x02f8</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
ttyS2 (COM3)
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
0x03e8</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
ttyS3 (COM4)
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
0x02e8</FONT>
</TABLE><P>If you are not sure about which serial port is which, you may have to either use a DOS-based diagnostic utility (like MS-DOS' MSD.EXE or a commercial package like Norton Utilities or Central Point Tools) or start at the lowest address and work up, testing the terminal each time. If the PC has only one port, it is almost always configured as COM1 (/dev/ttyS0). The Linux installation script usually configures the two PC serial ports, so you may only need to set the speeds and parameters for a terminal attached to a serial port. If you are using a multiport board, you will probably have to install drivers.
<BR>
<P>To create a new terminal device, you must run the mknod (make node) command to create the new device driver file, and then change the permissions on the file to let root or a root-started daemon run it. A typical command for creating a new terminal device is
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">mknod -m 660 /dev/ttyS0 c 4 64</FONT></PRE>
<P>where the -m 660 sets the permissions on the file, /dev/ttyS0 specifies the first serial port on the machine (COM1), the c indicates that the terminal is a character mode device (almost all terminals, except very high-speed high-end models are character devices), and the major and minor device numbers are set to 4 and 64, respectively. For the other serial ports on the PC (COM2 through COM4), the commands would be
<BR>
<PRE>
<FONT COLOR="#000080">mknod -m 660 /dev/ttyS1 c 4 65
mknod -m 660 /dev/ttyS2 c 4 66
mknod -m 660 /dev/ttyS3 c 4 67</FONT></PRE>
<P>The changes in the minor device number with the different commands above are required, although you can use any number you wish. The only requirement is that there must be a unique combination of major and minor device numbers for each terminal.
<BR>
<P>After the mknod command has been executed, you must set the device driver to the proper ownership. Issue the command
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">chown root.tty /dev/ttyS0</FONT></PRE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -