serial-console.rst 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. .. _serial_console:
  2. Linux Serial Console
  3. ====================
  4. To use a serial port as console you need to compile the support into your
  5. kernel - by default it is not compiled in. For PC style serial ports
  6. it's the config option next to menu option:
  7. :menuselection:`Character devices --> Serial drivers --> 8250/16550 and compatible serial support --> Console on 8250/16550 and compatible serial port`
  8. You must compile serial support into the kernel and not as a module.
  9. It is possible to specify multiple devices for console output. You can
  10. define a new kernel command line option to select which device(s) to
  11. use for console output.
  12. The format of this option is::
  13. console=device,options
  14. device: tty0 for the foreground virtual console
  15. ttyX for any other virtual console
  16. ttySx for a serial port
  17. lp0 for the first parallel port
  18. ttyUSB0 for the first USB serial device
  19. options: depend on the driver. For the serial port this
  20. defines the baudrate/parity/bits/flow control of
  21. the port, in the format BBBBPNF, where BBBB is the
  22. speed, P is parity (n/o/e), N is number of bits,
  23. and F is flow control ('r' for RTS). Default is
  24. 9600n8. The maximum baudrate is 115200.
  25. You can specify multiple console= options on the kernel command line.
  26. The behavior is well defined when each device type is mentioned only once.
  27. In this case, the output will appear on all requested consoles. And
  28. the last device will be used when you open ``/dev/console``.
  29. So, for example::
  30. console=ttyS1,9600 console=tty0
  31. defines that opening ``/dev/console`` will get you the current foreground
  32. virtual console, and kernel messages will appear on both the VGA
  33. console and the 2nd serial port (ttyS1 or COM2) at 9600 baud.
  34. The behavior is more complicated when the same device type is defined more
  35. times. In this case, there are the following two rules:
  36. 1. The output will appear only on the first device of each defined type.
  37. 2. ``/dev/console`` will be associated with the first registered device.
  38. Where the registration order depends on how kernel initializes various
  39. subsystems.
  40. This rule is used also when the last console= parameter is not used
  41. for other reasons. For example, because of a typo or because
  42. the hardware is not available.
  43. The result might be surprising. For example, the following two command
  44. lines have the same result::
  45. console=ttyS1,9600 console=tty0 console=tty1
  46. console=tty0 console=ttyS1,9600 console=tty1
  47. The kernel messages are printed only on ``tty0`` and ``ttyS1``. And
  48. ``/dev/console`` gets associated with ``tty0``. It is because kernel
  49. tries to register graphical consoles before serial ones. It does it
  50. because of the default behavior when no console device is specified,
  51. see below.
  52. Note that the last ``console=tty1`` parameter still makes a difference.
  53. The kernel command line is used also by systemd. It would use the last
  54. defined ``tty1`` as the login console.
  55. If no console device is specified, the first device found capable of
  56. acting as a system console will be used. At this time, the system
  57. first looks for a VGA card and then for a serial port. So if you don't
  58. have a VGA card in your system the first serial port will automatically
  59. become the console, unless the kernel is configured with the
  60. CONFIG_NULL_TTY_DEFAULT_CONSOLE option, then it will default to using the
  61. ttynull device.
  62. You will need to create a new device to use ``/dev/console``. The official
  63. ``/dev/console`` is now character device 5,1.
  64. (You can also use a network device as a console. See
  65. ``Documentation/networking/netconsole.rst`` for information on that.)
  66. Here's an example that will use ``/dev/ttyS1`` (COM2) as the console.
  67. Replace the sample values as needed.
  68. 1. Create ``/dev/console`` (real console) and ``/dev/tty0`` (master virtual
  69. console)::
  70. cd /dev
  71. rm -f console tty0
  72. mknod -m 622 console c 5 1
  73. mknod -m 622 tty0 c 4 0
  74. 2. LILO can also take input from a serial device. This is a very
  75. useful option. To tell LILO to use the serial port:
  76. In lilo.conf (global section)::
  77. serial = 1,9600n8 (ttyS1, 9600 bd, no parity, 8 bits)
  78. 3. Adjust to kernel flags for the new kernel,
  79. again in lilo.conf (kernel section)::
  80. append = "console=ttyS1,9600"
  81. 4. Make sure a getty runs on the serial port so that you can login to
  82. 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)::
  84. S1:23:respawn:/sbin/getty -L ttyS1 9600 vt100
  85. 5. Init and ``/etc/ioctl.save``
  86. Sysvinit remembers its stty settings in a file in ``/etc``, called
  87. ``/etc/ioctl.save``. REMOVE THIS FILE before using the serial
  88. console for the first time, because otherwise init will probably
  89. set the baudrate to 38400 (baudrate of the virtual console).
  90. 6. ``/dev/console`` and X
  91. Programs that want to do something with the virtual console usually
  92. open ``/dev/console``. If you have created the new ``/dev/console`` device,
  93. and your console is NOT the virtual console some programs will fail.
  94. Those are programs that want to access the VT interface, and use
  95. ``/dev/console instead of /dev/tty0``. Some of those programs are::
  96. Xfree86, svgalib, gpm, SVGATextMode
  97. It should be fixed in modern versions of these programs though.
  98. Note that if you boot without a ``console=`` option (or with
  99. ``console=/dev/tty0``), ``/dev/console`` is the same as ``/dev/tty0``.
  100. In that case everything will still work.
  101. 7. Thanks
  102. Thanks to Geert Uytterhoeven <geert@linux-m68k.org>
  103. for porting the patches from 2.1.4x to 2.1.6x for taking care of
  104. the integration of these patches into m68k, ppc and alpha.
  105. Miquel van Smoorenburg <miquels@cistron.nl>, 11-Jun-2000