brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: journalctl _KERNEL_SUBSYSTEM=usb shows what the kernel said about USB devices

Journalctl
~/tips/tip-journalctl-kernel-subsystem

journalctl -F _KERNEL_SUBSYSTEM

Filter kernel and udev messages to one kind of hardware, like USB or PCI.

Plugging in a flaky USB disk produces a burst of kernel lines between everything else. udev tags many of them with the subsystem they belong to, and you can filter on that tag.

See which subsystems your journal knows about:

journalctl -F _KERNEL_SUBSYSTEM

On a typical machine that lists usb, pci, virtio, platform and a few others. Then match on one:

journalctl -b _KERNEL_SUBSYSTEM=usb

Now you see the connect and disconnect lines, the descriptors the device reported, and errors such as resets, without scrolling past network or service messages. Add -f while you plug the device in and out to watch it happen, which I find the clearest view.

The field sits next to _KERNEL_DEVICE and _UDEV_SYSNAME, which narrow it down to one specific device once you know its name.

Not every kernel message carries these fields. Lines from drivers that just print text, such as many file system errors, have no subsystem attached, so they drop out of this filter. If you expect something and see nothing, fall back to journalctl -k -g usb to search the text of all kernel messages.

Further reading: systemd.journal-fields man page, journalctl man page

More Journalctl tips journalctl -k -g 'killed process' --since "2 days ago" journalctl _PID=1 -b ls -lh /var/log/journal/*/*.journal~ Storage=volatile sudo journalctl --setup-keys All Journalctl tips (81) All topics

Link