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