Friday 12 August 2011

How to Compile Linux Kernel and Installing a different Kernel in your System


Compiling the Linux Kernel is very easy , it needs to understand few things and some couple of commands.

# :-   super user(root)
$  :-  Normal User
Steps are as follows :

Step 1:
download the linux kernel code from the site(i will suggest www.kernel.org).
File name would be linux-x.y.z.tar.bz2, where x.y.z is actual version number.
For example file inux-2.6.25.tar.bz2 represents 2.6.25 kernel version.

Step 2:
Extract the tar file and put it inside /usr/src
$cp linux-x.y.x.tar.bz  /usr/src
$cd /usr/src
$tar -xjvf  linux-x.y.z
$cd linux-x.y.z

Step 3:
Configure the kernel according to your needs:
$make menuconfig

Step 4:
run the command
$make dep

Step 5:
$make
it will compile the kernel.

$make modules
it will compile the kernel modules

Now install the kernel modules
#make modules_install

Step 6:
Now we will install the kernel by using

#make install

It will install three files into /boot directory as well as modification to your kernel grub configuration file:

System.map-2.6.25
config-2.6.25
vmlinuz-2.6.25

Step 7:

Now we will create initrd image.
#mkinitramfs -o initrd.img-2.6.38.3 2.6.38.3

2.6.38.3 is kernel version

Step 8:
run the following command to update the grub.cfg file.
# update-grub


Step 9:
#reboot
Now reboot your system into your new kernel.

Wednesday 10 August 2011

PKG - CONFIG setting and Difference between /bin vs /sbin vs /usr/bin vs /usr/sbin

suppose you have installed some package for an example Glib-2.0  in some directory.
Now you want to use this package in your application.
So to include with PKG_CONFIG_PATH:

$ PKG_CONFIG_PATH=c:/glib-dev /  /lib/pkgconfig/  ;
$ export PKG_CONFIG_PATH

Now we can use Glib-2.0 with pkg-config during compiling our application or program.

$gcc  -o test *.c  `pkg-config --cflags --libs glib-2.0`



Difference between /bin vs /sbin vs /usr/bin vs /usr/sbin

/bin This directory contains executable programs which are needed in
single user mode and to bring the system up or repair it.

/sbin Like /bin, this directory holds commands needed to boot the sys-
tem, but which are usually not executed by normal users.

/usr/bin
This is the primary directory for executable programs. Most
programs executed by normal users which are not needed for boot-
ing or for repairing the system and which are not installed
locally should be placed in this directory.

/usr/sbin
This directory contains program binaries for system administra-
tion which are not essential for the boot process, for mounting
/usr, or for system repair.

Linux symbolic (soft) and hard links

Inodes are associated with precisely one directory entry at a time. However, with hard links it is possible to associate multiple directory entries with a single inode. To create a hard link use ln command as follows:
# ln /root/file1 /root/file2
# ls -l

Above commands create a link to file1.
Symbolic links refer to:
A symbolic path indicating the abstract location of another file.
Hard links refer to:
The specific location of physical data.

Hard link vs. Soft link in Linux or UNIX

  • Hard links cannot links directories
  • Cannot cross file system boundaries
Soft or symbolic links are just like hard links. It allows to associate multiple filenames with a single file. However, symbolic links allows:
  • To create links between directories
  • Can cross file system boundaries
These links behave differently when the source of the link is moved or removed.
  • Symbolic links are not updated.
  • Hard links always refer to the source, even if moved or removed.

How do I create symbolic link?

You can create symbolic link with ln command:
$ln -s /path/to/file1.txt  /path/to/file2.txt
$ls -ali
Above command will create a symbolic link to file1.txt.

Task: Symbolic link creation and deletion

Let us create a directory called foo, enter:
$mkdir foo
$cd foo
Copy /etc/resolv.conf file, enter:
$cp /etc/resolv.conf   .
View inode number, enter:
$ls -aliSample output:
total 152
1048600 drwxr-xr-x   2 ram ram   4096 2011-07-20 10:19 .
1015809 drwxrwxrwt 220 root  root  143360 2011-07-20 10:19 ..
1048601 -rwxr-xr-x   1 ram ram    259 2011-07-20 10:19 resolv.conf
Now create soft link to resolv.conf, enter:
$ln -s resolv.conf   alink.conf

Sample output:
total 152
1048600 drwxr-xr-x   2 ram ram   4096 2011-07-20 10:24 .
1015809 drwxrwxrwt 220 root  root  143360 2011-07-20 10:19 ..
1048602 lrwxrwxrwx   1 ram ram     11 2011-07-20 10:24 alink.conf -> resolv.conf
1048601 -rwxr-xr-x   1 ram ram    259 2011-07-20 10:19 resolv.conf
The reference count of the directory has not changed (total 152). Our symbolic (soft) link is stored in a different inode than the text file (1048602). The information stored in resolv.conf is accessible through the alink.conf file. If we delete the text file resolv.conf, alink.conf becomes a broken link and our data is lost:
$rm resolv.conf
$ls -ali
If alink.conf was a hard link, our data would still be accessible through alink.conf. Also, if you delete the soft link itself, the data would still be there.