Date: December 1, 2024

Reading kernel logs

If you're a computer science graduate and have taken an operating systems course,
you must have come across the Linux printk function. This function prints
messages to the kernel log, which is stored in the /var/log/dmesg file.
The log files gets reset on every boot.

The lost logs are retained in the /var/log/kern.log files. These may be
either text or compressed zip files. These logs are compressed on regular basis.
Not sure whether this is implemented in the kernel or by the distribution maintainers.

$  ls -l kern.log.1 kern.log.2 kern.log.3 kern.log.4
 -rw-r----- 1 tanmay tanmay 4216479 Dec  1 18:22 kern.log.1
 -rw-rw-r-- 1 tanmay tanmay 1556710 Nov  5 13:03 kern.log.2
 -rw-rw-r-- 1 tanmay tanmay  735540 Oct 27 00:00 kern.log.3
 -rw-rw-r-- 1 tanmay tanmay 2018545 Oct 23 00:00 kern.log.4


Anyway, I find these kernel logs really useful. Not only for identifying
errors or crashes in programs (if they are logged by the program), but also for
learning about the boot process and hardware in general.

Example kernel log:


$ sudo dmesg
[    0.000000] Linux version 6.8.0-49-generic (buildd@lcy02-amd64-028) (x86_64-linux-gnu-gcc-13 (Ubuntu 13.2.0-23ubuntu4) 13.2.0, GNU ld (GNU Binutils for Ubuntu) 2.42) #49-Ubuntu SMP PREEMPT_DYNAMIC Mon Nov  4 02:06:24 UTC 2024 (Ubuntu 6.8.0-49.49-generic 6.8.12)
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-6.8.0-49-generic root=UUID=5d48572f-77cd-465e-bd22-ae115a2b3962 ro quiet splash vt.handoff=7
...
[    0.018975] No NUMA configuration found
[    0.018977] Faking a node at [mem 0x0000000000000000-0x000000026effffff]
[    0.018998] NODE_DATA(0) allocated [mem 0x26efd3000-0x26effdfff]
[    0.019297] Zone ranges:
[    0.019299]   DMA      [mem 0x0000000000001000-0x0000000000ffffff]
[    0.019304]   DMA32    [mem 0x0000000001000000-0x00000000ffffffff]
[    0.019308]   Normal   [mem 0x0000000100000000-0x000000026effffff]
[    0.019312]   Device   empty
[    0.019314] Movable zone start for each node
[    0.019319] Early memory node ranges
[    0.019320]   node   0: [mem 0x0000000000001000-0x0000000000057fff]
[    0.019324]   node   0: [mem 0x0000000000059000-0x000000000009dfff]
[    0.019326]   node   0: [mem 0x0000000000100000-0x0000000073554fff]
[    0.019329]   node   0: [mem 0x0000000073557000-0x0000000075387fff]
[    0.019331]   node   0: [mem 0x0000000075c88000-0x000000008be9dfff]
[    0.019334]   node   0: [mem 0x000000008cffe000-0x000000008cffefff]
[    0.019336]   node   0: [mem 0x0000000100000000-0x000000026effffff]
[    0.019340] Initmem setup node 0 [mem 0x0000000000001000-0x000000026effffff]
[    0.019356] On node 0, zone DMA: 1 pages in unavailable ranges
[    0.019360] On node 0, zone DMA: 1 pages in unavailable ranges
[    0.019395] On node 0, zone DMA: 98 pages in unavailable ranges
[    0.023586] On node 0, zone DMA32: 2 pages in unavailable ranges
[    0.024414] On node 0, zone DMA32: 2304 pages in unavailable ranges
[    0.024513] On node 0, zone DMA32: 4448 pages in unavailable ranges
[    0.038073] On node 0, zone Normal: 12289 pages in unavailable ranges
[    0.038148] On node 0, zone Normal: 4096 pages in unavailable ranges
...


I've shown a small part of kernel log here.
Reading the kernel log introduced me to NUMA, how the kernel fakes a numa node for a single
processor. There's also other information like features supported by the CPU or the hardwares.
The logs here are root nodes of information, you'll need to traverse the whole tree
by yourself to understand stuff.

So, if you're lookin to get into operating systems or the Linux kernel,
reading kernel log can be really helpful.