601-604.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 160 行
HTML
160 行
<HTML>
<HEAD>
<TITLE>Linux Unleashed, Third Edition:Devices</TITLE>
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0672313723//-->
<!--TITLE=Linux Unleashed, Third Edition//-->
<!--AUTHOR=Tim Parker//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Sams//-->
<!--CHAPTER=33//-->
<!--PAGES=601-604//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="599-601.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="604-606.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading17"></A><FONT COLOR="#000077">Terminal Files: /etc/ttys and /etc/inittab</FONT></H4>
<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.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Warning: </B><BR>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></FONT>
</BLOCKQUOTE>
<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:</P>
<!-- CODE //-->
<PRE>
console tty1
console tty2
console tty3
console tty4
console tty5
console tty6
vt100 ttyp0
vt100 ttyp1
vt100 ttyp2
vt100 ttyp3
</PRE>
<!-- END CODE //-->
<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:</P>
<!-- CODE SNIP //-->
<PRE>
<I>ID:runlevel:action:process</I>
</PRE>
<!-- END CODE SNIP //-->
<P>The <I><TT>ID</TT></I> 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 <I><TT>runlevel</TT></I> 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 <I><TT>runlevel</TT></I>s are supported. Multiple <I><TT>runlevel</TT></I>s may be mentioned in the field.</P>
<P>The <I><TT>action</TT></I> section shows how to handle the <I><TT>process</TT></I> field. The <I><TT>action</TT></I> field has several valid entries:</P>
<CENTER>
<TABLE WIDTH="80%"><TR>
<TD WIDTH="25%"><TT>boot</TT>
<TD WIDTH="65%">Runs when <TT>inittab</TT> is first read
<TR>
<TD><TT>bootwait</TT>
<TD>Runs when <TT>inittab</TT> is first read
<TR>
<TD><TT>initdefault</TT>
<TD>Sets initial run level
<TR>
<TD><TT>off</TT>
<TD>Terminates the process if it is running
<TR>
<TD><TT>once</TT>
<TD>Starts the process once
<TR>
<TD VALIGN="TOP"><TT>ondemand</TT>
<TD>Always keeps the process running (the same as <TT>respawn</TT>)
<TR>
<TD><TT>powerfail</TT>
<TD>Executes when <TT>init</TT> gets a power fail signal
<TR>
<TD><TT>powerwait</TT>
<TD>Executes when <TT>init</TT> gets a power wait signal
<TR>
<TD><TT>sysinit</TT>
<TD>Executes before accessing the console
<TR>
<TD><TT>respawn</TT>
<TD>Always keeps the process running
<TR>
<TD><TT>wait</TT>
<TD>Starts the process once
</TABLE>
</CENTER>
<P>The <I><TT>action</TT></I> 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:</P>
<!-- CODE SNIP //-->
<PRE>
# 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
</PRE>
<!-- END CODE SNIP //-->
<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.</P>
<H4 ALIGN="LEFT"><A NAME="Heading18"></A><FONT COLOR="#000077">Terminal Definitions: The /etc/termcap File</FONT></H4>
<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:</P>
<!-- CODE //-->
<PRE>
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:
</PRE>
<!-- END CODE //-->
<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.</P>
<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.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Note: </B><BR>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></FONT>
</BLOCKQUOTE>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="599-601.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="604-606.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?