netconsole.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ==========
  3. Netconsole
  4. ==========
  5. started by Ingo Molnar <mingo@redhat.com>, 2001.09.17
  6. 2.6 port and netpoll api by Matt Mackall <mpm@selenic.com>, Sep 9 2003
  7. IPv6 support by Cong Wang <xiyou.wangcong@gmail.com>, Jan 1 2013
  8. Extended console support by Tejun Heo <tj@kernel.org>, May 1 2015
  9. Release prepend support by Breno Leitao <leitao@debian.org>, Jul 7 2023
  10. Userdata append support by Matthew Wood <thepacketgeek@gmail.com>, Jan 22 2024
  11. Please send bug reports to Matt Mackall <mpm@selenic.com>
  12. Satyam Sharma <satyam.sharma@gmail.com>, and Cong Wang <xiyou.wangcong@gmail.com>
  13. Introduction:
  14. =============
  15. This module logs kernel printk messages over UDP allowing debugging of
  16. problem where disk logging fails and serial consoles are impractical.
  17. It can be used either built-in or as a module. As a built-in,
  18. netconsole initializes immediately after NIC cards and will bring up
  19. the specified interface as soon as possible. While this doesn't allow
  20. capture of early kernel panics, it does capture most of the boot
  21. process.
  22. Sender and receiver configuration:
  23. ==================================
  24. It takes a string configuration parameter "netconsole" in the
  25. following format::
  26. netconsole=[+][r][src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr]
  27. where
  28. + if present, enable extended console support
  29. r if present, prepend kernel version (release) to the message
  30. src-port source for UDP packets (defaults to 6665)
  31. src-ip source IP to use (interface address)
  32. dev network interface (eth0)
  33. tgt-port port for logging agent (6666)
  34. tgt-ip IP address for logging agent
  35. tgt-macaddr ethernet MAC address for logging agent (broadcast)
  36. Examples::
  37. linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc
  38. or::
  39. insmod netconsole netconsole=@/,@10.0.0.2/
  40. or using IPv6::
  41. insmod netconsole netconsole=@/,@fd00:1:2:3::1/
  42. It also supports logging to multiple remote agents by specifying
  43. parameters for the multiple agents separated by semicolons and the
  44. complete string enclosed in "quotes", thusly::
  45. modprobe netconsole netconsole="@/,@10.0.0.2/;@/eth1,6892@10.0.0.3/"
  46. Built-in netconsole starts immediately after the TCP stack is
  47. initialized and attempts to bring up the supplied dev at the supplied
  48. address.
  49. The remote host has several options to receive the kernel messages,
  50. for example:
  51. 1) syslogd
  52. 2) netcat
  53. On distributions using a BSD-based netcat version (e.g. Fedora,
  54. openSUSE and Ubuntu) the listening port must be specified without
  55. the -p switch::
  56. nc -u -l -p <port>' / 'nc -u -l <port>
  57. or::
  58. netcat -u -l -p <port>' / 'netcat -u -l <port>
  59. 3) socat
  60. ::
  61. socat udp-recv:<port> -
  62. Dynamic reconfiguration:
  63. ========================
  64. Dynamic reconfigurability is a useful addition to netconsole that enables
  65. remote logging targets to be dynamically added, removed, or have their
  66. parameters reconfigured at runtime from a configfs-based userspace interface.
  67. To include this feature, select CONFIG_NETCONSOLE_DYNAMIC when building the
  68. netconsole module (or kernel, if netconsole is built-in).
  69. Some examples follow (where configfs is mounted at the /sys/kernel/config
  70. mountpoint).
  71. To add a remote logging target (target names can be arbitrary)::
  72. cd /sys/kernel/config/netconsole/
  73. mkdir target1
  74. Note that newly created targets have default parameter values (as mentioned
  75. above) and are disabled by default -- they must first be enabled by writing
  76. "1" to the "enabled" attribute (usually after setting parameters accordingly)
  77. as described below.
  78. To remove a target::
  79. rmdir /sys/kernel/config/netconsole/othertarget/
  80. The interface exposes these parameters of a netconsole target to userspace:
  81. ============== ================================= ============
  82. enabled Is this target currently enabled? (read-write)
  83. extended Extended mode enabled (read-write)
  84. release Prepend kernel release to message (read-write)
  85. dev_name Local network interface name (read-write)
  86. local_port Source UDP port to use (read-write)
  87. remote_port Remote agent's UDP port (read-write)
  88. local_ip Source IP address to use (read-write)
  89. remote_ip Remote agent's IP address (read-write)
  90. local_mac Local interface's MAC address (read-only)
  91. remote_mac Remote agent's MAC address (read-write)
  92. ============== ================================= ============
  93. The "enabled" attribute is also used to control whether the parameters of
  94. a target can be updated or not -- you can modify the parameters of only
  95. disabled targets (i.e. if "enabled" is 0).
  96. To update a target's parameters::
  97. cat enabled # check if enabled is 1
  98. echo 0 > enabled # disable the target (if required)
  99. echo eth2 > dev_name # set local interface
  100. echo 10.0.0.4 > remote_ip # update some parameter
  101. echo cb:a9:87:65:43:21 > remote_mac # update more parameters
  102. echo 1 > enabled # enable target again
  103. You can also update the local interface dynamically. This is especially
  104. useful if you want to use interfaces that have newly come up (and may not
  105. have existed when netconsole was loaded / initialized).
  106. Netconsole targets defined at boot time (or module load time) with the
  107. `netconsole=` param are assigned the name `cmdline<index>`. For example, the
  108. first target in the parameter is named `cmdline0`. You can control and modify
  109. these targets by creating configfs directories with the matching name.
  110. Let's suppose you have two netconsole targets defined at boot time::
  111. 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
  112. You can modify these targets in runtime by creating the following targets::
  113. mkdir cmdline0
  114. cat cmdline0/remote_ip
  115. 10.0.0.2
  116. mkdir cmdline1
  117. cat cmdline1/remote_ip
  118. 10.0.0.3
  119. Append User Data
  120. ----------------
  121. Custom user data can be appended to the end of messages with netconsole
  122. dynamic configuration enabled. User data entries can be modified without
  123. changing the "enabled" attribute of a target.
  124. Directories (keys) under `userdata` are limited to 53 character length, and
  125. data in `userdata/<key>/value` are limited to 200 bytes::
  126. cd /sys/kernel/config/netconsole && mkdir cmdline0
  127. cd cmdline0
  128. mkdir userdata/foo
  129. echo bar > userdata/foo/value
  130. mkdir userdata/qux
  131. echo baz > userdata/qux/value
  132. Messages will now include this additional user data::
  133. echo "This is a message" > /dev/kmsg
  134. Sends::
  135. 12,607,22085407756,-;This is a message
  136. foo=bar
  137. qux=baz
  138. Preview the userdata that will be appended with::
  139. cd /sys/kernel/config/netconsole/cmdline0/userdata
  140. for f in `ls userdata`; do echo $f=$(cat userdata/$f/value); done
  141. If a `userdata` entry is created but no data is written to the `value` file,
  142. the entry will be omitted from netconsole messages::
  143. cd /sys/kernel/config/netconsole && mkdir cmdline0
  144. cd cmdline0
  145. mkdir userdata/foo
  146. echo bar > userdata/foo/value
  147. mkdir userdata/qux
  148. The `qux` key is omitted since it has no value::
  149. echo "This is a message" > /dev/kmsg
  150. 12,607,22085407756,-;This is a message
  151. foo=bar
  152. Delete `userdata` entries with `rmdir`::
  153. rmdir /sys/kernel/config/netconsole/cmdline0/userdata/qux
  154. .. warning::
  155. When writing strings to user data values, input is broken up per line in
  156. configfs store calls and this can cause confusing behavior::
  157. mkdir userdata/testing
  158. printf "val1\nval2" > userdata/testing/value
  159. # userdata store value is called twice, first with "val1\n" then "val2"
  160. # so "val2" is stored, being the last value stored
  161. cat userdata/testing/value
  162. val2
  163. It is recommended to not write user data values with newlines.
  164. Extended console:
  165. =================
  166. If '+' is prefixed to the configuration line or "extended" config file
  167. is set to 1, extended console support is enabled. An example boot
  168. param follows::
  169. linux netconsole=+4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc
  170. Log messages are transmitted with extended metadata header in the
  171. following format which is the same as /dev/kmsg::
  172. <level>,<sequnum>,<timestamp>,<contflag>;<message text>
  173. If 'r' (release) feature is enabled, the kernel release version is
  174. prepended to the start of the message. Example::
  175. 6.4.0,6,444,501151268,-;netconsole: network logging started
  176. Non printable characters in <message text> are escaped using "\xff"
  177. notation. If the message contains optional dictionary, verbatim
  178. newline is used as the delimiter.
  179. If a message doesn't fit in certain number of bytes (currently 1000),
  180. the message is split into multiple fragments by netconsole. These
  181. fragments are transmitted with "ncfrag" header field added::
  182. ncfrag=<byte-offset>/<total-bytes>
  183. For example, assuming a lot smaller chunk size, a message "the first
  184. chunk, the 2nd chunk." may be split as follows::
  185. 6,416,1758426,-,ncfrag=0/31;the first chunk,
  186. 6,416,1758426,-,ncfrag=16/31; the 2nd chunk.
  187. Miscellaneous notes:
  188. ====================
  189. .. Warning::
  190. the default target ethernet setting uses the broadcast
  191. ethernet address to send packets, which can cause increased load on
  192. other systems on the same ethernet segment.
  193. .. Tip::
  194. some LAN switches may be configured to suppress ethernet broadcasts
  195. so it is advised to explicitly specify the remote agents' MAC addresses
  196. from the config parameters passed to netconsole.
  197. .. Tip::
  198. to find out the MAC address of, say, 10.0.0.2, you may try using::
  199. ping -c 1 10.0.0.2 ; /sbin/arp -n | grep 10.0.0.2
  200. .. Tip::
  201. in case the remote logging agent is on a separate LAN subnet than
  202. the sender, it is suggested to try specifying the MAC address of the
  203. default gateway (you may use /sbin/route -n to find it out) as the
  204. remote MAC address instead.
  205. .. note::
  206. the network device (eth1 in the above case) can run any kind
  207. of other network traffic, netconsole is not intrusive. Netconsole
  208. might cause slight delays in other traffic if the volume of kernel
  209. messages is high, but should have no other impact.
  210. .. note::
  211. if you find that the remote logging agent is not receiving or
  212. printing all messages from the sender, it is likely that you have set
  213. the "console_loglevel" parameter (on the sender) to only send high
  214. priority messages to the console. You can change this at runtime using::
  215. dmesg -n 8
  216. or by specifying "debug" on the kernel command line at boot, to send
  217. all kernel messages to the console. A specific value for this parameter
  218. can also be set using the "loglevel" kernel boot option. See the
  219. dmesg(8) man page and Documentation/admin-guide/kernel-parameters.rst
  220. for details.
  221. Netconsole was designed to be as instantaneous as possible, to
  222. enable the logging of even the most critical kernel bugs. It works
  223. from IRQ contexts as well, and does not enable interrupts while
  224. sending packets. Due to these unique needs, configuration cannot
  225. be more automatic, and some fundamental limitations will remain:
  226. only IP networks, UDP packets and ethernet devices are supported.