The Linux kernel logs your system’s essential messages about hardware, driver loads, boot processes, and critical events. To view them, you’ll need two core commands: dmesg for raw boot/logs and journalctl for structured systemd logs. Both are found in every Linux distribution’s core utilities—no extra packages required. This guide shows you exactly how to access, filter, and troubleshoot kernel logs without confusion.
What You'll Need
- The Linux terminal (available by default on all Linux distributions). On desktop systems, open it via the app menu (search for "Terminal"). On servers or cloud instances, the terminal is the primary interface.
- Basic familiarity with Linux command-line commands, but no prior experience is needed.
Step-by-Step
- Open the terminal.
On desktop systems, press
Ctrl+Alt+Tor search for "Terminal." On servers, open it via SSH or from the login screen. - Use
dmesgto view raw kernel boot logs.Run this command to display all messages logged since the last reboot, including hardware detection and driver initialization:
dmesgFor a cleaner output without timestamps, pipe the result to
grepto filter specific keywords:dmesg | grep -i "error\|fail\|ndis|warning"Example: To check if a USB device was detected correctly:
dmesg | grep -i "usb" - Use
journalctlfor detailed systemd logs.Replace
dmesg’s limitations withjournalctl, which captures kernel logs, service events, and more:journalctlFilter by boot context (e.g., last reboot):
journalctl -bSearch for kernel messages specifically:
journalctl -kTo see logs from a specific unit (e.g., a service like
sshd):journalctl -u sshd - Navigate log levels for precision.
Use
journalctlwith log levels to focus on critical issues:journalctl -p err(errors only)journalctl -p info(informational)journalctl -p warning(warnings)To follow logs in real-time (like a live tail):
journalctl -fNote:
dmesgdoes not support log levels—it shows all messages. - Save logs to a file for later reference.
Dump kernel logs to a file for debugging:
dmesg > kernel_logs.txtOr capture journalctl logs with:
journalctl -k > kernel_logs_journal.txtThis is useful for sharing with support teams or revisiting later.
Common Mistakes
- Assuming
dmesgshows all system activity.dmesgonly captures kernel and driver messages—it does not include logs from services likenginxorsystemd. Usejournalctlfor those. - Ignoring timestamps.
Logs from
dmesgshow timestamps by default, whilejournalctldefaults to logs from the last boot. Use-bto see real-time logs or-pto filter with timestamps. - Running
journalctlwithout-kfor kernel logs.By default,
journalctlshows systemd logs, not kernel messages. Append-kto restrict output to kernel logs.
Tips
- Use
grepfor quick searches.Instead of reading entire log files, filter for specific words or patterns (e.g.,
grep -i "driver"for driver-related errors). - Check hardware-related errors first.
Common kernel log issues include:
- USB device failures (
dmesg | grep -i "usb") - Network interface errors (
dmesg | grep -i "eth") - Disk I/O issues (
dmesg | grep -i "sda")
- USB device failures (
- Enable verbose kernel logging (advanced).
To increase kernel log verbosity (useful for debugging), modify the kernel command line by editing the bootloader config:
- On Grub (most Debian/Ubuntu systems): Edit
/etc/default/grub, addloglevel=3orconsole=ttyS0, then runsudo update-grub. - On systemd-boot: Edit the boot entry in
/boot/loader/entries/and appendloglevel=3.
Reboot after changes to see more detailed logs.
- On Grub (most Debian/Ubuntu systems): Edit
Troubleshooting
- Logs appear empty.
If no output appears:
- Check if the system was rebooted recently (
journalctl -b) - Verify that
journalctlis installed (which journalctl) - Try the older
cat /proc/kmsg(requires root) orcat /var/log/kern.log(some systems use this file instead).
- Check if the system was rebooted recently (
- Filtering doesn’t work.
If
grepor-pflags fail:- Ensure the command is run in the terminal (not a browser).
- Use quotes around complex patterns if spaces are involved (e.g.,
grep -i "driver error").
- Logs contain only "No such file or directory." errors.
This often means:
- Your system uses
systemdand lacksjournalctlpermissions. Run:sudo journalctlto access restricted logs. - The logs are being cleared by a script. Check for files like
/etc/systemd/system/logrotate.conf.
- Your system uses
Frequently Asked Questions
How do I check if my system’s hardware is detected correctly?
Run dmesg | grep -i "usb\|eth\|sda\|video" to scan for hardware-related errors. For network interfaces, try ip a alongside the logs.
Can I view kernel logs from a previous boot?
Use journalctl -b to see logs from the last boot. For older entries, check journalctl --since "2023-01-01" or examine /var/log/journal/ (requires root access).
Why don’t my logs show any errors?
Kernel messages are often filtered by default. Try:
journalctl -kfor kernel logs.dmesgfor raw boot messages.- A verbose boot (see the "Tips" section).
How can I export kernel logs to a file for debugging with a support team?
Save logs with:
dmesg > dmesg_backup.txt
journalctl -k > journal_backup.txt
sudo journalctl --since "1 hour ago" > recent_logs.txt
Is there a way to filter dmesg for only hardware errors?
Yes, use:
dmesg | grep -Ei "(hardware|device|failed|error|warn)"
dmesg | grep -Ei "(usb|eth|sda|gpu)"
What if journalctl shows logs from services instead of the kernel?
Append -k to restrict output to kernel logs:
journalctl -k
If that still doesn’t work, check if the logs are stored elsewhere (e.g., /var/log/kern.log).