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

  1. Open the terminal.

    On desktop systems, press Ctrl+Alt+T or search for "Terminal." On servers, open it via SSH or from the login screen.

  2. Use dmesg to view raw kernel boot logs.

    Run this command to display all messages logged since the last reboot, including hardware detection and driver initialization: dmesg

    For a cleaner output without timestamps, pipe the result to grep to filter specific keywords: dmesg | grep -i "error\|fail\|ndis|warning"

    Example: To check if a USB device was detected correctly: dmesg | grep -i "usb"

  3. Use journalctl for detailed systemd logs.

    Replace dmesg’s limitations with journalctl, which captures kernel logs, service events, and more: journalctl

    Filter by boot context (e.g., last reboot): journalctl -b

    Search for kernel messages specifically: journalctl -k

    To see logs from a specific unit (e.g., a service like sshd): journalctl -u sshd

  4. Navigate log levels for precision.

    Use journalctl with 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 -f

    Note: dmesg does not support log levels—it shows all messages.

  5. Save logs to a file for later reference.

    Dump kernel logs to a file for debugging: dmesg > kernel_logs.txt

    Or capture journalctl logs with: journalctl -k > kernel_logs_journal.txt

    This is useful for sharing with support teams or revisiting later.

Common Mistakes

  • Assuming dmesg shows all system activity.

    dmesg only captures kernel and driver messages—it does not include logs from services like nginx or systemd. Use journalctl for those.

  • Ignoring timestamps.

    Logs from dmesg show timestamps by default, while journalctl defaults to logs from the last boot. Use -b to see real-time logs or -p to filter with timestamps.

  • Running journalctl without -k for kernel logs.

    By default, journalctl shows systemd logs, not kernel messages. Append -k to restrict output to kernel logs.

Tips

  • Use grep for 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")

  • Enable verbose kernel logging (advanced).

    To increase kernel log verbosity (useful for debugging), modify the kernel command line by editing the bootloader config:

    1. On Grub (most Debian/Ubuntu systems): Edit /etc/default/grub, add loglevel=3 or console=ttyS0, then run sudo update-grub.
    2. On systemd-boot: Edit the boot entry in /boot/loader/entries/ and append loglevel=3.

    Reboot after changes to see more detailed logs.

Troubleshooting

  1. Logs appear empty.

    If no output appears:

    • Check if the system was rebooted recently (journalctl -b)
    • Verify that journalctl is installed (which journalctl)
    • Try the older cat /proc/kmsg (requires root) or cat /var/log/kern.log (some systems use this file instead).
  2. Filtering doesn’t work.

    If grep or -p flags 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").
  3. Logs contain only "No such file or directory." errors.

    This often means:

    • Your system uses systemd and lacks journalctl permissions. Run: sudo journalctl to access restricted logs.
    • The logs are being cleared by a script. Check for files like /etc/systemd/system/logrotate.conf.

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:

  1. journalctl -k for kernel logs.
  2. dmesg for raw boot messages.
  3. 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).