TipsAndTricks/Netconsole

From Yocto Project
Revision as of 12:39, 27 June 2016 by RossBurton (talk | contribs) (Created page with "Using Netconsole If your board doesn't have a traditional serial port it can be difficult to see early boot logs, but if you have ethernet then the netconsole can be used ins...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Using Netconsole

If your board doesn't have a traditional serial port it can be difficult to see early boot logs, but if you have ethernet then the netconsole can be used instead. The netconsole is a virtual serial console which outputs over UDP to a specific IP address.

The prerequisites are that netconsole support is enabled, and your ethernet driver is built in to the kernel and not a module. Luckily, the stock Yocto kernels have netconsole enabled and the atom-pc machine integrates the driver for my hardware.

Then, on the target machine, you pass netconsole=... to the kernel. The kernel documentation explains this quite well:

netconsole=[src-port]@[src-ip]/[],[tgt-port]@/[tgt-macaddr]
where
 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)

The biggest gotcha is that you (obviously) need a source IP address, and netconsole starts before the networking normally comes up. Apart from that you can generally get away with minimal settings:

netconsole=@192.168.1.21/,@192.168.1.17/

Note that apparently some routers may not forward the broadcast packets correctly, so you may need to specify the target MAC address.

On the target machine run something like netcat to capture the packets:

$ netcat -l -u -p 6666 | tee console.log

If you get the options wrong the kernel will tell you why, so if you don’t get any logging iterate a working argument on an image that works, using dmesg to see what the problem is.

Finally instead of typing in this argument every time you boot, you can add it to the boot loader in your local.conf:

APPEND += "netconsole=@192.168.1.21/,@192.168.1.17/"

(APPEND being the name of the variable that is passed to the kernel by the boot loader.)

Note that under systemd when journald starts up it will stop logging to the console, so if you want to get all systemd messages also pass systemd.log_target=kmsg to the kernel.