← Documents Documentation/admin-guide/serial-console.rst GitHub 원문 ↗

Linux 6.18.37 · Administration

Linux Serial Console

Serial console built-in 설정, `console=` device·baud 문법, 여러 console의 output 및 `/dev/console` 선택 규칙과 LILO·getty 설정을 설명합니다.

Source pathDocumentation/admin-guide/serial-console.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

serial-console.rst:1-147

Serial console support는 module이 아니라 kernel built-in이어야 합니다. 여러 `console=` option을 쓸 때 각 type의 첫 device가 output을 받고, `/dev/console`은 kernel이 처음 등록한 console에 연결된다는 차이를 기억해야 합니다.

Bootloader output, kernel message, login getty는 서로 별도 설정입니다. LILO와 kernel command line, `/etc/inittab`을 모두 맞추고 기존 `/etc/ioctl.save`가 잘못된 baudrate를 복원하지 않게 제거합니다.

device의미
`tty0`현재 foreground virtual console
`ttyX`그 밖의 virtual console
`ttySx`Serial port
`lp0`첫 parallel port
`ttyUSB0`첫 USB serial device

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. _serial_console:
2
3 Linux Serial Console
4 ====================
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
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
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
18 The format of this option is::
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
26 ttyUSB0 for the first USB serial device
27
28 options: depend on the driver. For the serial port this
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
33 9600n8. The maximum baudrate is 115200.
34
35 You can specify multiple console= options on the kernel command line.
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::
41
42 console=ttyS1,9600 console=tty0
43
44 defines that opening ``/dev/console`` will get you the current foreground
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
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
62 lines have the same result::
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.
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, unless the kernel is configured with the
82 CONFIG_NULL_TTY_DEFAULT_CONSOLE option, then it will default to using the
83 ttynull device.
84
85 You will need to create a new device to use ``/dev/console``. The official
86 ``/dev/console`` is now character device 5,1.
87
88 (You can also use a network device as a console. See
89 ``Documentation/networking/netconsole.rst`` for information on that.)
90
91 Here's an example that will use ``/dev/ttyS1`` (COM2) as the console.
92 Replace the sample values as needed.
93
94 1. Create ``/dev/console`` (real console) and ``/dev/tty0`` (master virtual
95 console)::
96
97 cd /dev
98 rm -f console tty0
99 mknod -m 622 console c 5 1
100 mknod -m 622 tty0 c 4 0
101
102 2. LILO can also take input from a serial device. This is a very
103 useful option. To tell LILO to use the serial port:
104 In lilo.conf (global section)::
105
106 serial = 1,9600n8 (ttyS1, 9600 bd, no parity, 8 bits)
107
108 3. Adjust to kernel flags for the new kernel,
109 again in lilo.conf (kernel section)::
110
111 append = "console=ttyS1,9600"
112
113 4. Make sure a getty runs on the serial port so that you can login to
114 it once the system is done booting. This is done by adding a line
115 like this to ``/etc/inittab`` (exact syntax depends on your getty)::
116
117 S1:23:respawn:/sbin/getty -L ttyS1 9600 vt100
118
119 5. Init and ``/etc/ioctl.save``
120
121 Sysvinit remembers its stty settings in a file in ``/etc``, called
122 ``/etc/ioctl.save``. REMOVE THIS FILE before using the serial
123 console for the first time, because otherwise init will probably
124 set the baudrate to 38400 (baudrate of the virtual console).
125
126 6. ``/dev/console`` and X
127 Programs that want to do something with the virtual console usually
128 open ``/dev/console``. If you have created the new ``/dev/console`` device,
129 and your console is NOT the virtual console some programs will fail.
130 Those are programs that want to access the VT interface, and use
131 ``/dev/console instead of /dev/tty0``. Some of those programs are::
132
133 Xfree86, svgalib, gpm, SVGATextMode
134
135 It should be fixed in modern versions of these programs though.
136
137 Note that if you boot without a ``console=`` option (or with
138 ``console=/dev/tty0``), ``/dev/console`` is the same as ``/dev/tty0``.
139 In that case everything will still work.
140
141 7. Thanks
142
143 Thanks to Geert Uytterhoeven <geert@linux-m68k.org>
144 for porting the patches from 2.1.4x to 2.1.6x for taking care of
145 the integration of these patches into m68k, ppc and alpha.
146
147 Miquel van Smoorenburg <miquels@cistron.nl>, 11-Jun-2000
148

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Serial console build 설정과 `console=` 문법

1-34

Serial port를 console로 쓰려면 kernel에 support를 built-in으로 compile해야 합니다. 기본으로는 포함되지 않습니다. PC-style port는 `Character devices --> Serial drivers --> 8250/16550 and compatible serial support --> Console on 8250/16550 and compatible serial port` menu option에서 설정하며 module로 build하면 안 됩니다.

Console output에 여러 device를 지정할 수 있으며 kernel command line의 `console=` option으로 사용할 device를 고릅니다. 기본 형식은 다음과 같습니다.

console=device,options
device의미
`tty0`현재 foreground virtual console
`ttyX`그 밖의 virtual console
`ttySx`Serial port
`lp0`첫 parallel port
`ttyUSB0`첫 USB serial device

`options`는 driver에 따라 달라집니다. Serial port는 `BBBBPNF` 형식으로 baudrate, parity, data bits, flow control을 지정합니다. `BBBB`는 speed, `P`는 parity(`n`, `o`, `e`), `N`은 bit 수, `F`는 flow control이며 RTS는 `r`입니다. 기본값은 `9600n8`, 최대 baudrate는 115200입니다.

여러 console의 output과 `/dev/console` 선택

35-90

Kernel command line에는 `console=`을 여러 번 지정할 수 있습니다. 각 device type이 한 번만 나오면 output은 요청한 모든 console에 나타나고 마지막 device가 `/dev/console`을 열 때 사용됩니다.

console=ttyS1,9600 console=tty0

이 예에서 `/dev/console`은 현재 foreground virtual console이고 kernel message는 VGA console과 두 번째 serial port `ttyS1` 또는 COM2에 9600 baud로 출력됩니다.

같은 device type을 여러 번 지정하면 두 규칙이 적용됩니다. Output은 각 type의 첫 device에만 나타나고 `/dev/console`은 처음 등록된 device에 연결됩니다. 등록 순서는 kernel subsystem 초기화 순서에 따라 달라집니다.

마지막 `console=` parameter가 typo나 없는 hardware 때문에 사용되지 못할 때도 첫 등록 device 규칙이 적용됩니다. 다음 두 command line은 같은 결과를 만듭니다.

console=ttyS1,9600 console=tty0 console=tty1
console=tty0 console=ttyS1,9600 console=tty1

Kernel message는 `tty0`과 `ttyS1`에만 출력되고 `/dev/console`은 `tty0`에 연결됩니다. Kernel이 기본 동작 때문에 graphical console을 serial보다 먼저 등록하기 때문입니다.

마지막 `console=tty1`도 systemd에는 영향을 줍니다. Systemd는 kernel command line의 마지막 `tty1`을 login console로 사용합니다.

Console device를 지정하지 않으면 system console 역할이 가능한 첫 device를 씁니다. 현재는 VGA card를 먼저 찾고 다음으로 serial port를 찾습니다. VGA가 없으면 첫 serial port가 자동 console이 되지만 `CONFIG_NULL_TTY_DEFAULT_CONSOLE`이 설정되면 기본으로 `ttynull`을 사용합니다.

공식 `/dev/console`은 character device 5,1입니다. Network device를 console로 쓰려면 `Documentation/networking/netconsole.rst`를 참조하십시오.

Console output과 `/dev/console` 선택
각 device type의 첫 항목kernel message output 대상
kernel이 처음 등록한 console`/dev/console` 연결 대상
command line의 마지막 consolesystemd login console 후보

여러 `console=` parameter가 있을 때 output과 controlling device가 결정되는 방식입니다.

`/dev/ttyS1`을 console로 쓰는 예제와 주의 사항

91-147

다음은 `/dev/ttyS1`(COM2)을 console로 쓰는 예제이며 sample 값은 환경에 맞게 바꿉니다. 먼저 real console `/dev/console`과 master virtual console `/dev/tty0`을 만듭니다.

cd /dev
rm -f console tty0
mknod -m 622 console c 5 1
mknod -m 622 tty0 c 4 0

LILO도 serial device에서 input을 받을 수 있습니다. `lilo.conf` global section에 다음 설정을 둡니다.

serial  = 1,9600n8 (ttyS1, 9600 bd, no parity, 8 bits)

새 kernel flag는 `lilo.conf` kernel section에서 다음과 같이 조정합니다.

append = "console=ttyS1,9600"

Boot가 끝난 뒤 serial port로 login할 수 있도록 getty를 실행해야 합니다. 정확한 문법은 getty에 따라 다르며 `/etc/inittab`에 다음과 같은 줄을 추가합니다.

S1:23:respawn:/sbin/getty -L ttyS1 9600 vt100

Sysvinit은 stty 설정을 `/etc/ioctl.save`에 기억합니다. Serial console을 처음 사용하기 전에 이 파일을 제거해야 합니다. 그렇지 않으면 init이 virtual console의 baudrate인 38400으로 설정할 수 있습니다.

Virtual console을 다루는 program은 흔히 `/dev/console`을 엽니다. 새 `/dev/console`을 만들었고 console이 virtual console이 아니면 VT interface를 원하면서 `/dev/tty0` 대신 `/dev/console`을 쓰는 program이 실패할 수 있습니다.

Xfree86, svgalib, gpm, SVGATextMode

Modern version에서는 이 문제가 수정됐어야 합니다. `console=` option 없이 또는 `console=/dev/tty0`으로 boot하면 `/dev/console`과 `/dev/tty0`이 같으므로 계속 동작합니다.

Geert Uytterhoeven `<geert@linux-m68k.org>`는 2.1.4x patch를 2.1.6x로 port하고 m68k, ppc, alpha 통합을 맡았습니다. 문서는 Miquel van Smoorenburg `<miquels@cistron.nl>`가 11-Jun-2000에 작성했습니다.