요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. 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.
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> -
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
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.
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.
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 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
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
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.
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.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
소개와 초기화 시점
1-33Netconsole은 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`를 붙이지 않아야 하므로 문서에 제시된 두 형식을 확인해야 합니다.
설정 문자열의 선택 표지와 주소 필드를 구조화했습니다.
송신 커널에서 원격 수집기까지의 기본 데이터 경로입니다.
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`임을 확인합니다.
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`만 남을 수 있습니다. 혼동을 피하려면 사용자 데이터 값에 줄바꿈을 넣지 않는 것이 좋습니다.
키와 값이 확장 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`가 나타납니다.
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>`과 타임스탬프는 같습니다.
확장 콘솔 레코드와 조각 필드를 나눠 보였습니다.
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 패킷·이더넷 장치만 지원한다는 근본적인 제한이 남습니다.
메시지가 도착하지 않을 때 확인할 핵심 경로입니다.
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.
요약·해설
netconsole.rst:1-462Netconsole은 디스크 로그나 직렬 콘솔을 사용할 수 없는 장애 상황을 위해 커널 로그를 UDP로 전송합니다. 정적 부팅 인자와 configfs 동적 대상, 확장 `/dev/kmsg` 형식, 사용자·시스템 메타데이터 및 조각화를 함께 지원합니다.
문서의 주요 설정 영역을 한눈에 정리했습니다.