📄 serialconsole-setup.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>Setting Up the Serial Console</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD Handbook" href="index.html" /><link rel="UP" title="Serial Communications" href="serialcomms.html" /><link rel="PREVIOUS" title="Dial-out Service" href="dialout.html" /><link rel="NEXT" title="PPP and SLIP" href="ppp-and-slip.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD Handbook</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="dialout.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 20 Serial Communications</td><td width="10%" align="right" valign="bottom"><a href="ppp-and-slip.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="SERIALCONSOLE-SETUP" name="SERIALCONSOLE-SETUP">20.6 Setting Upthe Serial Console</a></h1><i class="AUTHORGROUP"><span class="CONTRIB">Contributed by</span> Kazutaka YOKOTA.</i><i class="AUTHORGROUP"><span class="CONTRIB">Based on a document by</span> Bill Paul.</i><div class="SECT2"><h2 class="SECT2"><a id="SERIALCONSOLE-INTRO" name="SERIALCONSOLE-INTRO">20.6.1Introduction</a></h2><p>FreeBSD has the ability to boot on a system with only a dumb terminal on a serial portas a console. Such a configuration should be useful for two classes of people: systemadministrators who wish to install FreeBSD on machines that have no keyboard or monitorattached, and developers who want to debug the kernel or device drivers.</p><p>As described in <a href="boot.html">Chapter 12</a>, FreeBSD employs a three stagebootstrap. The first two stages are in the boot block code which is stored at thebeginning of the FreeBSD slice on the boot disk. The boot block will then load and runthe boot loader (<tt class="FILENAME">/boot/loader</tt>) as the third stage code.</p><p>In order to set up the serial console you must configure the boot block code, the bootloader code and the kernel.</p></div><div class="SECT2"><h2 class="SECT2"><a id="SERIALCONSOLE-HOWTO-FAST" name="SERIALCONSOLE-HOWTO-FAST">20.6.2Serial Console Configuration, Terse Version</a></h2><p>This section assumes that you are using the default setup, know how to connect serialports and just want a fast overview of a serial console. If you encounter difficulty withthese steps, please see the more extensive explanation of all the options and advancedsettings in <a href="serialconsole-setup.html#SERIALCONSOLE-HOWTO">Section20.6.3</a>.</p><div class="PROCEDURE"><ol type="1"><li><p>Connect the serial port. The serial console will be on <ttclass="DEVICENAME">COM1</tt>.</p></li><li><p><tt class="COMMAND">echo -h > /boot.config</tt> to enable the serial console forthe boot loader and kernel.</p></li><li><p>Edit <tt class="FILENAME">/etc/ttys</tt> and change <var class="LITERAL">off</var> to<var class="LITERAL">on</var> for the <var class="LITERAL">ttyd0</var> entry. Thisenables a login prompt on the serial console, which mirrors how video consoles aretypically setup.</p></li><li><p><tt class="COMMAND">shutdown -r now</tt> will reboot the system with the serialconsole.</p></li></ol></div></div><div class="SECT2"><h2 class="SECT2"><a id="SERIALCONSOLE-HOWTO" name="SERIALCONSOLE-HOWTO">20.6.3 SerialConsole Configuration</a></h2><div class="PROCEDURE"><ol type="1"><li><p>Prepare a serial cable.</p><p>You will need either a null-modem cable or a standard serial cable and a null-modemadapter. See <a href="serial.html#SERIAL-CABLES-PORTS">Section 20.2.2</a> for adiscussion on serial cables.</p></li><li><p>Unplug your keyboard.</p><p>Most PC systems probe for the keyboard during the Power-On Self-Test (POST) and willgenerate an error if the keyboard is not detected. Some machines complain loudly aboutthe lack of a keyboard and will not continue to boot until it is plugged in.</p><p>If your computer complains about the error, but boots anyway, then you do not have todo anything special. (Some machines with Phoenix BIOS installed merely say ``<ttclass="ERRORNAME">Keyboard failed</tt>'' and continue to boot normally.)</p><p>If your computer refuses to boot without a keyboard attached then you will have toconfigure the BIOS so that it ignores this error (if it can). Consult your motherboard'smanual for details on how to do this.</p><div class="TIP"><blockquote class="TIP"><p><b>Tip:</b> Setting the keyboard to ``Not installed'' in the BIOS setup does <spanclass="emphasis"><i class="EMPHASIS">not</i></span> mean that you will not be able to useyour keyboard. All this does is tell the BIOS not to probe for a keyboard at power-on, soit will not complain if the keyboard is not plugged in. You can leave the keyboardplugged in even with this flag set to ``Not installed'' and the keyboard will stillwork.</p></blockquote></div><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> If your system has a <span class="TRADEMARK">PS/2</span>® mouse,chances are very good that you may have to unplug your mouse as well as your keyboard.This is because <span class="TRADEMARK">PS/2</span> mice share some hardware with thekeyboard and leaving the mouse plugged in can fool the keyboard probe into thinking thekeyboard is still there. It is said that a Gateway 2000 Pentium 90 MHz system withan AMI BIOS that behaves this way. In general, this is not a problem since the mouse isnot much good without the keyboard anyway.</p></blockquote></div></li><li><p>Plug a dumb terminal into <tt class="DEVICENAME">COM1</tt> (<ttclass="DEVICENAME">sio0</tt>).</p><p>If you do not have a dumb terminal, you can use an old PC/XT with a modem program, orthe serial port on another <span class="TRADEMARK">UNIX</span>® box. If you do nothave a <tt class="DEVICENAME">COM1</tt> (<tt class="DEVICENAME">sio0</tt>), get one. Atthis time, there is no way to select a port other than <tt class="DEVICENAME">COM1</tt>for the boot blocks without recompiling the boot blocks. If you are already using <ttclass="DEVICENAME">COM1</tt> for another device, you will have to temporarily remove thatdevice and install a new boot block and kernel once you get FreeBSD up and running. (Itis assumed that <tt class="DEVICENAME">COM1</tt> will be available on afile/compute/terminal server anyway; if you really need <tt class="DEVICENAME">COM1</tt>for something else (and you cannot switch that something else to <ttclass="DEVICENAME">COM2</tt> (<tt class="DEVICENAME">sio1</tt>)), then you probablyshould not even be bothering with all this in the first place.)</p></li><li><p>Make sure the configuration file of your kernel has appropriate flags set for <ttclass="DEVICENAME">COM1</tt> (<tt class="DEVICENAME">sio0</tt>).</p><p>Relevant flags are:</p><div class="VARIABLELIST"><dl><dt><var class="LITERAL">0x10</var></dt><dd><p>Enables console support for this unit. The other console flags are ignored unless thisis set. Currently, at most one unit can have console support; the first one (in configfile order) with this flag set is preferred. This option alone will not make the serialport the console. Set the following flag or use the <var class="OPTION">-h</var> optiondescribed below, together with this flag.</p></dd><dt><var class="LITERAL">0x20</var></dt><dd><p>Forces this unit to be the console (unless there is another higher priority console),regardless of the <var class="OPTION">-h</var> option discussed below. This flag replacesthe <var class="LITERAL">COMCONSOLE</var> option in FreeBSD versions 2.<varclass="REPLACEABLE">X</var>. The flag <var class="LITERAL">0x20</var> must be usedtogether with the <var class="OPTION">0x10</var> flag.</p></dd><dt><var class="LITERAL">0x40</var></dt><dd><p>Reserves this unit (in conjunction with <var class="LITERAL">0x10</var>) and makes theunit unavailable for normal access. You should not set this flag to the serial port unitwhich you want to use as the serial console. The only use of this flag is to designatethe unit for kernel remote debugging. See <ahref="../../../../doc/en_US.ISO8859-1/books/developers-handbook/index.html"target="_top">The Developer's Handbook</a> for more information on remote debugging.</p><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> In FreeBSD 4.0 or later the semantics of the flag <varclass="LITERAL">0x40</var> are slightly different and there is another flag to specify aserial port for remote debugging.</p></blockquote></div></dd></dl></div><p>Example:</p><pre class="PROGRAMLISTING">device sio0 at isa? port IO_COM1 flags 0x10 irq 4</pre><p>See the <a href="http://www.FreeBSD.org/cgi/man.cgi?query=sio&sektion=4"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sio</span>(4)</span></a> manual page formore details.</p><p>If the flags were not set, you need to run UserConfig (on a different console) orrecompile the kernel.</p></li><li><p>Create <tt class="FILENAME">boot.config</tt> in the root directory of the <varclass="LITERAL">a</var> partition on the boot drive.</p><p>This file will instruct the boot block code how you would like to boot the system. Inorder to activate the serial console, you need one or more of the following options--ifyou want multiple options, include them all on the same line:</p><div class="VARIABLELIST"><dl><dt><var class="OPTION">-h</var></dt><dd><p>Toggles internal and serial consoles. You can use this to switch console devices. Forinstance, if you boot from the internal (video) console, you can use <varclass="OPTION">-h</var> to direct the boot loader and the kernel to use the serial portas its console device. Alternatively, if you boot from the serial port, you can use the<var class="OPTION">-h</var> to tell the boot loader and the kernel to use the videodisplay as the console instead.</p></dd><dt><var class="OPTION">-D</var></dt><dd><p>Toggles single and dual console configurations. In the single configuration theconsole will be either the internal console (video display) or the serial port, dependingon the state of the <var class="OPTION">-h</var> option above. In the dual consoleconfiguration, both the video display and the serial port will become the console at thesame time, regardless of the state of the <var class="OPTION">-h</var> option. However,note that the dual console configuration takes effect only during the boot block isrunning. Once the boot loader gets control, the console specified by the <varclass="OPTION">-h</var> option becomes the only console.</p></dd><dt><var class="OPTION">-P</var></dt><dd><p>Makes the boot block probe the keyboard. If no keyboard is found, the <varclass="OPTION">-D</var> and <var class="OPTION">-h</var> options are automaticallyset.</p><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> Due to space constraints in the current version of the boot blocks, the<var class="OPTION">-P</var> option is capable of detecting extended keyboards only.Keyboards with less than 101 keys (and without F11 and F12 keys) may not be detected.Keyboards on some laptop computers may not be properly found because of this limitation.If this is the case with your system, you have to abandon using the <varclass="OPTION">-P</var> option. Unfortunately there is no workaround for thisproblem.</p></blockquote></div></dd></dl></div><p>Use either the <var class="OPTION">-P</var> option to select the consoleautomatically, or the <var class="OPTION">-h</var> option to activate the serialconsole.</p><p>You may include other options described in <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=boot&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">boot</span>(8)</span></a> as well.</p><p>The options, except for <var class="OPTION">-P</var>, will be passed to the bootloader (<tt class="FILENAME">/boot/loader</tt>). The boot loader will determine which ofthe internal video or the serial port should become the console by examining the state ofthe <var class="OPTION">-h</var> option alone. This means that if you specify the <varclass="OPTION">-D</var> option but not the <var class="OPTION">-h</var> option in <ttclass="FILENAME">/boot.config</tt>, you can use the serial port as the console onlyduring the boot block; the boot loader will use the internal video display as theconsole.</p></li><li><p>Boot the machine.</p><p>When you start your FreeBSD box, the boot blocks will echo the contents of <ttclass="FILENAME">/boot.config</tt> to the console. For example:</p><pre class="SCREEN">/boot.config: -PKeyboard: no</pre><p>The second line appears only if you put <var class="OPTION">-P</var> in <ttclass="FILENAME">/boot.config</tt> and indicates presence/absence of the keyboard. Thesemessages go to either serial or internal console, or both, depending on the option in <ttclass="FILENAME">/boot.config</tt>.</p><div class="INFORMALTABLE"><a id="AEN29712" name="AEN29712"></a><table border="0" frame="void" class="CALSTABLE"><col /><col /><thead><tr><th>Options</th><th>Message goes to</th></tr></thead><tbody><tr><td>none</td><td>internal console</td></tr><tr><td><var class="OPTION">-h</var></td><td>serial console</td></tr><tr><td><var class="OPTION">-D</var></td><td>serial and internal consoles</td></tr><tr><td><var class="OPTION">-Dh</var></td><td>serial and internal consoles</td></tr><tr><td><var class="OPTION">-P</var>, keyboard present</td><td>internal console</td></tr><tr><td><var class="OPTION">-P</var>, keyboard absent</td><td>serial console</td></tr></tbody></table></div><p>After the above messages, there will be a small pause before the boot blocks continueloading the boot loader and before any further messages printed to the console. Undernormal circumstances, you do not need to interrupt the boot blocks, but you may want todo so in order to make sure things are set up correctly.</p><p>Hit any key, other than <span class="KEYCODE">Enter</span>, at the console tointerrupt the boot process. The boot blocks will then prompt you for further action. Youshould now see something like:</p><pre class="SCREEN">>> FreeBSD/i386 BOOTDefault: 0:ad(0,a)/boot/loaderboot:</pre><p>Verify the above message appears on either the serial or internal console or both,according to the options you put in <tt class="FILENAME">/boot.config</tt>. If themessage appears in the correct console, hit <span class="KEYCODE">Enter</span> tocontinue the boot process.</p><p>If you want the serial console but you do not see the prompt on the serial terminal,something is wrong with your settings. In the meantime, you enter <varclass="OPTION">-h</var> and hit Enter/Return (if possible) to tell the boot block (andthen the boot loader and the kernel) to choose the serial port for the console. Once thesystem is up, go back and check what went wrong.</p></li></ol></div><p>After the boot loader is loaded and you are in the third stage of the boot process youcan still switch between the internal console and the serial console by settingappropriate environment variables in the boot loader. See <ahref="serialconsole-setup.html#SERIALCONSOLE-LOADER">Section 20.6.6</a>.</p></div><div class="SECT2"><h2 class="SECT2"><a id="SERIALCONSOLE-SUMMARY" name="SERIALCONSOLE-SUMMARY">20.6.4Summary</a></h2><p>Here is the summary of various settings discussed in this section and the consoleeventually selected.</p><div class="SECT3"><h3 class="SECT3"><a id="AEN29756" name="AEN29756">20.6.4.1 Case 1: You Set the Flags to0x10 for <tt class="DEVICENAME">sio0</tt></a></h3><pre class="PROGRAMLISTING">device sio0 at isa? port IO_COM1 flags 0x10 irq 4</pre>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -