604-606.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 136 行
HTML
136 行
<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=604-606//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="601-604.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="607-608.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading19"></A><FONT COLOR="#000077">Adding a Terminal</FONT></H4>
<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 COM1 in DOS terms), <TT>/dev/ttyS1</TT> (for COM2), 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 serial ports based on their addresses in the BIOS. The usual addresses for the serial ports are as follows:</P>
<CENTER>
<TABLE WIDTH="90%"><TR>
<TD WIDTH="30%"><TT>ttyS0</TT> (COM1)
<TD WIDTH="70%"><TT>0x03f8</TT>
<TR>
<TD><TT>ttyS1</TT> (COM2)
<TD><TT>0x02f8</TT>
<TR>
<TD><TT>ttyS2</TT> (COM3)
<TD><TT>0x03e8</TT>
<TR>
<TD><TT>ttyS3</TT> (COM4)
<TD><TT>0x02e8</TT>
</TABLE>
</CENTER>
<P>If you’re not sure which serial port is which, you may have to use either a DOS-based diagnostic utility (such as MS-DOS’s MSD.EXE) 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.
</P>
<P>To create a new terminal device, you must run the <TT>mknod</TT> (make node) command to create the new device driver file, and then change the permissions on the file to let it be run by <TT>root</TT> or <TT>daemon</TT>. Most Linux distributions include the terminal devices already. The <TT>mknod</TT> command was covered in detail earlier in this chapter. Check out the section “The <TT>mknod</TT> Command.”</P>
<P>A typical command for creating a new terminal device is</P>
<!-- CODE SNIP //-->
<PRE>
mknod -m 660 /dev/ttyS0 c 4 64
</PRE>
<!-- END CODE SNIP //-->
<P>The <TT>-m 660</TT> sets the permissions on the file. <TT>/dev/ttyS0</TT> specifies the first serial port on the machine (COM1). The <TT>c</TT> indicates that the terminal is a character device (almost all terminals, except very high-speed high-end models, are character devices). The major device number is set to <TT>4</TT>, while the minor device number is set to <TT>64</TT>. For the other serial ports on the PC (COM2 through COM4), the commands would be as follows:</P>
<!-- CODE SNIP //-->
<PRE>
mknod -m 660 /dev/ttyS1 c 4 65
mknod -m 660 /dev/ttyS2 c 4 66
mknod -m 660 /dev/ttyS3 c 4 67
</PRE>
<!-- END CODE SNIP //-->
<P>The changes in the minor device number with the preceding different commands are not required, but there must be a unique minor device number for each terminal.
</P>
<P>After the <TT>mknod</TT> command has been executed, the device driver must be set to the proper ownership. Issue the command</P>
<!-- CODE SNIP //-->
<PRE>
chown root.tty /dev/ttyS0
</PRE>
<!-- END CODE SNIP //-->
<P>replacing the <TT>/dev/ttyS0</TT> with whatever device the command applies to. The ownership is set to <TT>root.tty</TT>.</P>
<P>You also want to change the entry in the <TT>/etc/ttys</TT> file to include the terminal type and device that you have added so that the startup of the terminal can be performed properly. Because the <TT>/etc/inittab</TT> file already contains entries for the standard serial ports, you can edit the entry for your new terminal’s port (if necessary) to set the baud rate and other parameters that may be required.</P>
<H4 ALIGN="LEFT"><A NAME="Heading20"></A><FONT COLOR="#000077">Using stty and tset</FONT></H4>
<P>The <TT>stty</TT> command enables you to change and query a terminal option. The <TT>stty</TT> command is very complex, with dozens of options that modify the behavior of the terminal device driver. Luckily, only the most intense system administrators have to use the many options, so in this chapter we will ignore most of the details.</P>
<P>To see the current settings of a terminal, use the <TT>stty</TT> command without any arguments. It displays a set of parameters. You can use this to verify that the terminal has read the configuration information properly from the <TT>/etc/inittab</TT> and <TT>/etc/gettydefs</TT> files.</P>
<P>Like <TT>stty</TT>, the <TT>tset</TT> command has many options, most of which are seldom used (especially if you are not dealing with strange terminals and weird connectors). The <TT>tset</TT> command is used to initialize the terminal driver. If the <TT>tset</TT> command is given with a specific argument, it uses that. Otherwise, the value in the <TT>TERM</TT> environment variable is used.</P>
<P>You can use <TT>tset</TT> within the startup files of a user who always logs in from a remote terminal (through a modem). If you put the command</P>
<!-- CODE SNIP //-->
<PRE>
tset -m dialup:vt100
</PRE>
<!-- END CODE SNIP //-->
<P>in the shell startup file (<TT>.profile</TT>, <TT>.cshrc</TT>, and so on), the terminal type will be set to <TT>vt100</TT> every time a connection is made through the modem. Of course, this sets the terminal type even if someone isn’t using a <TT>VT100</TT> terminal, so you can use the command</P>
<!-- CODE SNIP //-->
<PRE>
tset -m dialup:?vt100
</PRE>
<!-- END CODE SNIP //-->
<P>to have the user connecting through the modem prompted for the terminal type. The prompt looks like this:
</P>
<!-- CODE SNIP //-->
<PRE>
TERM=(vt100)?
</PRE>
<!-- END CODE SNIP //-->
<P>If the user presses Enter, the <TT>TERM</TT> variable is set to <TT>vt100</TT>. If the user doesn’t want to use that value, she can enter the correct string at the prompt.</P>
<P>So far, <TT>tset</TT> seems to be quite simple, but, in fact, it has a very complex structure when dealing with hard-wired terminals. To properly configure a terminal connected through a serial port, you need a command such as this:</P>
<!-- CODE SNIP //-->
<PRE>
eval ‘tset -s -Q -m dialup:?vt100 -m switch:z29‘
</PRE>
<!-- END CODE SNIP //-->
<P>The full details of this type of command are unimportant for most system administrators. If you want more information, check the man pages for <TT>tset</TT> and <TT>stty</TT> that came with your Linux system.</P>
<H4 ALIGN="LEFT"><A NAME="Heading21"></A><FONT COLOR="#000077">Resetting a Screwy Terminal</FONT></H4>
<P>Every now and then a terminal connected through a serial port starts acting screwy, either not showing a prompt or generating garbage. There are two quick ways to try to reset the terminal. If they don’t work, the terminal should be shut down and restarted. (You might have to kill the processes that were running on the terminal.)
</P>
<P>The first approach is to issue a set of Ctrl+J characters on the screwy terminal, and then type <B><TT>stty sane</TT></B> followed by another Ctrl+J. The command <TT>stty sane</TT> should reset the terminal characteristics to normal. You probably won’t see the letters you are typing, so enter them carefully.</P>
<P>If the terminal isn’t behaving at this point, try typing <B><TT>reset</TT></B> and pressing Enter or Ctrl+J. If this doesn’t work, the terminal is hung and should be reset manually.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="601-604.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="607-608.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?