The Linux kernel is a complex piece of engineering. From boot-up to runlevel 5 multi-user mode, the Linux kernel initializes and manages a PC’s resources including the processor, the memory, the networking, the video output, and the local storage. As the kernel works with all these different subsystems and resources, it logs various high-level messages to let system admins know what it is doing. These messages can be viewed using the “
dmesg” command. The problem is that the output from the kernel can seem complex and unintelligible to the untrained eye. However, with a little help understanding the basics, the “
dmesg” command can become a very powerful tool in a system admin’s tool-set.
The quickest way to learn about kernel messages is to examine the first few lines from the boot process. To view the first page of output, use the following command:
dmesg | less
The first three lines are likely about the initialization of the “Control Groups” for the processor. These aren’t that interesting unless you are a kernel hacker. However, the next line is very important. It will tell you what version of the Linux kernel you are running.
The output on my test machine reads:
Linux version 3.13.0-24-generic (buildd@roseapple) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #46-Ubuntu SMP Thu Apr 10 19:08:14 UTC 2014 (Ubuntu 3.13.0-24.46-generic 3.13.9)
What this tells me is that my test machine is running Linux kernel 3.13 which was compiled by Ubuntu on April 10 2014.
The next 80 to 100 lines are all low level details about the BIOS, the CPU and the memory. The next important line is the summary of the system memory. It always starts with “Memory:”. On my test machine, the output is:
Memory: 1525720K/1572408K available (6507K kernel code, 641K rwdata, 2752K rodata, 872K init, 924K bss, 46688K reserved, 659400K highmem)
The number after the slash is the total amount of system memory accessible to the Linux kernel, in this case 1.5GB. At this point, Linux has almost finished looking at the processor and memory, and it will soon turn its attention to the rest of the machine including the video, the USB ports, the hard disks and so on.
The kernel output is also a great way to discover how Linux is interacting with the hardware in your PC. For example, to discover which hard disks the kernel recognizes, you can search through the messages for the keyword “sda”. To do this, use “
grep” like this:
dmesg | grep sda
“sda” is the name given to the first SATA hard disk, “sdb” is the second SATA hard disk and so on. If you don’t find your disks under “sda”, “sdb” etc., try “hda”, “hdb” and so on.
To get information on the network card, search for “eth0”, for example:
dmesg | grep eth0
On my test machine, one of the lines of “eth0” related output shows:
e1000 0000:00:03.0 eth0: Intel(R) PRO/1000 Network Connection
This tells me that my Ethernet card is an Intel PRO/1000 (known as an e1000).
If you insert a USB flash drive and you want to check if it has been recognized by the kernel and what device name it has been assigned to, you can see the last few kernel messages using
dmesg | tail -20
tail to show the last 20 lines of output from dmesg. The example output shows that a flash drive make by ADATA was inserted into the USB port, it has a capacity of 8GB and that it has been assigned the device name of
dmesg can be a very useful tool for system admins. Give it a try and see what you can learn about your system. If you have any questions, please ask them in the comments section, and we will see if we can help.
Our latest tutorials delivered straight to your inbox