Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Linux (http://www.go4expert.com/articles/linux/)
-   -   Make Your Own Linux (http://www.go4expert.com/articles/linux-t985/)

Tango Issac Debian 7Jul2006 01:28

Make Your Own Linux
 
Linux now become the platform of the developers.They now feeling very excited in their colorful life with Linux.Some of them are thinking Linux as their wife!They always spending with Linux.They can now explain themselves more significantly to the total developer's world with their Personal Linux.They generate the sense of the Linux as more powerful,reliable,flexiable and scalable in the total developer's world.......They make it too flexible to support for multitude of multiprocessor's architechture,hardware devices,graphical support and communication protocols.

Some days ago,I have done an experiment with my friend's old unused PC for our target project.Our targets were---------------------
  1. Develop a boot loader to run on the PowerON
  2. A configured linux kernel
  3. A sweet file-system all with the necessary software.

HARDWARE USED:

  1. A P2 machine
  2. A 16MB RAM
  3. 2GB HDD
  4. A AMD Athlon 64 2800+(1.8GHz)machine as a host for our development

Maintaining the development Environment:



In this case,the development process has done on the host system,taking the targeting system as the consideration,because of the high memory,advantage of the lower compile time of the host machine.Here,the concept of the "Cross-compilation "is needed.Because the CROSS_COMPILER is a system that runs on one type of processor,but compiles instructions for the another.

Setting up the HOST



Though the presence of the different several processes I have used here "REMOVABLE STORAGE SETUP", where there are no direct physical link between the host and the target.Actually, a storage device is written by the host and is transferred into the target,which is used to boot the target system.

Preparation for the Host Environment

  1. Install a latest Linux edition of REDHAT,or other similar.
  2. Format the target HDD with a suitable file system.(I prefer ext2).
  3. The host system should have "Cross-Compiler toolchain" to build up the software for the target system.I have used GNU's cross Platform developent toolchain.I also used
    1. Binary Utilities (Assembler,linker and Various Object file Utilities).
    2. The GCC compiler for GNU C,C++
    3. The C Library(like glibc,newlib etc.)

Binding up our personal Toolchaon



Here , an alternative C library like "uClibc" is choosen for my personal system development.The "uClibc" is a C library optimized for embedded systems.

To build up our custom toolchain I have performed some steps as --------

With the open source Automation tools like "buildroot" I have configured the toolchain and installed it in "uClibc" version, "binutils" version, GCC version and so on.

After the succesful toolchain compilation,it has installed in a specific PATH environment variable to the "bin" directory of the installed path.

Having the cross development platform ready,we need three components to build up a complete Linux environment for an embedded system.
  1. The Kernel
  2. The Root file System
  3. The Boot Loader

Setting up the KERNEL:



First download the Linux kernel from "www.kernel.org" (say as inux2.4.20.tar.bz2) and extract it and cd to the directory.Now ,feel the thrillings that U'r ready now to compile the chossen kernel with your new toolchain.So, edit the "makefile" to set up the "CROSSCOMPILE" prefix using

CROSSCOMPILE =i386-linux-uclibc

Then configure the kernel according to the embedded target device requirements using

make menuconfig or make xconfig.

Then issue the "make dep" and "make bzImage" commands.

The kernel image is now built in the "arch/i386/boot" directory. If the modules r enabled,implement "make modules",and " make modules-install" . The compiled modules will be installed in " /lib/modules/linux-<version>".

Creating the Root File System



I have created the root file system on the previous "ext2" formatted HDD.FIrst, we mount the partition as SUPER USER,by

#mount -t ext2 /dev/hdc1 /mnt/target

Now enter to the /mnt/target dir and create a standard Linux root directory structure.

#mkdir bin boot dev etc etc/init.d proc sbin usr

Create "modules" directory in "lib" if modules were enabled.

#mkdir /lib/modules

Now set appropriate permissions for these directories.To set up various core linux utilities like sh,ls,cp,clear,mkdir.......Fortunately u can get a tool that combines all the utilities called " BUSYBOX".Busybox is highly configureable,and u can select only those utilities u want to for your platform.U can select also static or dynamic compilation.

Compile it with your new toolchain.

$ make
$ make PREFIX= /mnt/target install

This will populate bin,sbin,usr,usr directories with all symlinks to "busybox" binary in /mnt/target/bin directory.

Then,the boot directory needs to be generated with your previous compiled kernel image. U need to create the necessary device nodes appropriately in the "dev" directory using "mknod" utility; for example, the terminal devices like "tty", console , virtual terminal devices for VGA display,serial terminal devices,the ps mouse,null device etc.

Next set up the various startup scripts .Create a "rcS" script in " etc/init.d/"

#! /bin/sh
mount -a #Mount the default file system mentioned in /etc
/fstab
/bin/sh #Invoke Busybox shell

Create "fstab " file in /etc directory
Create "inittab" file in /etc directory

#This is run as first script
:: sysinit : /etc/init.d/rcS
::askfirst :-/bin/sh
::restart : /sbin/init
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/unmount -a -r >/dev/null 2>&1
Thse script may be customizesd according to the target requirements.

INSTALLING THE BOOT LOADER



To make first bootable Personal linux system u need to install the Boot Loader.Copy the Stage1 ,Stage2 dir.s of GRUB from the host machine into target's boot/GRUB directory.Install the GRUB on the target hard disk.

#/sbin/GRUB
#GRUB> root(hd1,0)
#GRUB> setup(hd1)

Now ,u need to edit 'etc/GRUB.conf as shown below:

#Assuming the Storage device will be installed as first
#harddisk.
title MYPERSONAL LINUX
root(hd0,0)
kernel /boot/bzImage ro root=/dev/hda1

Atlast,the GRUB should be compiled with our cross toolchain.

READY TO ENJOY



Shut down the host system.Remove the target HDD and install it on the target system.Power on this machine.See the GRUB menu.Select your choice.If choice the MYPERSONAL LINUX,your linux system get booted,and a Busybox shell promt should appear..

Now Start to enjoy........with Your Personal Linux System.

(At the last,Give greatful thanks to LINUS TORVALD ).

Resources:
  1. www.kernel.org

ManzZup 28Sep2011 21:39

Re: Make your own Linux
 
great one
gotta try this instead of LFS :)

dibinwebtech3 28Mar2012 17:40

Re: Make Your Own Linux
 
Grub installation very good and great pleasure


All times are GMT +5.5. The time now is 00:32.