← Documents Documentation/networking/netconsole.rst GitHub 원문 ↗

Linux 6.18.37 · Networking

Netconsole

커널 printk 로그를 UDP로 원격 전송하고 configfs에서 대상과 부가 데이터를 동적으로 관리하는 방법입니다.

Source pathDocumentation/networking/netconsole.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약·해설

netconsole.rst:1-462

Netconsole은 디스크 로그나 직렬 콘솔을 사용할 수 없는 장애 상황을 위해 커널 로그를 UDP로 전송합니다. 정적 부팅 인자와 configfs 동적 대상, 확장 `/dev/kmsg` 형식, 사용자·시스템 메타데이터 및 조각화를 함께 지원합니다.

Netconsole 기능 지도
영역핵심 기능
송신 경로printk → netpoll → UDP → 원격 수신기
동적 구성configfs 대상 추가·수정·삭제
부가 데이터사용자 키, taskname, release, CPU, msgid
확장 형식메타데이터 헤더와 ncfrag 조각화

문서의 주요 설정 영역을 한눈에 정리했습니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ==========
4 Netconsole
5 ==========
6
7
8 started by Ingo Molnar <mingo@redhat.com>, 2001.09.17
9
10 2.6 port and netpoll api by Matt Mackall <mpm@selenic.com>, Sep 9 2003
11
12 IPv6 support by Cong Wang <xiyou.wangcong@gmail.com>, Jan 1 2013
13
14 Extended console support by Tejun Heo <tj@kernel.org>, May 1 2015
15
16 Release prepend support by Breno Leitao <leitao@debian.org>, Jul 7 2023
17
18 Userdata append support by Matthew Wood <thepacketgeek@gmail.com>, Jan 22 2024
19
20 Sysdata append support by Breno Leitao <leitao@debian.org>, Jan 15 2025
21
22 Introduction:
23 =============
24
25 This module logs kernel printk messages over UDP allowing debugging of
26 problem where disk logging fails and serial consoles are impractical.
27
28 It can be used either built-in or as a module. As a built-in,
29 netconsole initializes immediately after NIC cards and will bring up
30 the specified interface as soon as possible. While this doesn't allow
31 capture of early kernel panics, it does capture most of the boot
32 process.
33
34 Sender and receiver configuration:
35 ==================================
36
37 It takes a string configuration parameter "netconsole" in the
38 following format::
39
40 netconsole=[+][r][src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr]
41
42 where
43 + if present, enable extended console support
44 r if present, prepend kernel version (release) to the message
45 src-port source for UDP packets (defaults to 6665)
46 src-ip source IP to use (interface address)
47 dev network interface name (eth0) or MAC address
48 tgt-port port for logging agent (6666)
49 tgt-ip IP address for logging agent
50 tgt-macaddr ethernet MAC address for logging agent (broadcast)
51
52 Examples::
53
54 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc
55
56 or::
57
58 insmod netconsole netconsole=@/,@10.0.0.2/
59
60 or using IPv6::
61
62 insmod netconsole netconsole=@/,@fd00:1:2:3::1/
63
64 or using a MAC address to select the egress interface::
65
66 linux netconsole=4444@10.0.0.1/22:33:44:55:66:77,9353@10.0.0.2/12:34:56:78:9a:bc
67
68 It also supports logging to multiple remote agents by specifying
69 parameters for the multiple agents separated by semicolons and the
70 complete string enclosed in "quotes", thusly::
71
72 modprobe netconsole netconsole="@/,@10.0.0.2/;@/eth1,6892@10.0.0.3/"
73
74 Built-in netconsole starts immediately after the TCP stack is
75 initialized and attempts to bring up the supplied dev at the supplied
76 address.
77
78 The remote host has several options to receive the kernel messages,
79 for example:
80
81 1) syslogd
82
83 2) netcat
84
85 On distributions using a BSD-based netcat version (e.g. Fedora,
86 openSUSE and Ubuntu) the listening port must be specified without
87 the -p switch::
88
89 nc -u -l -p <port>' / 'nc -u -l <port>
90
91 or::
92
93 netcat -u -l -p <port>' / 'netcat -u -l <port>
94
95 3) socat
96
97 ::
98
99 socat udp-recv:<port> -
100
101 Dynamic reconfiguration:
102 ========================
103
104 Dynamic reconfigurability is a useful addition to netconsole that enables
105 remote logging targets to be dynamically added, removed, or have their
106 parameters reconfigured at runtime from a configfs-based userspace interface.
107
108 To include this feature, select CONFIG_NETCONSOLE_DYNAMIC when building the
109 netconsole module (or kernel, if netconsole is built-in).
110
111 Some examples follow (where configfs is mounted at the /sys/kernel/config
112 mountpoint).
113
114 To add a remote logging target (target names can be arbitrary)::
115
116 cd /sys/kernel/config/netconsole/
117 mkdir target1
118
119 Note that newly created targets have default parameter values (as mentioned
120 above) and are disabled by default -- they must first be enabled by writing
121 "1" to the "enabled" attribute (usually after setting parameters accordingly)
122 as described below.
123
124 To remove a target::
125
126 rmdir /sys/kernel/config/netconsole/othertarget/
127
128 The interface exposes these parameters of a netconsole target to userspace:
129
130 =============== ================================= ============
131 enabled Is this target currently enabled? (read-write)
132 extended Extended mode enabled (read-write)
133 release Prepend kernel release to message (read-write)
134 dev_name Local network interface name (read-write)
135 local_port Source UDP port to use (read-write)
136 remote_port Remote agent's UDP port (read-write)
137 local_ip Source IP address to use (read-write)
138 remote_ip Remote agent's IP address (read-write)
139 local_mac Local interface's MAC address (read-only)
140 remote_mac Remote agent's MAC address (read-write)
141 transmit_errors Number of packet send errors (read-only)
142 =============== ================================= ============
143
144 The "enabled" attribute is also used to control whether the parameters of
145 a target can be updated or not -- you can modify the parameters of only
146 disabled targets (i.e. if "enabled" is 0).
147
148 To update a target's parameters::
149
150 cat enabled # check if enabled is 1
151 echo 0 > enabled # disable the target (if required)
152 echo eth2 > dev_name # set local interface
153 echo 10.0.0.4 > remote_ip # update some parameter
154 echo cb:a9:87:65:43:21 > remote_mac # update more parameters
155 echo 1 > enabled # enable target again
156
157 You can also update the local interface dynamically. This is especially
158 useful if you want to use interfaces that have newly come up (and may not
159 have existed when netconsole was loaded / initialized).
160
161 Netconsole targets defined at boot time (or module load time) with the
162 `netconsole=` param are assigned the name `cmdline<index>`. For example, the
163 first target in the parameter is named `cmdline0`. You can control and modify
164 these targets by creating configfs directories with the matching name.
165
166 Let's suppose you have two netconsole targets defined at boot time::
167
168 netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc;4444@10.0.0.1/eth1,9353@10.0.0.3/12:34:56:78:9a:bc
169
170 You can modify these targets in runtime by creating the following targets::
171
172 mkdir cmdline0
173 cat cmdline0/remote_ip
174 10.0.0.2
175
176 mkdir cmdline1
177 cat cmdline1/remote_ip
178 10.0.0.3
179
180 Append User Data
181 ----------------
182
183 Custom user data can be appended to the end of messages with netconsole
184 dynamic configuration enabled. User data entries can be modified without
185 changing the "enabled" attribute of a target.
186
187 Directories (keys) under `userdata` are limited to 53 character length, and
188 data in `userdata/<key>/value` are limited to 200 bytes::
189
190 cd /sys/kernel/config/netconsole && mkdir cmdline0
191 cd cmdline0
192 mkdir userdata/foo
193 echo bar > userdata/foo/value
194 mkdir userdata/qux
195 echo baz > userdata/qux/value
196
197 Messages will now include this additional user data::
198
199 echo "This is a message" > /dev/kmsg
200
201 Sends::
202
203 12,607,22085407756,-;This is a message
204 foo=bar
205 qux=baz
206
207 Preview the userdata that will be appended with::
208
209 cd /sys/kernel/config/netconsole/cmdline0/userdata
210 for f in `ls userdata`; do echo $f=$(cat userdata/$f/value); done
211
212 If a `userdata` entry is created but no data is written to the `value` file,
213 the entry will be omitted from netconsole messages::
214
215 cd /sys/kernel/config/netconsole && mkdir cmdline0
216 cd cmdline0
217 mkdir userdata/foo
218 echo bar > userdata/foo/value
219 mkdir userdata/qux
220
221 The `qux` key is omitted since it has no value::
222
223 echo "This is a message" > /dev/kmsg
224 12,607,22085407756,-;This is a message
225 foo=bar
226
227 Delete `userdata` entries with `rmdir`::
228
229 rmdir /sys/kernel/config/netconsole/cmdline0/userdata/qux
230
231 .. warning::
232 When writing strings to user data values, input is broken up per line in
233 configfs store calls and this can cause confusing behavior::
234
235 mkdir userdata/testing
236 printf "val1\nval2" > userdata/testing/value
237 # userdata store value is called twice, first with "val1\n" then "val2"
238 # so "val2" is stored, being the last value stored
239 cat userdata/testing/value
240 val2
241
242 It is recommended to not write user data values with newlines.
243
244 Task name auto population in userdata
245 -------------------------------------
246
247 Inside the netconsole configfs hierarchy, there is a file called
248 `taskname_enabled` under the `userdata` directory. This file is used to enable
249 or disable the automatic task name population feature. This feature
250 automatically populates the current task name that is scheduled in the CPU
251 sneding the message.
252
253 To enable task name auto-population::
254
255 echo 1 > /sys/kernel/config/netconsole/target1/userdata/taskname_enabled
256
257 When this option is enabled, the netconsole messages will include an additional
258 line in the userdata field with the format `taskname=<task name>`. This allows
259 the receiver of the netconsole messages to easily find which application was
260 currently scheduled when that message was generated, providing extra context
261 for kernel messages and helping to categorize them.
262
263 Example::
264
265 echo "This is a message" > /dev/kmsg
266 12,607,22085407756,-;This is a message
267 taskname=echo
268
269 In this example, the message was generated while "echo" was the current
270 scheduled process.
271
272 Kernel release auto population in userdata
273 ------------------------------------------
274
275 Within the netconsole configfs hierarchy, there is a file named `release_enabled`
276 located in the `userdata` directory. This file controls the kernel release
277 (version) auto-population feature, which appends the kernel release information
278 to userdata dictionary in every message sent.
279
280 To enable the release auto-population::
281
282 echo 1 > /sys/kernel/config/netconsole/target1/userdata/release_enabled
283
284 Example::
285
286 echo "This is a message" > /dev/kmsg
287 12,607,22085407756,-;This is a message
288 release=6.14.0-rc6-01219-g3c027fbd941d
289
290 .. note::
291
292 This feature provides the same data as the "release prepend" feature.
293 However, in this case, the release information is appended to the userdata
294 dictionary rather than being included in the message header.
295
296
297 CPU number auto population in userdata
298 --------------------------------------
299
300 Inside the netconsole configfs hierarchy, there is a file called
301 `cpu_nr` under the `userdata` directory. This file is used to enable or disable
302 the automatic CPU number population feature. This feature automatically
303 populates the CPU number that is sending the message.
304
305 To enable the CPU number auto-population::
306
307 echo 1 > /sys/kernel/config/netconsole/target1/userdata/cpu_nr
308
309 When this option is enabled, the netconsole messages will include an additional
310 line in the userdata field with the format `cpu=<cpu_number>`. This allows the
311 receiver of the netconsole messages to easily differentiate and demultiplex
312 messages originating from different CPUs, which is particularly useful when
313 dealing with parallel log output.
314
315 Example::
316
317 echo "This is a message" > /dev/kmsg
318 12,607,22085407756,-;This is a message
319 cpu=42
320
321 In this example, the message was sent by CPU 42.
322
323 .. note::
324
325 If the user has set a conflicting `cpu` key in the userdata dictionary,
326 both keys will be reported, with the kernel-populated entry appearing after
327 the user one. For example::
328
329 # User-defined CPU entry
330 mkdir -p /sys/kernel/config/netconsole/target1/userdata/cpu
331 echo "1" > /sys/kernel/config/netconsole/target1/userdata/cpu/value
332
333 Output might look like::
334
335 12,607,22085407756,-;This is a message
336 cpu=1
337 cpu=42 # kernel-populated value
338
339
340 Message ID auto population in userdata
341 --------------------------------------
342
343 Within the netconsole configfs hierarchy, there is a file named `msgid_enabled`
344 located in the `userdata` directory. This file controls the message ID
345 auto-population feature, which assigns a numeric id to each message sent to a
346 given target and appends the ID to userdata dictionary in every message sent.
347
348 The message ID is generated using a per-target 32 bit counter that is
349 incremented for every message sent to the target. Note that this counter will
350 eventually wrap around after reaching uint32_t max value, so the message ID is
351 not globally unique over time. However, it can still be used by the target to
352 detect if messages were dropped before reaching the target by identifying gaps
353 in the sequence of IDs.
354
355 It is important to distinguish message IDs from the message <sequnum> field.
356 Some kernel messages may never reach netconsole (for example, due to printk
357 rate limiting). Thus, a gap in <sequnum> cannot be solely relied upon to
358 indicate that a message was dropped during transmission, as it may never have
359 been sent via netconsole. The message ID, on the other hand, is only assigned
360 to messages that are actually transmitted via netconsole.
361
362 Example::
363
364 echo "This is message #1" > /dev/kmsg
365 echo "This is message #2" > /dev/kmsg
366 13,434,54928466,-;This is message #1
367 msgid=1
368 13,435,54934019,-;This is message #2
369 msgid=2
370
371
372 Extended console:
373 =================
374
375 If '+' is prefixed to the configuration line or "extended" config file
376 is set to 1, extended console support is enabled. An example boot
377 param follows::
378
379 linux netconsole=+4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc
380
381 Log messages are transmitted with extended metadata header in the
382 following format which is the same as /dev/kmsg::
383
384 <level>,<sequnum>,<timestamp>,<contflag>;<message text>
385
386 If 'r' (release) feature is enabled, the kernel release version is
387 prepended to the start of the message. Example::
388
389 6.4.0,6,444,501151268,-;netconsole: network logging started
390
391 Non printable characters in <message text> are escaped using "\xff"
392 notation. If the message contains optional dictionary, verbatim
393 newline is used as the delimiter.
394
395 If a message doesn't fit in certain number of bytes (currently 1000),
396 the message is split into multiple fragments by netconsole. These
397 fragments are transmitted with "ncfrag" header field added::
398
399 ncfrag=<byte-offset>/<total-bytes>
400
401 For example, assuming a lot smaller chunk size, a message "the first
402 chunk, the 2nd chunk." may be split as follows::
403
404 6,416,1758426,-,ncfrag=0/31;the first chunk,
405 6,416,1758426,-,ncfrag=16/31; the 2nd chunk.
406
407 Miscellaneous notes:
408 ====================
409
410 .. Warning::
411
412 the default target ethernet setting uses the broadcast
413 ethernet address to send packets, which can cause increased load on
414 other systems on the same ethernet segment.
415
416 .. Tip::
417
418 some LAN switches may be configured to suppress ethernet broadcasts
419 so it is advised to explicitly specify the remote agents' MAC addresses
420 from the config parameters passed to netconsole.
421
422 .. Tip::
423
424 to find out the MAC address of, say, 10.0.0.2, you may try using::
425
426 ping -c 1 10.0.0.2 ; /sbin/arp -n | grep 10.0.0.2
427
428 .. Tip::
429
430 in case the remote logging agent is on a separate LAN subnet than
431 the sender, it is suggested to try specifying the MAC address of the
432 default gateway (you may use /sbin/route -n to find it out) as the
433 remote MAC address instead.
434
435 .. note::
436
437 the network device (eth1 in the above case) can run any kind
438 of other network traffic, netconsole is not intrusive. Netconsole
439 might cause slight delays in other traffic if the volume of kernel
440 messages is high, but should have no other impact.
441
442 .. note::
443
444 if you find that the remote logging agent is not receiving or
445 printing all messages from the sender, it is likely that you have set
446 the "console_loglevel" parameter (on the sender) to only send high
447 priority messages to the console. You can change this at runtime using::
448
449 dmesg -n 8
450
451 or by specifying "debug" on the kernel command line at boot, to send
452 all kernel messages to the console. A specific value for this parameter
453 can also be set using the "loglevel" kernel boot option. See the
454 dmesg(8) man page and Documentation/admin-guide/kernel-parameters.rst
455 for details.
456
457 Netconsole was designed to be as instantaneous as possible, to
458 enable the logging of even the most critical kernel bugs. It works
459 from IRQ contexts as well, and does not enable interrupts while
460 sending packets. Due to these unique needs, configuration cannot
461 be more automatic, and some fundamental limitations will remain:
462 only IP networks, UDP packets and ethernet devices are supported.
463

3. 한국어 전문 번역

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

소개와 초기화 시점

1-33

Netconsole은 2001년 Ingo Molnar가 시작했으며, 이후 netpoll API와 2.6 포팅, IPv6, 확장 콘솔, 커널 릴리스 접두사, 사용자 데이터와 시스템 데이터 기능이 차례로 추가되었습니다. 이 문서의 앞부분은 각 기능을 추가한 개발자와 날짜를 기록합니다.

이 모듈은 커널의 `printk` 메시지를 UDP로 전송합니다. 디스크에 로그를 남길 수 없는 장애이거나 직렬 콘솔을 쓰기 어려운 환경에서, 다른 호스트가 커널 로그를 받아 장애 원인을 조사하도록 하는 것이 목적입니다.

Netconsole은 커널에 내장하거나 모듈로 로드할 수 있습니다. 내장한 경우 NIC가 초기화된 직후 시작하여 지정한 인터페이스를 가능한 한 빨리 올립니다. 아주 이른 시점의 커널 패닉까지 잡을 수는 없지만 부팅 과정의 대부분은 수집할 수 있습니다.

.. SPDX-License-Identifier: GPL-2.0

==========
Netconsole
==========


started by Ingo Molnar <mingo@redhat.com>, 2001.09.17

2.6 port and netpoll api by Matt Mackall <mpm@selenic.com>, Sep 9 2003

IPv6 support by Cong Wang <xiyou.wangcong@gmail.com>, Jan 1 2013

Extended console support by Tejun Heo <tj@kernel.org>, May 1 2015

Release prepend support by Breno Leitao <leitao@debian.org>, Jul 7 2023

Userdata append support by Matthew Wood <thepacketgeek@gmail.com>, Jan 22 2024

Sysdata append support by Breno Leitao <leitao@debian.org>, Jan 15 2025

Introduction:
=============

This module logs kernel printk messages over UDP allowing debugging of
problem where disk logging fails and serial consoles are impractical.

It can be used either built-in or as a module. As a built-in,
netconsole initializes immediately after NIC cards and will bring up
the specified interface as soon as possible. While this doesn't allow
capture of early kernel panics, it does capture most of the boot
process.

송신자와 수신자 구성

34-100

`netconsole` 설정 문자열은 `[+][r][src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr]` 형식입니다. 앞의 `+`는 확장 콘솔을 켜고, `r`은 메시지 앞에 커널 릴리스 문자열을 붙입니다. 송신 UDP 포트 기본값은 6665이고 수신 포트 기본값은 6666입니다.

`src-ip`는 송신 인터페이스에 사용할 주소이며 `dev`에는 `eth0` 같은 인터페이스 이름 또는 해당 인터페이스의 MAC 주소를 지정할 수 있습니다. `tgt-ip`는 로그 수신자의 주소이고 `tgt-macaddr`는 수신자의 이더넷 MAC 주소입니다. 대상 MAC을 생략하면 브로드캐스트 주소를 사용합니다.

문서는 IPv4 주소와 명시적 포트 및 MAC을 모두 쓰는 부팅 인자, 대부분을 기본값으로 둔 모듈 로드, IPv6 대상, MAC 주소로 송신 인터페이스를 선택하는 예를 제공합니다. 여러 수신자로 동시에 보내려면 각 대상을 세미콜론으로 구분하고 전체 모듈 매개변수 문자열을 따옴표로 감쌉니다.

커널 내장형 Netconsole은 TCP 스택이 준비된 직후 시작하며 지정한 장치를 지정 주소로 올리려고 시도합니다. 원격 호스트에서는 `syslogd`, UDP 수신 모드의 `nc` 또는 `netcat`, `socat udp-recv:<port> -` 같은 방법으로 메시지를 받을 수 있습니다. BSD 계열 netcat을 쓰는 배포판은 구현에 따라 수신 포트에 `-p`를 붙이지 않아야 하므로 문서에 제시된 두 형식을 확인해야 합니다.

netconsole 설정 필드
필드의미기본값 또는 비고
+확장 콘솔 사용선택
r커널 릴리스 접두사 사용선택
src-port송신 UDP 포트6665
src-ip / dev송신 주소와 인터페이스인터페이스 이름 또는 MAC
tgt-port수신 UDP 포트6666
tgt-ip원격 로그 수신자 IP필수 대상
tgt-macaddr원격 이더넷 MAC생략하면 브로드캐스트

설정 문자열의 선택 표지와 주소 필드를 구조화했습니다.

Netconsole UDP 경로
kernel printknetconsole / netpollUDP packet
송신 NIC이더넷 네트워크원격 syslogd · netcat · socat

송신 커널에서 원격 수집기까지의 기본 데이터 경로입니다.

Sender and receiver configuration:
==================================

It takes a string configuration parameter "netconsole" in the
following format::

 netconsole=[+][r][src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr]

   where
        +             if present, enable extended console support
        r             if present, prepend kernel version (release) to the message
        src-port      source for UDP packets (defaults to 6665)
        src-ip        source IP to use (interface address)
        dev           network interface name (eth0) or MAC address
        tgt-port      port for logging agent (6666)
        tgt-ip        IP address for logging agent
        tgt-macaddr   ethernet MAC address for logging agent (broadcast)

Examples::

 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc

or::

 insmod netconsole netconsole=@/,@10.0.0.2/

or using IPv6::

 insmod netconsole netconsole=@/,@fd00:1:2:3::1/

or using a MAC address to select the egress interface::

   linux netconsole=4444@10.0.0.1/22:33:44:55:66:77,9353@10.0.0.2/12:34:56:78:9a:bc

It also supports logging to multiple remote agents by specifying
parameters for the multiple agents separated by semicolons and the
complete string enclosed in "quotes", thusly::

 modprobe netconsole netconsole="@/,@10.0.0.2/;@/eth1,6892@10.0.0.3/"

Built-in netconsole starts immediately after the TCP stack is
initialized and attempts to bring up the supplied dev at the supplied
address.

The remote host has several options to receive the kernel messages,
for example:

1) syslogd

2) netcat

   On distributions using a BSD-based netcat version (e.g. Fedora,
   openSUSE and Ubuntu) the listening port must be specified without
   the -p switch::

        nc -u -l -p <port>' / 'nc -u -l <port>

    or::

        netcat -u -l -p <port>' / 'netcat -u -l <port>

3) socat

::

   socat udp-recv:<port> -

configfs 동적 재구성

101-179

동적 재구성 기능을 사용하면 실행 중에 원격 로그 대상을 추가하거나 제거하고 매개변수를 바꿀 수 있습니다. 커널 또는 모듈을 빌드할 때 `CONFIG_NETCONSOLE_DYNAMIC`을 선택해야 하며, 예시는 configfs가 `/sys/kernel/config`에 마운트되어 있다고 가정합니다.

`/sys/kernel/config/netconsole/` 아래에 임의 이름의 디렉터리를 만들면 대상이 추가됩니다. 새 대상은 기본 매개변수를 가지지만 처음에는 비활성 상태이므로 필요한 값을 설정한 뒤 `enabled`에 `1`을 써야 합니다. 대상 디렉터리를 `rmdir`로 제거하면 해당 대상도 삭제됩니다.

대상은 활성 여부, 확장 모드, 릴리스 접두사, 로컬 장치 이름, 로컬·원격 UDP 포트, 로컬·원격 IP, 로컬·원격 MAC, 송신 오류 수를 configfs 속성으로 노출합니다. `local_mac`과 `transmit_errors`는 읽기 전용이고 나머지 설정 속성은 읽고 쓸 수 있습니다.

활성화된 대상의 매개변수는 수정할 수 없습니다. 먼저 `enabled`를 확인하고 필요하면 `0`을 써서 비활성화한 다음 `dev_name`, `remote_ip`, `remote_mac` 등을 바꾸고 다시 `1`을 써서 켭니다. 이 방식은 Netconsole이 초기화된 뒤 새로 생긴 로컬 인터페이스를 사용해야 할 때 특히 유용합니다.

부팅 또는 모듈 로드 시 `netconsole=`로 정의한 대상은 순서대로 `cmdline0`, `cmdline1` 같은 이름을 받습니다. 같은 이름의 configfs 디렉터리를 만들면 해당 명령행 대상을 제어하고 수정할 수 있습니다. 문서의 두 대상 예에서는 `cmdline0/remote_ip`가 `10.0.0.2`, `cmdline1/remote_ip`가 `10.0.0.3`임을 확인합니다.

동적 대상 속성
속성의미접근
enabled현재 대상 활성 여부읽기·쓰기
extended확장 모드읽기·쓰기
release커널 릴리스 접두사읽기·쓰기
dev_name로컬 인터페이스 이름읽기·쓰기
local_port / remote_port송신·수신 UDP 포트읽기·쓰기
local_ip / remote_ip송신·수신 IP 주소읽기·쓰기
local_mac로컬 인터페이스 MAC읽기 전용
remote_mac원격 수신자 MAC읽기·쓰기
transmit_errors패킷 송신 오류 수읽기 전용

configfs에서 보이는 대상별 설정과 접근 권한입니다.

Dynamic reconfiguration:
========================

Dynamic reconfigurability is a useful addition to netconsole that enables
remote logging targets to be dynamically added, removed, or have their
parameters reconfigured at runtime from a configfs-based userspace interface.

To include this feature, select CONFIG_NETCONSOLE_DYNAMIC when building the
netconsole module (or kernel, if netconsole is built-in).

Some examples follow (where configfs is mounted at the /sys/kernel/config
mountpoint).

To add a remote logging target (target names can be arbitrary)::

 cd /sys/kernel/config/netconsole/
 mkdir target1

Note that newly created targets have default parameter values (as mentioned
above) and are disabled by default -- they must first be enabled by writing
"1" to the "enabled" attribute (usually after setting parameters accordingly)
as described below.

To remove a target::

 rmdir /sys/kernel/config/netconsole/othertarget/

The interface exposes these parameters of a netconsole target to userspace:

        =============== =================================       ============
        enabled                Is this target currently enabled?        (read-write)
        extended        Extended mode enabled                        (read-write)
        release                Prepend kernel release to message        (read-write)
        dev_name        Local network interface name                (read-write)
        local_port        Source UDP port to use                        (read-write)
        remote_port        Remote agent's UDP port                        (read-write)
        local_ip        Source IP address to use                (read-write)
        remote_ip        Remote agent's IP address                (read-write)
        local_mac        Local interface's MAC address                (read-only)
        remote_mac        Remote agent's MAC address                (read-write)
        transmit_errors        Number of packet send errors                (read-only)
        =============== =================================       ============

The "enabled" attribute is also used to control whether the parameters of
a target can be updated or not -- you can modify the parameters of only
disabled targets (i.e. if "enabled" is 0).

To update a target's parameters::

 cat enabled                                # check if enabled is 1
 echo 0 > enabled                        # disable the target (if required)
 echo eth2 > dev_name                        # set local interface
 echo 10.0.0.4 > remote_ip                # update some parameter
 echo cb:a9:87:65:43:21 > remote_mac        # update more parameters
 echo 1 > enabled                        # enable target again

You can also update the local interface dynamically. This is especially
useful if you want to use interfaces that have newly come up (and may not
have existed when netconsole was loaded / initialized).

Netconsole targets defined at boot time (or module load time) with the
`netconsole=` param are assigned the name `cmdline<index>`.  For example, the
first target in the parameter is named `cmdline0`.  You can control and modify
these targets by creating configfs directories with the matching name.

Let's suppose you have two netconsole targets defined at boot time::

 netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc;4444@10.0.0.1/eth1,9353@10.0.0.3/12:34:56:78:9a:bc

You can modify these targets in runtime by creating the following targets::

 mkdir cmdline0
 cat cmdline0/remote_ip
 10.0.0.2

 mkdir cmdline1
 cat cmdline1/remote_ip
 10.0.0.3

사용자 데이터 추가

180-243

동적 구성을 켜면 각 Netconsole 메시지 끝에 사용자 정의 데이터를 붙일 수 있습니다. 대상의 `enabled` 상태를 바꾸지 않고도 사용자 데이터 항목을 수정할 수 있습니다. `userdata` 아래의 디렉터리 이름이 키이며 최대 53자, `userdata/<key>/value`의 데이터는 최대 200바이트입니다.

예제는 `cmdline0` 아래에 `userdata/foo`와 `userdata/qux`를 만들고 각각 `bar`, `baz`를 씁니다. 이후 `/dev/kmsg`에 메시지를 쓰면 기본 확장 메시지 다음 줄에 `foo=bar`, `qux=baz`가 추가됩니다. 각 키의 `value`를 읽어 실제로 덧붙을 사용자 데이터를 미리 확인할 수 있습니다.

키 디렉터리만 만들고 `value`에 아무것도 쓰지 않은 항목은 전송에서 빠집니다. 항목을 삭제할 때는 해당 키 디렉터리를 `rmdir`로 제거합니다.

configfs의 store 호출은 입력을 줄 단위로 나눕니다. 따라서 `printf "val1\nval2"`처럼 여러 줄을 한 값에 쓰면 store가 두 번 호출되고 마지막 `val2`만 남을 수 있습니다. 혼동을 피하려면 사용자 데이터 값에 줄바꿈을 넣지 않는 것이 좋습니다.

사용자 데이터 구성
userdata/<key>value 파일에 최대 200바이트 기록key=value 생성
확장 콘솔 메시지줄바꿈 구분자로 사용자 데이터 추가원격 수신자

키와 값이 확장 Netconsole 메시지에 합쳐지는 과정입니다.

Append User Data
----------------

Custom user data can be appended to the end of messages with netconsole
dynamic configuration enabled. User data entries can be modified without
changing the "enabled" attribute of a target.

Directories (keys) under `userdata` are limited to 53 character length, and
data in `userdata/<key>/value` are limited to 200 bytes::

 cd /sys/kernel/config/netconsole && mkdir cmdline0
 cd cmdline0
 mkdir userdata/foo
 echo bar > userdata/foo/value
 mkdir userdata/qux
 echo baz > userdata/qux/value

Messages will now include this additional user data::

 echo "This is a message" > /dev/kmsg

Sends::

 12,607,22085407756,-;This is a message
  foo=bar
  qux=baz

Preview the userdata that will be appended with::

 cd /sys/kernel/config/netconsole/cmdline0/userdata
 for f in `ls userdata`; do echo $f=$(cat userdata/$f/value); done

If a `userdata` entry is created but no data is written to the `value` file,
the entry will be omitted from netconsole messages::

 cd /sys/kernel/config/netconsole && mkdir cmdline0
 cd cmdline0
 mkdir userdata/foo
 echo bar > userdata/foo/value
 mkdir userdata/qux

The `qux` key is omitted since it has no value::

 echo "This is a message" > /dev/kmsg
 12,607,22085407756,-;This is a message
  foo=bar

Delete `userdata` entries with `rmdir`::

 rmdir /sys/kernel/config/netconsole/cmdline0/userdata/qux

.. warning::
   When writing strings to user data values, input is broken up per line in
   configfs store calls and this can cause confusing behavior::

     mkdir userdata/testing
     printf "val1\nval2" > userdata/testing/value
     # userdata store value is called twice, first with "val1\n" then "val2"
     # so "val2" is stored, being the last value stored
     cat userdata/testing/value
     val2

   It is recommended to not write user data values with newlines.

작업 이름 자동 추가

244-271

대상의 `userdata` 디렉터리에는 `taskname_enabled` 파일이 있습니다. 여기에 `1`을 쓰면 메시지를 보내는 CPU에서 현재 스케줄된 작업 이름을 커널이 자동으로 채웁니다.

기능을 켠 메시지에는 `taskname=<task name>` 줄이 추가됩니다. 수신자는 메시지가 만들어질 때 어떤 애플리케이션이 실행 중이었는지 확인하여 커널 로그에 문맥을 더하고 메시지를 분류할 수 있습니다. `/dev/kmsg`에 `echo`로 쓴 문서 예제에서는 `taskname=echo`가 나타납니다.

Task name auto population in userdata
-------------------------------------

Inside the netconsole configfs hierarchy, there is a file called
`taskname_enabled` under the `userdata` directory. This file is used to enable
or disable the automatic task name population feature. This feature
automatically populates the current task name that is scheduled in the CPU
sneding the message.

To enable task name auto-population::

  echo 1 > /sys/kernel/config/netconsole/target1/userdata/taskname_enabled

When this option is enabled, the netconsole messages will include an additional
line in the userdata field with the format `taskname=<task name>`. This allows
the receiver of the netconsole messages to easily find which application was
currently scheduled when that message was generated, providing extra context
for kernel messages and helping to categorize them.

Example::

  echo "This is a message" > /dev/kmsg
  12,607,22085407756,-;This is a message
   taskname=echo

In this example, the message was generated while "echo" was the current
scheduled process.

커널 릴리스 자동 추가

272-296

`userdata/release_enabled`는 모든 송신 메시지의 사용자 데이터 사전에 커널 릴리스 버전을 자동으로 추가할지 제어합니다. 해당 파일에 `1`을 쓰면 예제처럼 `release=6.14.0-rc6-01219-g3c027fbd941d` 형식의 줄이 붙습니다.

이 기능이 제공하는 정보는 `release` 접두사 기능과 같습니다. 차이는 릴리스 문자열을 메시지 헤더 앞에 넣는 대신 사용자 데이터 사전에 `release` 키로 추가한다는 점입니다.

Kernel release auto population in userdata
------------------------------------------

Within the netconsole configfs hierarchy, there is a file named `release_enabled`
located in the `userdata` directory. This file controls the kernel release
(version) auto-population feature, which appends the kernel release information
to userdata dictionary in every message sent.

To enable the release auto-population::

  echo 1 > /sys/kernel/config/netconsole/target1/userdata/release_enabled

Example::

  echo "This is a message" > /dev/kmsg
  12,607,22085407756,-;This is a message
   release=6.14.0-rc6-01219-g3c027fbd941d

.. note::

   This feature provides the same data as the "release prepend" feature.
   However, in this case, the release information is appended to the userdata
   dictionary rather than being included in the message header.

CPU 번호 자동 추가

297-339

`userdata/cpu_nr` 파일은 메시지를 보내는 CPU 번호의 자동 추가를 켜거나 끕니다. 이 파일에 `1`을 쓰면 메시지의 사용자 데이터에 `cpu=<cpu_number>` 줄이 추가됩니다. 병렬로 출력되는 로그를 다룰 때 수신자가 CPU별 메시지를 구분하고 역다중화하는 데 유용합니다.

예제에서 메시지는 CPU 42가 보냈으므로 `cpu=42`가 붙습니다. 사용자가 이미 `cpu`라는 사용자 데이터 키를 만들었더라도 커널 항목이 이를 덮어쓰지는 않습니다. 두 키가 모두 보고되며 사용자 정의 `cpu=1` 뒤에 커널이 채운 `cpu=42`가 나타납니다.

자동 시스템 데이터
제어 파일출력 키용도
taskname_enabledtaskname현재 예약된 작업 이름
release_enabledrelease커널 릴리스 버전
cpu_nrcpu송신 CPU 번호
msgid_enabledmsgid대상별 송신 메시지 번호

Netconsole이 사용자 데이터 영역에 자동으로 붙일 수 있는 문맥입니다.

CPU number auto population in userdata
--------------------------------------

Inside the netconsole configfs hierarchy, there is a file called
`cpu_nr` under the `userdata` directory. This file is used to enable or disable
the automatic CPU number population feature. This feature automatically
populates the CPU number that is sending the message.

To enable the CPU number auto-population::

  echo 1 > /sys/kernel/config/netconsole/target1/userdata/cpu_nr

When this option is enabled, the netconsole messages will include an additional
line in the userdata field with the format `cpu=<cpu_number>`. This allows the
receiver of the netconsole messages to easily differentiate and demultiplex
messages originating from different CPUs, which is particularly useful when
dealing with parallel log output.

Example::

  echo "This is a message" > /dev/kmsg
  12,607,22085407756,-;This is a message
   cpu=42

In this example, the message was sent by CPU 42.

.. note::

   If the user has set a conflicting `cpu` key in the userdata dictionary,
   both keys will be reported, with the kernel-populated entry appearing after
   the user one. For example::

     # User-defined CPU entry
     mkdir -p /sys/kernel/config/netconsole/target1/userdata/cpu
     echo "1" > /sys/kernel/config/netconsole/target1/userdata/cpu/value

   Output might look like::

     12,607,22085407756,-;This is a message
      cpu=1
      cpu=42    # kernel-populated value

메시지 ID 자동 추가

340-371

`userdata/msgid_enabled`는 대상에 실제로 전송되는 각 메시지에 숫자 ID를 붙입니다. ID는 대상별 32비트 카운터에서 생성되어 메시지마다 증가합니다. `uint32_t` 최댓값 뒤에는 순환하므로 시간 전체에 걸쳐 전역적으로 유일한 값은 아니지만, 수신 측은 연속 ID의 빈 구간으로 전송 중 유실을 감지할 수 있습니다.

`msgid`와 확장 헤더의 `<sequnum>`은 의미가 다릅니다. `printk` 속도 제한 등의 이유로 어떤 커널 메시지는 Netconsole에 전달되기 전에 사라질 수 있으므로 `<sequnum>`의 공백만으로 네트워크 전송 중 유실을 판단할 수 없습니다. 반면 `msgid`는 Netconsole이 실제 송신한 메시지에만 부여됩니다.

문서 예제는 두 메시지에 `msgid=1`, `msgid=2`가 순서대로 붙는 모습을 보여 줍니다. 따라서 대상별 수집기는 이 번호의 연속성을 검사해야 하며, 카운터 순환도 함께 고려해야 합니다.

Message ID auto population in userdata
--------------------------------------

Within the netconsole configfs hierarchy, there is a file named `msgid_enabled`
located in the `userdata` directory. This file controls the message ID
auto-population feature, which assigns a numeric id to each message sent to a
given target and appends the ID to userdata dictionary in every message sent.

The message ID is generated using a per-target 32 bit counter that is
incremented for every message sent to the target. Note that this counter will
eventually wrap around after reaching uint32_t max value, so the message ID is
not globally unique over time. However, it can still be used by the target to
detect if messages were dropped before reaching the target by identifying gaps
in the sequence of IDs.

It is important to distinguish message IDs from the message <sequnum> field.
Some kernel messages may never reach netconsole (for example, due to printk
rate limiting). Thus, a gap in <sequnum> cannot be solely relied upon to
indicate that a message was dropped during transmission, as it may never have
been sent via netconsole. The message ID, on the other hand, is only assigned
to messages that are actually transmitted via netconsole.

Example::

  echo "This is message #1" > /dev/kmsg
  echo "This is message #2" > /dev/kmsg
  13,434,54928466,-;This is message #1
   msgid=1
  13,435,54934019,-;This is message #2
   msgid=2

확장 콘솔 형식과 조각화

372-406

설정 문자열 앞에 `+`를 붙이거나 configfs의 `extended` 파일을 `1`로 설정하면 확장 콘솔이 켜집니다. 메시지는 `/dev/kmsg`와 같은 `<level>,<sequnum>,<timestamp>,<contflag>;<message text>` 형식의 메타데이터 헤더를 사용합니다.

`r` 릴리스 기능도 켜면 커널 릴리스가 메시지 시작에 추가됩니다. 출력할 수 없는 문자는 `\xff` 표기법으로 이스케이프하고, 선택적 사전 데이터가 있으면 실제 줄바꿈 문자를 구분자로 사용합니다.

메시지가 현재 한도인 1000바이트 안에 들어가지 않으면 Netconsole이 여러 조각으로 나눕니다. 각 조각에는 `ncfrag=<byte-offset>/<total-bytes>` 헤더 필드가 추가됩니다. 예제의 전체 31바이트 메시지는 오프셋 0과 16에서 시작하는 두 조각으로 전송되며 두 조각의 `<sequnum>`과 타임스탬프는 같습니다.

확장 메시지 헤더
필드의미
level커널 로그 수준
sequnum커널 메시지 시퀀스 번호
timestamp메시지 타임스탬프
contflag연속 메시지 상태
message text이스케이프된 메시지 본문
ncfrag조각의 바이트 오프셋 / 전체 바이트 수

확장 콘솔 레코드와 조각 필드를 나눠 보였습니다.

Extended console:
=================

If '+' is prefixed to the configuration line or "extended" config file
is set to 1, extended console support is enabled. An example boot
param follows::

 linux netconsole=+4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc

Log messages are transmitted with extended metadata header in the
following format which is the same as /dev/kmsg::

 <level>,<sequnum>,<timestamp>,<contflag>;<message text>

If 'r' (release) feature is enabled, the kernel release version is
prepended to the start of the message. Example::

 6.4.0,6,444,501151268,-;netconsole: network logging started

Non printable characters in <message text> are escaped using "\xff"
notation. If the message contains optional dictionary, verbatim
newline is used as the delimiter.

If a message doesn't fit in certain number of bytes (currently 1000),
the message is split into multiple fragments by netconsole. These
fragments are transmitted with "ncfrag" header field added::

 ncfrag=<byte-offset>/<total-bytes>

For example, assuming a lot smaller chunk size, a message "the first
chunk, the 2nd chunk." may be split as follows::

 6,416,1758426,-,ncfrag=0/31;the first chunk,
 6,416,1758426,-,ncfrag=16/31; the 2nd chunk.

네트워크 주의 사항과 설계 한계

407-462

대상 MAC의 기본값은 이더넷 브로드캐스트 주소이므로 같은 세그먼트의 다른 시스템에 부하를 줄 수 있습니다. 일부 LAN 스위치는 브로드캐스트를 억제하기도 하므로 가능하면 원격 수신자의 MAC 주소를 설정 문자열에 명시하는 편이 좋습니다.

같은 LAN에 있는 `10.0.0.2`의 MAC은 먼저 `ping`한 뒤 ARP 테이블에서 찾을 수 있습니다. 원격 로그 수신자가 다른 서브넷에 있다면 수신자 자체의 MAC이 아니라 기본 게이트웨이의 MAC을 원격 MAC으로 지정해야 하며, 게이트웨이는 라우팅 테이블에서 확인할 수 있습니다.

Netconsole이 사용하는 인터페이스는 일반 네트워크 트래픽도 계속 처리할 수 있습니다. 커널 메시지가 매우 많으면 다른 트래픽에 약간의 지연을 줄 수 있지만 그 밖의 침해적 영향은 없습니다.

원격 수신자가 일부 메시지만 받는다면 송신자의 `console_loglevel`이 높은 우선순위 메시지만 콘솔로 내보내도록 설정되었을 가능성이 큽니다. 실행 중에는 `dmesg -n 8`, 부팅 때는 `debug` 또는 특정 `loglevel` 커널 옵션으로 모든 필요한 메시지를 콘솔에 보낼 수 있습니다. 자세한 값은 `dmesg(8)`과 `Documentation/admin-guide/kernel-parameters.rst`를 참조합니다.

Netconsole은 심각한 커널 결함도 가능한 즉시 기록하도록 설계되었습니다. IRQ 문맥에서도 동작하고 패킷을 보내는 동안 인터럽트를 활성화하지 않습니다. 이 요구 때문에 구성을 더 자동화하기 어렵고, IP 네트워크·UDP 패킷·이더넷 장치만 지원한다는 근본적인 제한이 남습니다.

운영 시 점검 순서
console_loglevel 확인netconsole 대상 IP·포트 확인원격 UDP 수신기 확인
같은 서브넷: 수신자 MAC다른 서브넷: 게이트웨이 MAC스위치 브로드캐스트 정책 확인

메시지가 도착하지 않을 때 확인할 핵심 경로입니다.

Miscellaneous notes:
====================

.. Warning::

   the default target ethernet setting uses the broadcast
   ethernet address to send packets, which can cause increased load on
   other systems on the same ethernet segment.

.. Tip::

   some LAN switches may be configured to suppress ethernet broadcasts
   so it is advised to explicitly specify the remote agents' MAC addresses
   from the config parameters passed to netconsole.

.. Tip::

   to find out the MAC address of, say, 10.0.0.2, you may try using::

        ping -c 1 10.0.0.2 ; /sbin/arp -n | grep 10.0.0.2

.. Tip::

   in case the remote logging agent is on a separate LAN subnet than
   the sender, it is suggested to try specifying the MAC address of the
   default gateway (you may use /sbin/route -n to find it out) as the
   remote MAC address instead.

.. note::

   the network device (eth1 in the above case) can run any kind
   of other network traffic, netconsole is not intrusive. Netconsole
   might cause slight delays in other traffic if the volume of kernel
   messages is high, but should have no other impact.

.. note::

   if you find that the remote logging agent is not receiving or
   printing all messages from the sender, it is likely that you have set
   the "console_loglevel" parameter (on the sender) to only send high
   priority messages to the console. You can change this at runtime using::

        dmesg -n 8

   or by specifying "debug" on the kernel command line at boot, to send
   all kernel messages to the console. A specific value for this parameter
   can also be set using the "loglevel" kernel boot option. See the
   dmesg(8) man page and Documentation/admin-guide/kernel-parameters.rst
   for details.

Netconsole was designed to be as instantaneous as possible, to
enable the logging of even the most critical kernel bugs. It works
from IRQ contexts as well, and does not enable interrupts while
sending packets. Due to these unique needs, configuration cannot
be more automatic, and some fundamental limitations will remain:
only IP networks, UDP packets and ethernet devices are supported.