Friday, January 15, 2010

dmesg Command in Linux

This article serves as an introduction , to one of the rarely known UNIX commands to general under-graduate students , the "dmesg" command .

Definition :
dmesg - print or control the kernel ring buffer  .

What do we mean by the term Kernel Ring Buffer ?

In simplest terms it is a log which contains messages from the kernel .

For example we can try a simple command :

[root@localhost]#dmesg | grep Memory 
[    0.000000] Memory: 371348k/393152k available (4565k kernel code, 21120k reserved, 2143k data, 540k init, 0k highmem) 

This command gives certain information about the memory reserved by the kernel at boot time .

Uses of dmesg command:

1) Useful to extract information , about the functioning of various kernel modules basically the device drivers.

Therefore , this message was  logged in by the kernel at the time of file system mounting and can be extracted using the dmesg utility .

Useful Links :
1 ) 
Offers a simple and an effective example .

2) For more advanced usage of dmesg command refer :
 The link mentioned , also provides the answer to the general query of what is a Ring Buffer.

 For those interested to see the file from which we can see the input file to the dmesg command ,
open the file /var/log/dmesg with any standard text editor.

Hope this solves some of your queries.

WAKING UP LINUX : An introduction to the LINUX boot sequence .

The article is intended at understanding one of the basic concepts of LINUX, it's boot sequence .

A very important note is that the boot sequence is system architecture dependent .

To simplify things let us get an overview in terms of a simple diagram :

Reference :

Let us handle the issue in terms of the various stages mentioned in the figure above :

Step1 ) Loading up the BIOS :

This is an OS independent process (Quite inferable) .

1) Even though we hardly deal with switches and cables to boot a system these days , the process is still the same and to make a computer enthusiast's job simple , the boot process is identical on all processor architectures .

2) The BIOS is first program plugged in from a fixed location of the firmware ( the motherboard ) .This fixed location could be a flash memory / the ROM itself.
The BIOS , these days have so many options to allow us to boot into the system . We could set the boot from the DVD/USB and various  other options seen at the system startup .

A sample can be seen as depicted in the figure below :

The BIOS , later boots the stage 1 boot loader whose basic function , is to locate a more advanced boot loader also called as the Stage 2 boot loader .

So let's skip the functions of the 1st stage boot loader and move on to the next one i.e the Stage 2 boot loader .

Step 2) Functions of the Stage 2 boot loader :
As a first step for all who wish to know more about LINUX kernel images visit ,
LINUX Kernel Image , to get  a very brief  and a handy introduction .

The Stage 2 boot loader loads both the LINUX kernel image and the initial file system . At this point , the Stage 2 boot loader verifies the device attached to the system and interfaces them for the OS to get ready to use them.

At this stage , the kernel is decompressed and the root file system is mounted . Along with this the Stage 2 boot loader initialises the basic kernel modules into functioning before it hands control to the Kernel .

Stage 3) The LINUX kernel:

The Linux kernel , initialises the first user process i.e init and then the high-level initialiasation is performed to complete the process of booting .