Saturday, September 26, 2009

Howto - Create new startup script.

Ok, this is pretty trivial but yet very important.

You're working under run-level 3 and you wish to execute a a super duper startup script - located under:/usr/local/bin/startup.sh, each time system enters run-level 3.
Let's see how it's done:
1.First of all chmod 700 /usr/local/bin/startup.sh (security reasons..).

2.Next, change directory to:
cd /etc/init.d/rc3.d/

3.From here we will create a symbolic link to the real location of the script:
ln -s /usr/local/bin/startup.sh S99startup.sh

The S99 prefix, S=start ,99=startup sequence (last one).
From now every time user enters run-level 3 the startup.sh script will run.

Compiling a Linux Kernel

In this article I will demonstrate how to compile a Linux kernel from source step by step, let's get busy ;)

1.The most recent Linux kernel source can be obtained from:http://www.kernel.org/.

The file comes as a .bz2 compressed file, so after you finish the download extract it with:
tar xvjf linux-2.6.31.1.tar.bz2 -C /usr/src

*important notice:before you begin compiling the kernel make sure your partition has plenty of free space allocated, the procedure may consume couple of gigs, so if you run out of space during the compiling procedure - the procedure will fail ,so if your /usr/src/x will be on your root partition please check it with df -h.

2. Make sure you have most recent gcc & ncurses develpoment tools installed, if you are using Debian based distro:
apt-get gcc install
apt-get install libncurses5-dev


Red Hat/Fedora users:
yum install gcc
yum install ncurses-devel

Suse users:
yast -i gcc
yast -i ncurses-devel

3. Switch to the extracted kernel's directory:

cd /usr/src/linux-2.6.31.1


I suggest running:
make mrproper

This will remove temporary files & leftovers from the source tree.


It's time to configure the features of your kernel, with the following 3 tools you can include/exclude certain modules from you kernel and build it from scratch, the tools are:

* make config -
This is a text-based tool that you step through to configure kernel options one by one. It is no longer recommended because the kernel provies so many options, and the interface involves simply stepping one by one through them tediously. However, make config is a standard tool and is provided with all Linux distributions

* make menuconfig -
The second type of make method is make menuconfig. It gives you a graphical menu-based display without requiring you to use the X Window System. When you use make menuconfig, you are presented with a directory tree menu system. Following each selection, you are presented with the available options. To include an option, use the y key; to exclude it, use the n key; and to include it as a module, use the m key. Letters that are highlighted are considered hotkeys and allow you to quickly maneuver through the menu options. To exit a window, select the Exit option, or press the Esc key twice.

* make xconfig -
The third type of make method is make xconfig. This method is very popular among new Linux users and users who are accustomed to graphical interface tools. The make xconfig tool requires X Window System support. When starting make xconfig, you are presented with a window with buttons for each class of configuration. Pressing a configuration button, you are prompted, in a tree style, the options available. You can then select, deselect, or modularize each option by pressing the corresponding button next to the item. One of the benefits of using this configuration method over the standard make config method is the backward mobility of the configuration. This means that if you change your mind, or make a mistake, you can move back and change the option in make xconfig.
 

When you're done setting the configuration of your brand new kernel the configuration will be stored inside  .config

4. It's time to compile the kernel but before that, we want to remove any irrelevant dependencies:

make clean

Ok, you are ready for the compilation, issue the next command:

make bzImage

This will build the kernel boot image ,it may take pretty long time, so be patient . The bzImage kernel image is not restricted to 520 KB or even 640 KB (unlike zImage). The bzImage is now the preferred boot image.
The resulting kernel image will be under "arch/x86/boot/bzImage"

5.
When the build of the boot image is done run:

make modules


Modules are parts of the kernel that are loaded on the fly, as they are needed. They are stored in individual files (e.g. ext3.o). The more modules you have, the longer this will take to compile, once again be patient.

6.It's time to install the modules:

make modules_install

This will copy all the modules to a new directory, "/lib/modules/a.b.c" where a.b.c is the kernel version.

7. now, you're left with 2 options - you can either run:
make install  (this will automatically copy the new image to /boot partition,create initrd image there and update your boot loader).

or you can set this manually (less recommended, as there is a good chance you will miss something):

*copy your bzImage file to the /boot partition and give it a uniqe name such as:

cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.31.1
cp System.map /boot/System.map-2.6.31.1


*create and initrd image with: mkinitrd -v /boot/initrd-2.6.31.1

*update the boot loader configuration file, a good chance you're using GRUB with your distro as a default boot loader, in that case you will need to edit /boot/grub/menu.lst

and add another instance for the new kernel, this will look something like this:


title Test Kernel (2.6.31.1)
root (hd0,1) kernel /boot/bzImage-2.6.31.1 ro root=LABEL=/
initrd /boot/initrd-2.6.31.1.img


That's it, you're done - now reboot your machine and when the GRUB menu comes up try booting up to the new kernel image.

Monday, September 14, 2009

Howto access contents of Linux ramdisk (initrd)

initrd - is a contraction of "initial ram disk." This initrd image is used by the kernel to load drivers before it starts booting. The purpose of this is to let users build modularized kernels that do not contain support for all 40 different SCSI controllers (for example) and still are able to boot from any SCSI hardware. In this case, the initrd image would contain the needed SCSI drivers and any other drivers needed to get the kernel off the ground.

In order to access it's contents we should follow the following steps:
cp /boot/initrd /tmp/initrd.gz
gzip /tmp/initrd.gz
mount /tmp/initrd /mnt -o loop

Monday, September 7, 2009

Mount ISO Image under Linux

Sometimes for various reasons we wish to mount ISO directly from the OS, in Linux the process is really simple and doesn't require any 3rd party tool like Window's "Daemon Tools" or "Alcohol"...
Lets see how it's done in 4 easy steps:

1)First become root:

#su -

2)Next, create the folder where the ISO will be extracted:
#mkdir /mnt/iso

3)Mount the ISO with:

mount -o loop CentOS-5.5-x86_64-bin-DVD-1of2.iso /mnt/iso/


4)Browse to folder:
#ls -F /mnt/iso

Quick & Easy!
Enjoy ;)