162306a36Sopenharmony_ci.. _serial_console:
262306a36Sopenharmony_ci
362306a36Sopenharmony_ciLinux Serial Console
462306a36Sopenharmony_ci====================
562306a36Sopenharmony_ci
662306a36Sopenharmony_ciTo use a serial port as console you need to compile the support into your
762306a36Sopenharmony_cikernel - by default it is not compiled in. For PC style serial ports
862306a36Sopenharmony_ciit's the config option next to menu option:
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci:menuselection:`Character devices --> Serial drivers --> 8250/16550 and compatible serial support --> Console on 8250/16550 and compatible serial port`
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ciYou must compile serial support into the kernel and not as a module.
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ciIt is possible to specify multiple devices for console output. You can
1562306a36Sopenharmony_cidefine a new kernel command line option to select which device(s) to
1662306a36Sopenharmony_ciuse for console output.
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ciThe format of this option is::
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci	console=device,options
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci	device:		tty0 for the foreground virtual console
2362306a36Sopenharmony_ci			ttyX for any other virtual console
2462306a36Sopenharmony_ci			ttySx for a serial port
2562306a36Sopenharmony_ci			lp0 for the first parallel port
2662306a36Sopenharmony_ci			ttyUSB0 for the first USB serial device
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci	options:	depend on the driver. For the serial port this
2962306a36Sopenharmony_ci			defines the baudrate/parity/bits/flow control of
3062306a36Sopenharmony_ci			the port, in the format BBBBPNF, where BBBB is the
3162306a36Sopenharmony_ci			speed, P is parity (n/o/e), N is number of bits,
3262306a36Sopenharmony_ci			and F is flow control ('r' for RTS). Default is
3362306a36Sopenharmony_ci			9600n8. The maximum baudrate is 115200.
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ciYou can specify multiple console= options on the kernel command line.
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ciThe behavior is well defined when each device type is mentioned only once.
3862306a36Sopenharmony_ciIn this case, the output will appear on all requested consoles. And
3962306a36Sopenharmony_cithe last device will be used when you open ``/dev/console``.
4062306a36Sopenharmony_ciSo, for example::
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci	console=ttyS1,9600 console=tty0
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_cidefines that opening ``/dev/console`` will get you the current foreground
4562306a36Sopenharmony_civirtual console, and kernel messages will appear on both the VGA
4662306a36Sopenharmony_ciconsole and the 2nd serial port (ttyS1 or COM2) at 9600 baud.
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ciThe behavior is more complicated when the same device type is defined more
4962306a36Sopenharmony_citimes. In this case, there are the following two rules:
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci1. The output will appear only on the first device of each defined type.
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci2. ``/dev/console`` will be associated with the first registered device.
5462306a36Sopenharmony_ci   Where the registration order depends on how kernel initializes various
5562306a36Sopenharmony_ci   subsystems.
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci   This rule is used also when the last console= parameter is not used
5862306a36Sopenharmony_ci   for other reasons. For example, because of a typo or because
5962306a36Sopenharmony_ci   the hardware is not available.
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ciThe result might be surprising. For example, the following two command
6262306a36Sopenharmony_cilines have the same result::
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci	console=ttyS1,9600 console=tty0 console=tty1
6562306a36Sopenharmony_ci	console=tty0 console=ttyS1,9600 console=tty1
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ciThe kernel messages are printed only on ``tty0`` and ``ttyS1``. And
6862306a36Sopenharmony_ci``/dev/console`` gets associated with ``tty0``. It is because kernel
6962306a36Sopenharmony_citries to register graphical consoles before serial ones. It does it
7062306a36Sopenharmony_cibecause of the default behavior when no console device is specified,
7162306a36Sopenharmony_cisee below.
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ciNote that the last ``console=tty1`` parameter still makes a difference.
7462306a36Sopenharmony_ciThe kernel command line is used also by systemd. It would use the last
7562306a36Sopenharmony_cidefined ``tty1`` as the login console.
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ciIf no console device is specified, the first device found capable of
7862306a36Sopenharmony_ciacting as a system console will be used. At this time, the system
7962306a36Sopenharmony_cifirst looks for a VGA card and then for a serial port. So if you don't
8062306a36Sopenharmony_cihave a VGA card in your system the first serial port will automatically
8162306a36Sopenharmony_cibecome the console.
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ciYou will need to create a new device to use ``/dev/console``. The official
8462306a36Sopenharmony_ci``/dev/console`` is now character device 5,1.
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci(You can also use a network device as a console.  See
8762306a36Sopenharmony_ci``Documentation/networking/netconsole.rst`` for information on that.)
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ciHere's an example that will use ``/dev/ttyS1`` (COM2) as the console.
9062306a36Sopenharmony_ciReplace the sample values as needed.
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci1. Create ``/dev/console`` (real console) and ``/dev/tty0`` (master virtual
9362306a36Sopenharmony_ci   console)::
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci     cd /dev
9662306a36Sopenharmony_ci     rm -f console tty0
9762306a36Sopenharmony_ci     mknod -m 622 console c 5 1
9862306a36Sopenharmony_ci     mknod -m 622 tty0 c 4 0
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci2. LILO can also take input from a serial device. This is a very
10162306a36Sopenharmony_ci   useful option. To tell LILO to use the serial port:
10262306a36Sopenharmony_ci   In lilo.conf (global section)::
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci     serial  = 1,9600n8 (ttyS1, 9600 bd, no parity, 8 bits)
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci3. Adjust to kernel flags for the new kernel,
10762306a36Sopenharmony_ci   again in lilo.conf (kernel section)::
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci     append = "console=ttyS1,9600"
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci4. Make sure a getty runs on the serial port so that you can login to
11262306a36Sopenharmony_ci   it once the system is done booting. This is done by adding a line
11362306a36Sopenharmony_ci   like this to ``/etc/inittab`` (exact syntax depends on your getty)::
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci     S1:23:respawn:/sbin/getty -L ttyS1 9600 vt100
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci5. Init and ``/etc/ioctl.save``
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci   Sysvinit remembers its stty settings in a file in ``/etc``, called
12062306a36Sopenharmony_ci   ``/etc/ioctl.save``. REMOVE THIS FILE before using the serial
12162306a36Sopenharmony_ci   console for the first time, because otherwise init will probably
12262306a36Sopenharmony_ci   set the baudrate to 38400 (baudrate of the virtual console).
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci6. ``/dev/console`` and X
12562306a36Sopenharmony_ci   Programs that want to do something with the virtual console usually
12662306a36Sopenharmony_ci   open ``/dev/console``. If you have created the new ``/dev/console`` device,
12762306a36Sopenharmony_ci   and your console is NOT the virtual console some programs will fail.
12862306a36Sopenharmony_ci   Those are programs that want to access the VT interface, and use
12962306a36Sopenharmony_ci   ``/dev/console instead of /dev/tty0``. Some of those programs are::
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci     Xfree86, svgalib, gpm, SVGATextMode
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci   It should be fixed in modern versions of these programs though.
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci   Note that if you boot without a ``console=`` option (or with
13662306a36Sopenharmony_ci   ``console=/dev/tty0``), ``/dev/console`` is the same as ``/dev/tty0``.
13762306a36Sopenharmony_ci   In that case everything will still work.
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci7. Thanks
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci   Thanks to Geert Uytterhoeven <geert@linux-m68k.org>
14262306a36Sopenharmony_ci   for porting the patches from 2.1.4x to 2.1.6x for taking care of
14362306a36Sopenharmony_ci   the integration of these patches into m68k, ppc and alpha.
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ciMiquel van Smoorenburg <miquels@cistron.nl>, 11-Jun-2000
146