serial-console.rst 4.3 KB
Newer Older
1 2
.. _serial_console:

3 4
Linux Serial Console
====================
L
Linus Torvalds 已提交
5 6 7

To use a serial port as console you need to compile the support into your
kernel - by default it is not compiled in. For PC style serial ports
8 9 10 11
it's the config option next to menu option:

:menuselection:`Character devices --> Serial drivers --> 8250/16550 and compatible serial support --> Console on 8250/16550 and compatible serial port`

L
Linus Torvalds 已提交
12 13 14 15 16 17
You must compile serial support into the kernel and not as a module.

It is possible to specify multiple devices for console output. You can
define a new kernel command line option to select which device(s) to
use for console output.

18
The format of this option is::
L
Linus Torvalds 已提交
19 20 21 22 23 24 25

	console=device,options

	device:		tty0 for the foreground virtual console
			ttyX for any other virtual console
			ttySx for a serial port
			lp0 for the first parallel port
26
			ttyUSB0 for the first USB serial device
L
Linus Torvalds 已提交
27 28

	options:	depend on the driver. For the serial port this
29 30 31 32
			defines the baudrate/parity/bits/flow control of
			the port, in the format BBBBPNF, where BBBB is the
			speed, P is parity (n/o/e), N is number of bits,
			and F is flow control ('r' for RTS). Default is
L
Linus Torvalds 已提交
33 34 35 36
			9600n8. The maximum baudrate is 115200.

You can specify multiple console= options on the kernel command line.
Output will appear on all of them. The last device will be used when
37
you open ``/dev/console``. So, for example::
L
Linus Torvalds 已提交
38 39 40

	console=ttyS1,9600 console=tty0

41
defines that opening ``/dev/console`` will get you the current foreground
L
Linus Torvalds 已提交
42 43 44 45 46 47 48 49 50 51 52
virtual console, and kernel messages will appear on both the VGA
console and the 2nd serial port (ttyS1 or COM2) at 9600 baud.

Note that you can only define one console per device type (serial, video).

If no console device is specified, the first device found capable of
acting as a system console will be used. At this time, the system
first looks for a VGA card and then for a serial port. So if you don't
have a VGA card in your system the first serial port will automatically
become the console.

53 54
You will need to create a new device to use ``/dev/console``. The official
``/dev/console`` is now character device 5,1.
L
Linus Torvalds 已提交
55

56
(You can also use a network device as a console.  See
57
``Documentation/networking/netconsole.txt`` for information on that.)
58

59
Here's an example that will use ``/dev/ttyS1`` (COM2) as the console.
L
Linus Torvalds 已提交
60 61
Replace the sample values as needed.

62 63
1. Create ``/dev/console`` (real console) and ``/dev/tty0`` (master virtual
   console)::
L
Linus Torvalds 已提交
64

65 66 67 68
     cd /dev
     rm -f console tty0
     mknod -m 622 console c 5 1
     mknod -m 622 tty0 c 4 0
L
Linus Torvalds 已提交
69 70 71

2. LILO can also take input from a serial device. This is a very
   useful option. To tell LILO to use the serial port:
72
   In lilo.conf (global section)::
L
Linus Torvalds 已提交
73

74
     serial  = 1,9600n8 (ttyS1, 9600 bd, no parity, 8 bits)
L
Linus Torvalds 已提交
75 76

3. Adjust to kernel flags for the new kernel,
77
   again in lilo.conf (kernel section)::
L
Linus Torvalds 已提交
78

79
     append = "console=ttyS1,9600"
L
Linus Torvalds 已提交
80 81 82

4. Make sure a getty runs on the serial port so that you can login to
   it once the system is done booting. This is done by adding a line
83
   like this to ``/etc/inittab`` (exact syntax depends on your getty)::
L
Linus Torvalds 已提交
84

85
     S1:23:respawn:/sbin/getty -L ttyS1 9600 vt100
L
Linus Torvalds 已提交
86

87
5. Init and ``/etc/ioctl.save``
L
Linus Torvalds 已提交
88

89 90
   Sysvinit remembers its stty settings in a file in ``/etc``, called
   ``/etc/ioctl.save``. REMOVE THIS FILE before using the serial
L
Linus Torvalds 已提交
91 92 93
   console for the first time, because otherwise init will probably
   set the baudrate to 38400 (baudrate of the virtual console).

94
6. ``/dev/console`` and X
L
Linus Torvalds 已提交
95
   Programs that want to do something with the virtual console usually
96
   open ``/dev/console``. If you have created the new ``/dev/console`` device,
L
Linus Torvalds 已提交
97 98
   and your console is NOT the virtual console some programs will fail.
   Those are programs that want to access the VT interface, and use
99
   ``/dev/console instead of /dev/tty0``. Some of those programs are::
L
Linus Torvalds 已提交
100

101
     Xfree86, svgalib, gpm, SVGATextMode
L
Linus Torvalds 已提交
102 103 104

   It should be fixed in modern versions of these programs though.

105 106 107
   Note that if you boot without a ``console=`` option (or with
   ``console=/dev/tty0``), ``/dev/console`` is the same as ``/dev/tty0``.
   In that case everything will still work.
L
Linus Torvalds 已提交
108 109 110 111 112 113 114 115

7. Thanks

   Thanks to Geert Uytterhoeven <geert@linux-m68k.org>
   for porting the patches from 2.1.4x to 2.1.6x for taking care of
   the integration of these patches into m68k, ppc and alpha.

Miquel van Smoorenburg <miquels@cistron.nl>, 11-Jun-2000