Difference between revisions of "Netconsole"

From ArchWiki
Jump to: navigation, search
m
(flag for redirect)
 
(17 intermediate revisions by 12 users not shown)
Line 1: Line 1:
 
[[Category:Kernel]]
 
[[Category:Kernel]]
 
[[Category:Networking]]
 
[[Category:Networking]]
 +
[[ja:Netconsole]]
 
[[ru:Netconsole]]
 
[[ru:Netconsole]]
'''netconsole''' is a kernel module that sends all kernel log messages (i.e. [[dmesg]]) over the network to another computer, without involving user space (e.g. syslogd). Name "netconsole" is a misnomer because it's not really a "console", more like a remote logging service.
+
[[zh-CN:Netconsole]]
 +
{{Redirect|Boot debugging|Poor adaptation of [https://www.kernel.org/doc/Documentation/networking/netconsole.txt]}}
 +
'''netconsole''' is a kernel module that sends all kernel log messages (i.e. dmesg) over the network to another computer, without involving user space (e.g. syslogd). Name "netconsole" is a misnomer because it's not really a "console", more like a remote logging service.
  
 
It can be used either built-in or as a module. Built-in ''netconsole'' initializes immediately after NIC cards and will bring up the specified interface as soon as possible. The module is mainly used for capturing kernel panic output from a headless machine, or in other situations where the user space is no more functional.
 
It can be used either built-in or as a module. Built-in ''netconsole'' initializes immediately after NIC cards and will bring up the specified interface as soon as possible. The module is mainly used for capturing kernel panic output from a headless machine, or in other situations where the user space is no more functional.
  
Documentation is available in the Linux kernel tree under '''[http://lxr.linux.no/linux+v2.6.32/Documentation/networking/netconsole.txt Documentation/networking/netconsole.txt]'''
+
Documentation is available in the Linux kernel tree under [https://www.kernel.org/doc/Documentation/networking/netconsole.txt Documentation/networking/netconsole.txt].
  
== Installation ==
+
== Sender configuration ==
  
Install {{pkg|gnu-netcat}} from the [[official repositories]].
+
=== Built-in Configuration ===
  
== Build-in Configuration ==
+
Netconsole can be configured via the {{ic|netconsole}} [[kernel parameter]] in the following format:
  
''Netconsole'' and other modules' [[Kernel parameters]] can be passed from a bootloader to kernel at its startup via kernel command line by modifying the bootloader environment, which is type and version specific. Example for Uboot, where 1st address is Plug Computer ArchLinux device's netconsole Out Port & IP, and 2nd address is your PC's netconsole In Port & IP & adapter MAC:
+
netconsole=[src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr]
  
fw_setenv usb_custom_params 'loglevel=7 netconsole=6666@192.168.1.28/eth0,6666@192.168.1.19/00:13:32:20:r9:a5'
+
where the fields have the following meaning:
  
Logging is done by your ArchLinux set logger like ''syslog-ng'', so available loglevels (output details) are defined in that logger docs, and may differ for each log type. One can also pass ''netconsole'' string parameters at kernel runtime (no config file required), then start two ''netconsole'' instances on the monitoring PC (one to read output, another for input), and restart it on the PC or device you are logging as shown in ''Dynamic Configuration'':
+
* {{ic|src-port}} &mdash; source for UDP packets (defaults to 6665)
 +
* {{ic|src-ip}} &mdash; source IP to use (interface address)
 +
* {{ic|dev}} &mdash; network interface (eth0)
 +
* {{ic|tgt-port}} &mdash; port for logging agent (6666)
 +
* {{ic|tgt-ip}} &mdash; IP address for logging agent
 +
* {{ic|tgt-macaddr}} &mdash; ethernet MAC address for logging agent (broadcast)
  
<pre>
+
For example:
# set log level for kernel messages
+
dmesg -n 8
+
  
netconsole=6666@192.168.1.28/eth0,6666@192.168.1.19/00:13:32:20:r9:a5
+
netconsole=6665@192.168.1.28/eth0,6666@192.168.1.19/00:13:32:20:r9:a5'
  
nc -l -u -p 6666 &
+
{{Note|MAC address is optional, but the slash must stay: {{ic|...,6666@192.168.1.19/}}}}
nc -u 192.168.1.28 6666
+
</pre>
+
One may need to switch off PC and router firewall, and setup proper router port forwarding to monitor and input data in ''Netconsole''.
+
  
== Dynamic configuration ==
+
The logging level can be set with the {{ic|loglevel}} kernel parameter, e.g.:
  
Netconsole can be loaded as one of ''kernel modules'' manually after boot or auto during boot depending on this module config. See [[kernel modules]] for configuring it to load at boot. For loading manually any time after boot:
+
loglevel=7
<pre>
+
 
 +
=== Runtime configuration ===
 +
 
 +
Netconsole can be loaded as ''kernel module'' manually after boot or automatically during boot depending on the module configuration (see [[Kernel modules]] for details).
 +
 
 +
To load the {{ic|netconsole}} module manually any time after boot:
 +
 
 +
{{bc|<nowiki>
 
# set log level for kernel messages
 
# set log level for kernel messages
 
dmesg -n 8
 
dmesg -n 8
Line 50: Line 60:
 
# set destination IP address
 
# set destination IP address
 
echo 192.168.0.17 > remote_ip
 
echo 192.168.0.17 > remote_ip
 +
# set local network device name (find it trough ifconfig, examples: eth0, eno1, wlan0)
 +
echo eno1 > dev_name
 
# find destination MAC address
 
# find destination MAC address
arping `cat remote_ip` -f |grep -o ..:..:..:..:..:.. > remote_mac
+
arping $(cat remote_ip) -f | grep -o ..:..:..:..:..:.. > remote_mac
  
 
echo 1 > enabled
 
echo 1 > enabled
</pre>
+
</nowiki>}}
  
netconsole should now be configured. To verify, run 'dmesg |tail' and you should see "netconsole: network logging started". Check available log levels by running 'dmesg -h'.
+
Netconsole should now be configured. To verify, run {{ic|<nowiki>dmesg | tail</nowiki>}} and you should see "netconsole: network logging started". Check available log levels by running {{ic|dmesg -h}}.
  
== Receiver ==
+
== Receiver configuration ==
<pre>
+
 
nc -u -l 6666
+
{{Expansion}}
</pre>
+
 
 +
Install {{pkg|gnu-netcat}} or {{pkg|socat}} from the [[official repositories]].
 +
 
 +
nc -u -l 6666
 
or
 
or
 +
nc -u -l -p 6666
 +
 +
Logging is done by your Arch Linux set logger like ''syslog-ng'', so available loglevels (output details) are defined in that logger docs, and may differ for each log type. One can also pass ''netconsole'' string parameters at kernel runtime (no config file required), then start two ''netconsole'' instances on the monitoring PC (one to read output, another for input), and restart it on the PC or device you are logging as shown in ''Dynamic Configuration'':
 +
 
<pre>
 
<pre>
nc -u -l -p 6666
+
# set log level for kernel messages
 +
dmesg -n 8
 +
 
 +
netconsole=6666@192.168.1.28/eth0,6666@192.168.1.19/00:13:32:20:r9:a5
 +
 
 +
{{Note| MAC address is optional.}}
 +
 
 +
nc -l -u -p 6666 &
 +
nc -u 192.168.1.28 6666
 +
 
 +
# socat as alternative to nc in one command
 +
socat - udp4-datagram:192.168.1.28:6666,bind=6666
 
</pre>
 
</pre>
  
 +
One may need to switch off PC and router firewall, and setup proper router port forwarding to monitor and input data in ''Netconsole''. A more flexible configuration can be achieved if netconsole is setup on a [http://archlinuxarm.org/forum/viewtopic.php?f=18&t=3355 different subnet] so that if the device is moved to a different network IP's won't clash, however [http://archlinuxarm.org/platforms/armv5/seagate-goflex-home#qt-platform_tabs-ui-tabs3 it may require a more complex setup] on the receiver with aliased ethernet interface.
 +
 +
== Usage ==
  
== Starting at Boot ==
+
{{Style|Moved from [[Boot debugging]]}}
Just add the netconsole to the kernel cmd line.  It takes a string configuration parameter "netconsole" in the following format:
+
  
{{bc|<nowiki>  netconsole=[src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr]
+
[[netconsole]] is a kernel module which sends kernel logs over the network, which is useful for debugging slower computers. The setup process is:
        src-port      source for UDP packets (defaults to 6665)
+
# Set up another computer (running Arch) to accept syslog requests on a remote port using {{ic|syslog.conf}}
        src-ip        source IP to use (interface address)
+
# View the logs using your {{ic|/var/log/everything.log}} file
        dev          network interface (eth0)
+
# On the computer you are debugging, add a kernel paramter like {{ic|1=netconsole=514@10.0.0.2/12:34:56:78:9a:bc}} (along with whatever debugging parameters you want)
        tgt-port     port for logging agent (6666)
+
# Restart the computer and view the logs
        tgt-ip        IP address for logging agent
+
        tgt-macaddr  ethernet MAC address for logging agent (broadcast)</nowiki>}}
+
  
Examples:
+
== See also ==
linux /vmlinuz-linux root=UUID=a322511e-b028-4f11-87b6-e48b5d99bbd8 ro netconsole=514@10.0.0.1/eth1,514@10.0.0.2/12:34:56:78:9a:bc
+
linux /vmlinuz-linux root=/dev/disk/by-label/ROOT ro netconsole=514@10.0.0.2/12:34:56:78:9a:bc
+
  
From: [[Boot_Debugging#Net_Console|Net Console for Boot Debugging]].
+
* [[Boot debugging#netconsole]]

Latest revision as of 20:10, 9 February 2016

Tango-emblem-symbolic-link.pngThis article is being considered for redirection to Boot debugging.Tango-emblem-symbolic-link.png

Notes: Poor adaptation of [1] (Discuss in Talk:Netconsole#)

netconsole is a kernel module that sends all kernel log messages (i.e. dmesg) over the network to another computer, without involving user space (e.g. syslogd). Name "netconsole" is a misnomer because it's not really a "console", more like a remote logging service.

It can be used either built-in or as a module. Built-in netconsole initializes immediately after NIC cards and will bring up the specified interface as soon as possible. The module is mainly used for capturing kernel panic output from a headless machine, or in other situations where the user space is no more functional.

Documentation is available in the Linux kernel tree under Documentation/networking/netconsole.txt.

Sender configuration

Built-in Configuration

Netconsole can be configured via the netconsole kernel parameter in the following format:

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

where the fields have the following meaning:

  • src-port — source for UDP packets (defaults to 6665)
  • src-ip — source IP to use (interface address)
  • dev — network interface (eth0)
  • tgt-port — port for logging agent (6666)
  • tgt-ip — IP address for logging agent
  • tgt-macaddr — ethernet MAC address for logging agent (broadcast)

For example:

netconsole=6665@192.168.1.28/eth0,6666@192.168.1.19/00:13:32:20:r9:a5'
Note: MAC address is optional, but the slash must stay: ...,6666@192.168.1.19/

The logging level can be set with the loglevel kernel parameter, e.g.:

loglevel=7

Runtime configuration

Netconsole can be loaded as kernel module manually after boot or automatically during boot depending on the module configuration (see Kernel modules for details).

To load the netconsole module manually any time after boot:

# set log level for kernel messages
dmesg -n 8

modprobe configfs
modprobe netconsole
mount none -t configfs /sys/kernel/config

# 'netconsole' dir is auto created if the module is loaded 
mkdir /sys/kernel/config/netconsole/target1
cd /sys/kernel/config/netconsole/target1

# set local IP address
echo 192.168.0.111 > local_ip
# set destination IP address
echo 192.168.0.17 > remote_ip
# set local network device name (find it trough ifconfig, examples: eth0, eno1, wlan0)
echo eno1 > dev_name
# find destination MAC address
arping $(cat remote_ip) -f | grep -o ..:..:..:..:..:.. > remote_mac

echo 1 > enabled

Netconsole should now be configured. To verify, run dmesg | tail and you should see "netconsole: network logging started". Check available log levels by running dmesg -h.

Receiver configuration

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:Netconsole#)

Install gnu-netcat or socat from the official repositories.

nc -u -l 6666

or

nc -u -l -p 6666

Logging is done by your Arch Linux set logger like syslog-ng, so available loglevels (output details) are defined in that logger docs, and may differ for each log type. One can also pass netconsole string parameters at kernel runtime (no config file required), then start two netconsole instances on the monitoring PC (one to read output, another for input), and restart it on the PC or device you are logging as shown in Dynamic Configuration:

# set log level for kernel messages
dmesg -n 8

netconsole=6666@192.168.1.28/eth0,6666@192.168.1.19/00:13:32:20:r9:a5

{{Note| MAC address is optional.}}

nc -l -u -p 6666 &
nc -u 192.168.1.28 6666

# socat as alternative to nc in one command
socat - udp4-datagram:192.168.1.28:6666,bind=6666

One may need to switch off PC and router firewall, and setup proper router port forwarding to monitor and input data in Netconsole. A more flexible configuration can be achieved if netconsole is setup on a different subnet so that if the device is moved to a different network IP's won't clash, however it may require a more complex setup on the receiver with aliased ethernet interface.

Usage

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements.Tango-edit-clear.png

Reason: Moved from Boot debugging (Discuss in Talk:Netconsole#)
netconsole is a kernel module which sends kernel logs over the network, which is useful for debugging slower computers. The setup process is:
  1. Set up another computer (running Arch) to accept syslog requests on a remote port using syslog.conf
  2. View the logs using your /var/log/everything.log file
  3. On the computer you are debugging, add a kernel paramter like netconsole=514@10.0.0.2/12:34:56:78:9a:bc (along with whatever debugging parameters you want)
  4. Restart the computer and view the logs

See also