Tag: fedora

How to create or build RPM Package

How to create or build RPM Package

Introduction –

* “rpmbuild” tool is used to build both…

1) Binary Package ~ used to install the software and supporting scripts. It contains the files that comprise the application, along with any additional information needed to install and erase it.
2) Source Package ~ contains the original compressed tar file of source code, patches and Specification File.

* What is RPM & RPM package Manager?

The RPM Package Manager (RPM) is a powerful command line package management system capable of installing, uninstalling, verifying, querying, and updating software packages.

RPM package consists of an archive of files and meta-data used to install and erase the archive files. The meta-data includes helper scripts, file attributes, and descriptive information about the package.

* To build RPM package you need to specify three things ~

1) Source of application – In any case, you should not modify the sources used in the package building process.

2) Patches – RPM gives you the ability to automatically apply patches to them. The patch addresses an issue specific to the target system. This could include changing makefiles to install the application into the appropriate directories, or resolving cross-platform conflicts. Patches create the environment required for proper compilation.

3) Specification File – The specification file is at the heart of RPM package building process. It contains information required by RPM to build the package, as well as instructions telling RPM how to build it. The specification file also dictates exactly what files are a part of the package, and where they should be installed.

** Specification File ~ is divided in to 8 sections as shown below

a) Preamble ~ contains information that will be displayed when users request information about the package. This would include a description of the package’s function, the version number of the software etc.

b) Preparation ~ where the actual work of building a package starts. As the name implies, this section is where the necessary preparations are made prior to the actual building of the software. In general, if anything needs to be done to the sources prior to building the software, it needs to happen in the preparation section. The contents of this section are an ordinary shell script. However, RPM does provide two macros to make life easier. One macro can unpack a compressed tar file and cd into the source directory. The other macro easily applies patches to the unpacked sources.

c) Build ~ This section consists of a shell script. It is used to perform whatever commands are required to actually compile the sources like single make  command, or be more complex if the build process requires it. There are no macros available in this section.

d) Install ~ This section also containing a shell script, the install section is used to perform the commands required to actually install the software.

e) Install and Uninstall Scripts ~ It consists of scripts that will be run, on the user’s system, when the package is actually installed or removed. RPM can execute a script pre/post installation/removal of package.

f) Verify Script ~ script that is executed on the user’s system. It is executed when RPM verifies the package’s proper installation.

g) Clean Section ~ script that can clean things up after the build. This script is rarely used, since RPM normally does a good job of clean-up in most build environments.

h) File List ~ consists of a list of files that will comprise the package. Additionally, a number of macros can be used to control file attributes when installed, as well as to denote which files are documentation, and which contain configuration information. The file list is very important.

*** RPM’s requirement for build environment ~

A] RPM requires a set of directories to perform the build. While the directories’ locations and names can be changed. Default layout is shown below –

root@arunsb:~# ls -l /usr/src/redhat/

drwxr-xr-x 2 root root 4096 Aug 25  2007 SOURCES => Contains the original sources, patches, and icon files
drwxr-xr-x 2 root root 4096 Aug 25  2007 SPECS => Contains the specification files
drwxr-xr-x 2 root root 4096 Aug 25  2007 BUILD => Directory in which the sources are unpacked, & software is built
drwxr-xr-x 8 root root 4096 May 28  2008 RPMS => Contains the binary package files created by the build process
drwxr-xr-x 2 root root 4096 Aug 25  2007 SRPMS => Contains the source package files created by the build process

root@arunsb:~#

B] Need to export few global variables used by RPM –

root@arunsb:~# export  RPM_BUILD_DIR=/usr/src/redhat/BUILD/
root@arunsb:~# export  RPM_SOURCE_DIR=/usr/src/redhat/SOURCES/

Step 1] Create Specification (spec) File ~

root@arunsb:~# head -n 50  /usr/src/redhat/SPECS/openlsm.spec
# Authority: Arun Bagul

#RPM_BUILD_DIR    /usr/src/redhat/BUILD/
#RPM_SOURCE_DIR    /usr/src/redhat/SOURCES/

%define MY_PREFIX    /usr/local/openlsm/

## Preamble Section-
Name: openlsm
Version: 0.99
Vendor: IndianGNU.org & openlsm
Release: r45
Group: System Environment/Daemons
Packager: IndianGNU.org (http://www.indiangnu.org)
URL: http://openlsm.sourceforge.net/
Summary: openlsm Admin Server
License: GPL

%description
openlsm Admin Server is free & open source web based control panel for Linux,Unix systems.

## Preparation Section-
%prep

rm -rf ${RPM_BUILD_DIR}/openlsm-0.99-r45/
tar xvfz ${RPM_SOURCE_DIR}/openlsm-0.99-r45.tar.gz -C ${RPM_BUILD_DIR}

## Build Section-
%build

cd ./openlsm-0.99-r45/
./configure –prefix=/usr/local/openlsm –with-mysql=/usr/bin/mysql_config –enable-internal-pcre –with-geoip=/usr –with-ldap=/usr –enable-trace
make

## Install Section-
%install

cd ./openlsm-0.99-r45/
make install

## Files Section-
%files

/usr/local/openlsm
/usr/local/openlsm/etc/openlsm/openlsm.conf
/usr/local/openlsm/etc/openlsm/openlsm.conf.perf_sample
/usr/local/openlsm/etc/openlsm/ssl/
/usr/local/openlsm/bin/openlsm-config
….
…..
….. list of files installed by pkg
root@arunsb:~#

* How do you create the File List?

Creating the file list is manual process. What I did is I took the file list from my manual installed prefix directory with find command as shown below…

root@arunsb:~# find /usr/local/openlsm/ -type f -or  -type d

Step 2] Starting the Build ~

root@arunsb:~# cd /usr/src/redhat/SPECS
root@arunsb:/usr/src/redhat/SPECS# ls -l  openlsm.spec
-rw-r–r– 1 root root 12938 Dec  2 17:21 openlsm.spec
root@arunsb:/usr/src/redhat/SPECS#

root@arunsb:/usr/src/redhat/SPECS# rpmbuild   -ba  openlsm.spec

….
…..

Checking for unpackaged file(s): /usr/lib/rpm/check-files %{buildroot}
Wrote: /usr/src/redhat/SRPMS/openlsm-0.99-r45.src.rpm
Wrote: /usr/src/redhat/RPMS/i386/openlsm-0.99-r45.i386.rpm
root@arunsb:/usr/src/redhat/SPECS# echo $?
0

root@arunsb:/usr/src/redhat/SPECS# ls -l  /usr/src/redhat/SRPMS/openlsm-0.99-r45.src.rpm
-rw-r–r– 1 root root 3206 Dec  2 17:50 /usr/src/redhat/SRPMS/openlsm-0.99-r45.src.rpm
root@arunsb:/usr/src/redhat/SPECS# ls -l  /usr/src/redhat/RPMS/i386/openlsm-0.99-r45.i386.rpm
-rw-r–r– 1 root root 3052868 Dec  2 17:50 /usr/src/redhat/RPMS/i386/openlsm-0.99-r45.i386.rpm
root@arunsb:/usr/src/redhat/SPECS#

* Source and Binary package created !!

** Let’s see what happened in “/usr/src/redhat/” directory

root@arunsb:/usr/src/redhat# pwd
/usr/src/redhat
root@arunsb:/usr/src/redhat# ls
BUILD  RPMS  SOURCES  SPECS  SRPMS
root@arunsb:/usr/src/redhat# ls BUILD/
openlsm-0.99-r45                                               <== Source extracted here as part of build instructions from specification file ie “openlsm.spec”
root@arunsb:/usr/src/redhat# ls SOURCES/
openlsm-0.99-r45.tar.gz                                 <== original ‘openlsm-0.99-r45.tar.gz’ source file copied by me
root@arunsb:/usr/src/redhat# ls RPMS/
athlon  i386  i486  i586  i686  noarch
root@arunsb:/usr/src/redhat# ls RPMS/i386/
openlsm-0.99-r45.i386.rpm <== Binary rpm package created!
root@arunsb:/usr/src/redhat# ls SRPMS/
openlsm-0.99-r45.src.rpm <== Source rpm package created!
root@arunsb:/usr/src/redhat#

Step 3] Now install the package and test it ~

root@arunsb:/usr/src/redhat# cp RPMS/i386/openlsm-0.99-r45.i386.rpm  /home/arunsb/

root@arunsb:/usr/src/redhat# cd /home/arunsb/
root@arunsb:~# ls
openlsm-0.99-r45.i386.rpm
root@arunsb:~# rpm -ivh openlsm-0.99-r45.i386.rpm
Preparing…                ########################################### [100%]
1:openlsm                ########################################### [100%]
root@arunsb:~# ls /usr/local/openlsm/
bin  contrib  etc  include  lib  sbin  scripts  share  var
root@arunsb:~#

** Starting the openlsm server ~

root@arunsb:~# /usr/local/openlsm/contrib/openlsm-redhat  start
* Starting openlsm admin server: openlsm
.                                                         [  OK  ]
root@arunsb:~#
root@arunsb:~# /usr/local/openlsm/contrib/openlsm-redhat  status
openlsm (pid 21607) is running…
root@arunsb:~#

root@arunsb:~# rpm -q openlsm-0.99-r45
openlsm-0.99-r45
root@arunsb:~#

root@arunsb:~# rpm -ql  openlsm-0.99-r45
..

root@arunsb:~# rpm  -qiv  openlsm-0.99-r45
Name        : openlsm                      Relocations: (not relocatable)
Version     : 0.99                              Vendor: IndianGNU.org & openlsm
Release     : r45                           Build Date: Wed 02 Dec 2009 05:50:54 PM IST
Install Date: Wed 02 Dec 2009 06:06:23 PM IST      Build Host: alongseveral-dr.eglbp.corp.yahoo.com
Group       : System Environment/Daemons    Source RPM: openlsm-0.99-r45.src.rpm
Size        : 14877918                         License: GPL
Signature   : (none)
Packager    : IndianGNU.org (http://www.indiangnu.org)
URL         : http://openlsm.sourceforge.net/
Summary     : openlsm Admin Server
Description :
openlsm Admin Server is free & open source web based control panel for Linux,Unix systems.
root@arunsb:~#

** NOTE ~ This article does not contain information on how to define micros,how to copy docs,man pages to default location, how to set permision and ownership etc. I will cover this topics in next article on RPM.

Regards,
Arun Bagul

***

|| How to create or build RPM Package ||

Introduction –

* “rpmbuild” tool is used to build both…

1) Binary Package ~ used to install the software and supporting scripts. It contains the files that comprise the application, along with any additional information needed to install and erase it.
2) Source Package ~ contains the original compressed tar file of source code, patches and Specification File.

* What is RPM & RPM package Manager?

The RPM Package Manager (RPM) is a powerful command line package management system capable of installing, uninstalling, verifying, querying, and updating software packages.

RPM package consists of an archive of files and meta-data used to install and erase the archive files. The meta-data includes helper scripts, file
attributes, and descriptive information about the package.

* To build RPM package you need to specify three things ~

1) Source of application – In any case, you should not modify the sources used in the package building process.

2) Patches – RPM gives you the ability to automatically apply patches to them. The patch addresses an issue specific to the target system. This could include changing makefiles to install the application into the appropriate directories, or resolving cross-platform conflicts. Patches create the environment required for proper compilation.

3) Specification File – The specification file is at the heart of RPM package building process. It contains information required by RPM to build the package, as well as instructions telling RPM how to build it. The specification file also dictates exactly what files are a part of the package, and where they should be installed.

** Specification File ~ is divided in to 8 sections as shown below

a) Preamble ~ contains information that will be displayed when users request information about the package. This would include a description of the package’s function, the version number of the software etc.

b) Preparation ~ where the actual work of building a package starts. As the name implies, this section is where the necessary preparations are made prior to the actual building of the software. In general, if anything needs to be done to the sources prior to building the software, it needs to happen in the preparation section. The contents of this section are an ordinary shell script. However, RPM does provide two macros to make life easier. One macro can unpack a compressed tar file and cd into the source directory. The other macro easily applies patches to the unpacked sources.

c) Build ~ This section consists of a shell script. It is used to perform whatever commands are required to actually compile the sources like single make  command, or be more complex if the build process requires it. There are no macros available in this section.

d) Install ~ This section also containing a shell script, the install section is used to perform the commands required to actually install the software.

e) Install and Uninstall Scripts ~ It consists of scripts that will be run, on the user’s system, when the package is actually installed or removed. RPM can execute a script pre/post installation/removal of package.

f) Verify Script ~ script that is executed on the user’s system. It is executed when RPM verifies the package’s proper installation.

g) Clean Section ~ script that can clean things up after the build. This script is rarely used, since RPM normally does a good job of clean-up in most build environments.

h) File List ~ consists of a list of files that will comprise the package. Additionally, a number of macros can be used to control file attributes when installed, as well as to denote which files are documentation, and which contain configuration information. The file list is very important.

*** RPM’s requirement for build environment ~

A] RPM requires a set of directories to perform the build. While the directories’ locations and names can be changed. Default layout is shown below –

root@arunsb:~# ls -l /usr/src/redhat/

drwxr-xr-x 2 root root 4096 Aug 25  2007 SOURCES        => Contains the original sources, patches, and icon files
drwxr-xr-x 2 root root 4096 Aug 25  2007 SPECS            => Contains the specification files
drwxr-xr-x 2 root root 4096 Aug 25  2007 BUILD            => Directory in which the sources are unpacked, and the software is built
drwxr-xr-x 8 root root 4096 May 28  2008 RPMS            => Contains the binary package files created by the build process
drwxr-xr-x 2 root root 4096 Aug 25  2007 SRPMS            => Contains the source package files created by the build process

root@arunsb:~#

B] Need to export few global variables used by RPM –

root@arunsb:~# export RPM_BUILD_DIR=/usr/src/redhat/BUILD/
root@arunsb:~# export RPM_SOURCE_DIR=/usr/src/redhat/SOURCES/

Step 1] Create Specification (spec) File ~

root@arunsb:~# head -n 50  /usr/src/redhat/SPECS/openlsm.spec
# Authority: Arun Bagul

#RPM_BUILD_DIR    /usr/src/redhat/BUILD/
#RPM_SOURCE_DIR    /usr/src/redhat/SOURCES/

%define MY_PREFIX    /usr/local/openlsm/

## Preamble Section-
Name: openlsm
Version: 0.99
Vendor: IndianGNU.org & openlsm
Release: r45
Group: System Environment/Daemons
Packager: IndianGNU.org (http://www.indiangnu.org)
URL: http://openlsm.sourceforge.net/
Summary: openlsm Admin Server
License: GPL

%description
openlsm Admin Server is free & open source web based control panel for Linux,Unix systems.

## Preparation Section-
%prep

rm -rf ${RPM_BUILD_DIR}/openlsm-0.99-r45/
tar xvfz ${RPM_SOURCE_DIR}/openlsm-0.99-r45.tar.gz -C ${RPM_BUILD_DIR}

## Build Section-
%build

cd ./openlsm-0.99-r45/
./configure –prefix=/usr/local/openlsm –with-mysql=/usr/bin/mysql_config –enable-internal-pcre –with-geoip=/usr –with-ldap=/usr –enable-trace
make

## Install Section-
%install

cd ./openlsm-0.99-r45/
make install

## Files Section-
%files

/usr/local/openlsm
/usr/local/openlsm/etc/openlsm/openlsm.conf
/usr/local/openlsm/etc/openlsm/openlsm.conf.perf_sample
/usr/local/openlsm/etc/openlsm/ssl/
/usr/local/openlsm/bin/openlsm-config
….
…..
….. list of files installed by pkg
root@arunsb:~#

* How do you create the File List?

Creating the file list is manual process. What I did is I took the file list from my manual installed prefix directory with find command as shown below…

root@arunsb:~# find /usr/local/openlsm/ -type f -or  -type d

Step 2] Starting the Build ~

root@arunsb:~# cd /usr/src/redhat/SPECS
root@arunsb:/usr/src/redhat/SPECS# ls -l  openlsm.spec
-rw-r–r– 1 root root 12938 Dec  2 17:21 openlsm.spec
root@arunsb:/usr/src/redhat/SPECS#

root@arunsb:/usr/src/redhat/SPECS# rpmbuild -ba openlsm.spec

….
…..

Checking for unpackaged file(s): /usr/lib/rpm/check-files %{buildroot}
Wrote: /usr/src/redhat/SRPMS/openlsm-0.99-r45.src.rpm
Wrote: /usr/src/redhat/RPMS/i386/openlsm-0.99-r45.i386.rpm
root@arunsb:/usr/src/redhat/SPECS# echo $?
0

root@arunsb:/usr/src/redhat/SPECS# ls -l  /usr/src/redhat/SRPMS/openlsm-0.99-r45.src.rpm
-rw-r–r– 1 root root 3206 Dec  2 17:50 /usr/src/redhat/SRPMS/openlsm-0.99-r45.src.rpm
root@arunsb:/usr/src/redhat/SPECS# ls -l  /usr/src/redhat/RPMS/i386/openlsm-0.99-r45.i386.rpm
-rw-r–r– 1 root root 3052868 Dec  2 17:50 /usr/src/redhat/RPMS/i386/openlsm-0.99-r45.i386.rpm
root@arunsb:/usr/src/redhat/SPECS#

* Source and Binary package created !!

** Let’s see what happened in “/usr/src/redhat/” directory

root@arunsb:/usr/src/redhat# pwd
/usr/src/redhat
root@arunsb:/usr/src/redhat# ls
BUILD  RPMS  SOURCES  SPECS  SRPMS
root@arunsb:/usr/src/redhat# ls BUILD/
openlsm-0.99-r45                                <== Source extracted here as part of build instructions from specification file ie “openlsm.spec”
root@arunsb:/usr/src/redhat# ls SOURCES/
openlsm-0.99-r45.tar.gz                         <== original ‘openlsm-0.99-r45.tar.gz’ source file copied by me
root@arunsb:/usr/src/redhat# ls RPMS/
athlon  i386  i486  i586  i686  noarch
root@arunsb:/usr/src/redhat# ls RPMS/i386/
openlsm-0.99-r45.i386.rpm                       <== Binary rpm package created!
root@arunsb:/usr/src/redhat# ls SRPMS/
openlsm-0.99-r45.src.rpm            <== Source rpm package created!
root@arunsb:/usr/src/redhat#

Step 3] Now install the package and test it ~

root@arunsb:/usr/src/redhat# cp RPMS/i386/openlsm-0.99-r45.i386.rpm  /home/arunsb/

root@arunsb:/usr/src/redhat# cd /home/arunsb/
root@arunsb:~# ls
openlsm-0.99-r45  openlsm-0.99-r45.i386.rpm  openlsm-0.99-r45.tar.gz  thttpd-2.25b-3.dag.src.rpm  thttpd-2.25b-dag.spec
root@arunsb:~# rpm -ivh openlsm-0.99-r45.i386.rpm
Preparing…                ########################################### [100%]
1:openlsm                ########################################### [100%]
root@arunsb:~# ls /usr/local/openlsm/
bin  contrib  etc  include  lib  sbin  scripts  share  var
root@arunsb:~#

** Starting the openlsm server ~

root@arunsb:~# /usr/local/openlsm/contrib/openlsm-redhat  start
* Starting openlsm admin server: openlsm
.                                                         [  OK  ]
root@arunsb:~#
root@arunsb:~# /usr/local/openlsm/contrib/openlsm-redhat  status
openlsm (pid 21607) is running…
root@arunsb:~#

root@arunsb:~# rpm -q openlsm-0.99-r45
openlsm-0.99-r45
root@arunsb:~#

root@arunsb:~# rpm -lq openlsm-0.99-r45
..

root@arunsb:~# rpm -qiv openlsm-0.99-r45
Name        : openlsm                      Relocations: (not relocatable)
Version     : 0.99                              Vendor: IndianGNU.org & openlsm
Release     : r45                           Build Date: Wed 02 Dec 2009 05:50:54 PM IST
Install Date: Wed 02 Dec 2009 06:06:23 PM IST      Build Host: alongseveral-dr.eglbp.corp.yahoo.com
Group       : System Environment/Daemons    Source RPM: openlsm-0.99-r45.src.rpm
Size        : 14877918                         License: GPL
Signature   : (none)
Packager    : IndianGNU.org (http://www.indiangnu.org)
URL         : http://openlsm.sourceforge.net/
Summary     : openlsm Admin Server
Description :
openlsm Admin Server is free & open source web based control panel for Linux,Unix systems.
root@arunsb:~#

** NOTE ~ This article does not contain information on how to define micros,how to copy docs,man pages to default location, how to set permision and ownership etc. I will cover this topics in next article on RPM.

Regards,
Arun Bagul

How to disable core(s) of CPU

How to disable core(s) of CPU

Introduction ~

The question is why we  need to disable few core of CPU? Sometime it is necessary to run certain applications, which are not compatible with multi core processing.  Disabling core will not affect physically your hardware. Linux OS will simply ignore the core(s) you selected to disable.

Steps 1] How to do it?

Debian/Ubuntu ~

root@laptop:/home/arunsb# cat /boot/grub/menu.lst

title        Ubuntu 9.04, kernel 2.6.28-11-generic
kernel        /vmlinuz-2.6.28-11-generic root=UUID=55d33e45-75c7-54sc-b204-97b44e1d6a39 ro quiet splash maxcpus=1
initrd        /initrd.img-2.6.28-11-generic

Redhat/Fedora based system ~

root@laptop:/home/arunsb# cat /boot/grub/grub.conf

title Red Hat Enterprise Linux ES (2.6.9-78.ELsmp)
root (hd0,4)
kernel /boot/vmlinuz-2.6.9-78.ELsmp ro root=LABEL=/    maxcpus=1
initrd /boot/initrd-2.6.9-78.ELsmp.img

Note ~ after changing grub config file please reboot the system to apply changes!

As shown above “maxcpus=1” indicates that Linux will use only one CPU core. you can change this value as per your requirement and hardware available.

You can  also change this value during  starting of system from GRUB menu but it is temporary setting. To make it permanent you need to modify the  grub.conf (Redhat/Fedora) or menu.lst (debian/Ubuntu) GRUB config file.

Step 2] How to verify ~

I have dual core CPU as shown below and I have disable 1 core so After reboot I should get only one CPU core active

** Before above setting!

root@laptop:/home/arunsb# cat /proc/cpuinfo   | grep processor
processor    : 0
processor    : 1
root@laptop:/home/arunsb#

* Verify after above setting ~

root@laptop:/home/arunsb# cat /proc/cpuinfo   | grep processor
processor       : 0

root@laptop:/home/arunsb#

* How to Disable CPU without Reboot?
root@arunb:~# echo 0 > /sys/devices/system/cpu/cpu1/online

* Confirm ?
root@arunb:~# cat /proc/cpuinfo | grep -i ‘Processor’
processor : 0
root@arunb:~#

Thank you,
Arun Bagul

How to create edit/extract initrd in Ubuntu/Debian and Redhat/Fedora Linux ?

How to create edit/extract initrd in Ubuntu/Debian and Redhat/Fedora Linux ?

Introduction ~

Long back I edited initrd as  old linux (Ubuntu 6.06) box was not able to boot with SCSI hard disk? One of my friend wanted to do the same for other purpose. So got a chance to write article on the same? Let’s start with what is initrd?

What is initrd ?

initrd (Initial Ram Disk) is a temporary file system ( used as /) commonly used in the boot process of the Linux kernel. It is typically used for making preparations before the real root file system can be mounted.

Why someone want to edit/modify initrd ?

I assume that you all are familier with Linux booting process? Once Linux kernel loaded in to memory (RAM) it start init (father/mother of all  process) process. is that true? Let me ask you one question. Before loading actual physical root file system (/) how kernel access /sbin/init script? what is the use by specifying “initrd” file in GRUB ?  hold on!!

Suppose your root partion resides on some SCSI device and driver for this SCSI devices is compiled as a kernel module. Of course this module is required at boot time to have access to the root partion — but it is not in the kernel. Thus the need for an initrd image. Additionally after udev subsystem become common, somebody has to start udev to create device nodes. This is initrd’s duty too.

See the GRUB menu as shown below ~

title        Ubuntu 9.04, kernel 2.6.28-11-generic
kernel        /vmlinuz-2.6.28-11-generic root=/dev/sda3  ro quiet splash
initrd        /initrd.img-2.6.28-11-generic

GRUB loads  kernel and initrd image in to memory(RAM). When kernel boots  it checks for initrd image, and if it exists starts init script that resides on this image. init script is usually written in bash. When init script on initrd image is finished, kernel usually start standard init process ie /sbin/init

Step 1] Copy original initrd image file to temp location  ~

** Create temporary directory and copy initrd file in that temp directory

arunsb@laptop:~$ cp /boot/initrd.img-2.6.28-11-generic  /tmp/

arunsb@laptop:~$ mkdir /tmp/initrd-src

** Now extract “initrd” image –

arunsb@laptop:~$ cd /tmp/initrd-src

arunsb@laptop:/tmp/initrd-src$ gzip -dc  /tmp/initrd.img-2.6.28-11-generic  | cpio -id
38791 blocks
arunsb@laptop:/tmp/initrd-src$ ls -l
total 36
drwxr-xr-x 2 arunsb arunsb 4096 2009-07-12 16:32 bin
drwxr-xr-x 3 arunsb arunsb 4096 2009-07-12 16:32 conf
drwxr-xr-x 6 arunsb arunsb 4096 2009-07-12 16:32 etc
-rwxr-xr-x 1 arunsb arunsb 4825 2009-07-12 16:32 init
drwxr-xr-x 5 arunsb arunsb 4096 2009-07-12 16:32 lib
drwxr-xr-x 2 arunsb arunsb 4096 2009-07-12 16:32 sbin
drwxr-xr-x 8 arunsb arunsb 4096 2009-07-12 16:32 scripts
drwxr-xr-x 3 arunsb arunsb 4096 2009-07-12 16:32 usr
arunsb@laptop:/tmp/initrd-src$

** Check how “init” looks like ~

arunsb@laptop:/tmp/initrd-src$ head init
#!/bin/sh

echo “Loading, please wait…”

[ -d /dev ] || mkdir -m 0755 /dev
[ -d /root ] || mkdir -m 0700 /root
[ -d /sys ] || mkdir /sys
[ -d /proc ] || mkdir /proc
[ -d /tmp ] || mkdir /tmp
mkdir -p /var/lock
arunsb@laptop:/tmp/initrd-src$

Step 2] Edit/Modify as per your requirement

Step 3] How to create initrd image  ~

Create initrd image from scratch –

root@laptop:/home/arunsb# mkinitramfs  -v -o  /tmp/initrd-arun-$(uname -r)

root@laptop:/home/arunsb# ls -l /tmp/initrd-arun-2.6.28-11-generic
-rw-r–r– 1 root root 7536506 2009-07-12 17:11 /tmp/initrd-arun-2.6.28-11-generic

root@laptop:/home/arunsb# du -sh /tmp/initrd-arun-2.6.28-11-generic
7.2M    /tmp/initrd-arun-2.6.28-11-generic
root@laptop:/home/arunsb#

mkinitramfs ~ is the tool used to create initrd image. “initrd” image is a gzipped cpio archive.

** After all modifcation create initrd image as shown below…

arunsb@laptop:/tmp/initrd-src$ find . | cpio –quiet –dereference -o -H newc | gzip -9 > /tmp/initrd.img-2.6.28-11-arun
arunsb@laptop:/tmp/initrd-src$ ls -l /tmp/initrd.img-2.6.28-11-arun
-rw-r–r– 1 arunsb arunsb 7505955 2009-07-12 16:56 /tmp/initrd.img-2.6.28-11-arun
arunsb@laptop:/tmp/initrd-src$

* Enjoy !!

Regards,
Arun Bagul