Chinese (People's Republic of China)  English  Français


Supinfo-Projects.com
Tous les projets des élèves ingénieurs de Supinfo



Projets
  Dernier Projet
  Les plus populaires
  Tous les Projets

387 Visiteurs
3168 Projets


My Supinfo-Projects

   Connectez-vous
   Créez un Compte


Synopsis

   221 Visites
   Note INTERNET : 12
    (5 Votants)
   0 Commentaires

   Lire l'article

Evaluez cet article

20
18
16
14
12
10
8
6
4
2
0


Commentez cet article

Auteur :

Email :

Votre commentaire :



 
2005 - Pérennisation
Créer sa propre distribution Linux
[60 mn de lecture - paru le 11/24/2004 5:17:30 PM - Public : Confirmé]

Auteur

marcha_gFrançois MARCHAND
Elève-Ingénieur Supinfo Paris
Promotion SUPINFO 2004

   Lui écrire
   Tous les projets de cet auteur
   Le mini-CV de cet auteur

PART III – LOADING THE DISTRIBUTION IN RAM

 

Our distribution must be loaded into a ramdisk, a file system that is not on a drive but in memory. The linuxrx dectects the CD-ROM drive (had, hdb, hdc ou hdd), prepares a ramdisk that will be the new rootfs copies the necessary files and tells the system where is the root file system.

Then the system uses the init program on this file system and the distribution starts normally.

 

I- Creation of the initial ramdisk of initrd

 

The purpose of this rootf is to prepare the ramdisk to receive the rootfs, to detect where the CD-ROM drive is and to launch the copy of the files necessary to the construction of the rootfs. These are the files required for the initrd creation:

.

|-- bin

|   |-- bash

|   |-- cat

|   |-- cp

|   |-- echo

|   |-- findcd

|   |-- mke2fs

|   |-- mount

|   |-- rm

|   `-- umount

|-- cdrom

|-- dev

|   |-- console

|   |-- hda

|   |-- hdb

|   |-- hdc

|   |-- hdd

|   |-- null

|   `-- ram1

|-- etc

|   `-- mtab

|-- lib

|   |-- ld-linux.so.2

|   |-- libc.so.6

|   |-- libcom_err.so.2

|   |-- libcrypt.so.1

|   |-- libdl.so.2

|   |-- libe2p.so.2

|   |-- libext2fs.so.2

|   |-- libncurses.so.5

|   `-- libuuid.so.1

|-- linuxrc

|-- proc

`-- ramdisk

 

Voici le détail de ces fichiers :

.:

total 32

drwxr-xr-x    2 root     root         4096 Aug 24 16:09 bin

drwxr-xr-x    2 root     root         4096 Aug 21 12:31 cdrom

drwxr-xr-x    2 root     root         4096 Aug 21 16:00 dev

drwxr-xr-x    2 root     root         4096 Aug 21 15:48 etc

drwxr-xr-x    2 root     root         4096 Aug 21 14:54 lib

-rwxr-xr-x    1 root     root         1765 Aug 24 16:09 linuxrc

drwxr-xr-x    2 root     root         4096 Aug 19 15:46 proc

drwxr-xr-x    2 root     root         4096 Aug 21 12:29 ramdisk

 

./bin:

total 656

-rwxr-xr-x    1 root     root       461400 Aug 19 16:39 bash

-rwxr-xr-x    1 root     root         9668 Aug 19 15:56 cat

-rwxr-xr-x    1 root     root        32272 Aug 23 14:47 cp

-rwxr-xr-x    1 root     root         7148 Aug 19 15:56 echo

-rwxr-xr-x    1 root     root          576 Aug 21 17:55 findcd

-rwxr-xr-x    1 root     root        19536 Aug 21 12:36 mke2fs

-rwxr-xr-x    1 root     root        65404 Aug 19 15:56 mount

-rwxr-xr-x    1 root     root        20304 Aug 21 13:52 rm

-rwsr-xr-x    1 root     root        36572 Aug 19 15:56 umount

 

./cdrom:

total 0

 

./dev:

total 0

crw-r--r--    1 root     root       4,   0 Aug 19 16:02 console

brw-r--r--    1 root     root       3,   0 Aug 19 16:02 hda

brw-r--r--    1 root     root       3,  64 Aug 19 16:02 hdb

brw-r--r--    1 root     root      22,   0 Aug 19 16:02 hdc

brw-r--r--    1 root     root      22,  64 Aug 19 16:02 hdd

crw-r--r--    1 root     root       1,   3 Aug 19 16:02 null

brw-r-----    1 root     root       1,   1 Aug 21 16:00 ram1

 

./etc:

total 0

-rw-r--r--    1 root     root            0 Aug 21 15:48 mtab

 

./lib:

total 1332

-rwxr-xr-x    1 root     root        83976 Aug 19 15:59 ld-linux.so.2

-rwxr-xr-x    1 root     root       887712 Aug 19 15:59 libc.so.6

-rw-r--r--    1 root     root       5244 Aug 21 14:54 libcom_err.so.2

-rw-r--r--    1 root     root        20436 Aug 19 15:59 libcrypt.so.1

-rw-r--r--    1 root     root         9452 Aug 19 16:44 libdl.so.2

-rw-r--r--    1 root     root        12300 Aug 21 14:54 libe2p.so.2

-rw-r--r--    1 root     root       66000 Aug 21 14:54 libext2fs.so.2

-rw-r--r--    1 root     root     233816 Aug 19 16:41 libncurses.so.5

-rw-r--r--    1 root     root         7752 Aug 21 14:54 libuuid.so.1

 

./proc:

total 0

 

./ramdisk:

total 0

 

The files in the bin directory are binaries necessary to the linuxrc execution. The files in the lib directory are the libraries used by the programs in bin. To determine which libraries are necessary, we use ldd. The files in dev are imput/output files necessary to linuxrc.

 

Here is the linuxrc script, it uses the bash located in bin:

 

#! /bin/bash

echo "Installation of the ramdisk"

/bin/mount -n proc /proc -t proc

#mounting  procfs for collection system information

echo "Proc FS mounted"

/bin/mke2fs /dev/ram1 65535

#ramdisk formating

echo "ramdisk formated"

/bin/mount -n -t ext2 /dev/ram1 /ramdisk

#we mount the ramdisk in the fs initrd

echo "Ramdisk mounted"

/bin/rm -Rf /ramdisk/lost+found

#deleting lost+found directory

echo "Ramdisk ready"

/bin/mount -n -t iso9660 /dev/$(/bin/findcd) /cdrom

#we mount the cd-rom detected by findcd

echo "CD-ROM mounted"

echo "Copying files in progress ..."

echo "Copying directory /bin ..."

/bin/cp -Rpd /cdrom/bin /ramdisk/

echo "Copying directory /boot ..."

/bin/cp -Rpd /cdrom/boot /ramdisk/

echo "Copying directory /cdrom ..."

/bin/cp -Rpd /cdrom/cdrom /ramdisk/

echo "Copying directory /dev ..."

/bin/cp -Rpd /cdrom/dev /ramdisk/

echo "Copying directory /etc ..."

/bin/cp -Rpd /cdrom/etc /ramdisk/

echo "Copying directory /floppy ..."

/bin/cp -Rpd /cdrom/floppy /ramdisk/

echo "Copying directory /home ..."

/bin/cp -Rpd /cdrom/home /ramdisk/

echo "Copying directory /initrd ..."

/bin/cp -Rpd /cdrom/initrd /ramdisk/

echo "Copying directory /lib ..."

/bin/cp -Rpd /cdrom/lib /ramdisk/

echo "Copying directory /mnt ..."

/bin/cp -Rpd /cdrom/mnt /ramdisk/

echo "Copying directory /proc ..."

/bin/cp -Rpd /cdrom/proc /ramdisk/

echo "Copying directory /root ..."

/bin/cp -Rpd /cdrom/root /ramdisk/

echo "Copying directory /sbin ..."

/bin/cp -Rpd /cdrom/sbin /ramdisk/

echo "Copying directory /tmp ..."

/bin/cp -Rpd /cdrom/tmp /ramdisk/

echo "Copying directory /usr ..."

/bin/cp -Rpd /cdrom/usr /ramdisk/

echo "Copying directory /var ..."

/bin/cp -Rpd /cdrom/var /ramdisk/

echo "... Files copied"

#Copy of the files on the rootfs

/bin/umount /cdrom

#Unmounting CD-ROM

echo "CD-ROM démonté"

/bin/umount /ramdisk

#Unmounting ramdisk

echo "Ramdisk unmounted"

echo "257" > /proc/sys/kernel/real-root-dev

#We specify the new rootfs

#the number 257 is calculated from the minor and the major of the peripheral

#under the 0xminmaj form and converted to decimal

/bin/umount /proc

#We unmount the proc fs

 


This script works thanks to another bash script that allows CD-ROM detection. This script uses the data in /proc to determine where the CD-ROM is.  Here is the script:

 

#! /bin/bash

function returnhda

{

 if [ $(cat /proc/ide/ide0/hda/media) = "cdrom" ]

 then echo "hda"

 fi

}

 

function returnhdb

{

 if [ $(cat /proc/ide/ide0/hdb/media) = "cdrom" ]

 then echo "hdb"

 fi

}

 

function returnhdc

{

 if [ $(cat /proc/ide/ide1/hdc/media) = "cdrom" ]

 then echo "hdc"

 fi

}

 

function returnhdd

{

 if [ $(cat /proc/ide/ide1/hdd/media) = "cdrom" ]

 then echo "hdd"

 fi

}

 

test -e /proc/ide/ide0/hda/media && returnhda

test -e /proc/ide/ide0/hdb/media && returnhdb

test -e /proc/ide/ide1/hdc/media && returnhdc

test -e /proc/ide/ide1/hdd/media && returnhdd

 

This script performs tests in the /proc directory in order to determine where the CD-ROM drive is. Once these tests have been performed, is sends the CD-ROM drive’s ID so that the linuxrc script can mount it and copy the necessary files.

 

We now need to create and image of this initrd. Let us start by creating a 2MB ram file system and mount it:

#mke2fs /dev/ram 2048

#mount /dev/ram /mnt

 

We can now copy the files needed with the –Rvpd option in order to keep the permissions of the copied files. We suppose that the previous files are in /backup_initrd .

#cp –Rvpd ./backup_initrd/* /mnt

 

II- Making the boot file system (bootfs)

 

We now need to create an image of this file system. We use the dd tool with the following syntax:

#dd if=/dev/ram bs=1k count=2048 | gzip –v9 > initrd.gz

On remarque que l’image a été compressé afin d’occuper le moins de place possible.

 

The image has been compressed to reduce its size. Nous allons maintenant pouvoir passer à la réalisation de l’étape suivante de la distribution, la création du bootfs.

We can now copy the initial ramdisk image (intitrd.gz) in the boot directory of our LFS system. We will use LILO to copy the boot sector of the floppy disk. This is our lilo.conf file that we named mdlilo.conf:

 

boot =/dev/fd0

install =/boot/boot.b

map =/boot/map

read-write

backup =/dev/null

compact

image           = kernel

label  = ramd

initrd = /boot/initrd.gz

 

We have specified the initrd. Although the distribution is on a bootable CD-ROM, we specify that the boot peripheral is /dev/fd0 to respect the emulation system.

 

In order to create the boot disk that we will use to produce our CD-ROM image, we have to use a true floppy disk and create its image. We start by formatting a floppy disk in the /dev/fd0 drive:

#mke2fs /dev/fd0 1440

 

We mount the floppy disk :

#mount /dev/fd0 /floppy

 

We copy the necessary files that we have previously created in /backup_bootfs :

 #cp –Rvpd . /backup_bootfs/* /floppy

 

Once the floppy disk created, we make it bootable using a specific LILO command :

#lilo –v –C mdlilo.conf –r /floppy

 

This command uses the mdlilo.conf file to write the floppy disk boot sector of the floppy mounted on /floppy.

We now need to create an image of this floppy disk using the dd tool, we will call it bootfs.img:

 

#dd if=/dev/fd0 of=bootfs.img bs=10k count=144

 

III- Creation of the iso image

 

We can now create the .iso image for our CD-ROM. We will use the “El Torito” specification to make a bootable CD-ROM. It requires a boot.catalog file and the boot floppy disk previously created. We will use the mkisofs utility to create the iso image. We run this command from the root file system:

 

#mkisofs –r –b boot/bootfs.img –c boot/boot.catalog –o bootcd.iso .

 

We can now burn our image on a recordable CD-ROM with the help of a CD recorder software such as cdrecord.

 



Articles de la même catégorie

 Pages : Top


136 Visites
0 Commentaires
"Thin Client/ Windows Terminal Server" or lightening of data-processing maintenance
[30 mn de lecture - paru le 11/22/2004 12:11:30 PM - Public : Débutant]

En savoir plus


66 Visites
0 Commentaires
Newsletters management
[15 mn de lecture - paru le 11/22/2004 5:30:18 AM - Public : Débutant]

En savoir plus


55 Visites
0 Commentaires
The Technology for the communities
[20 mn de lecture - paru le 11/21/2004 5:59:47 PM - Public : Débutant]

En savoir plus

   Tous les Articles


SUPINFO Training Center peut vous proposer une formation système ...

   Devenez Ingénieur Système Microsoft en 35 jours avec SUPINFO Training Center
   Devenez Administrateur Système Microsoft avec SUPINFO Training Center


Powered by Campus-Booster Technology
Conditions d'utilisation & Copyright | Respect de la vie privée
© Copyright 1965-2006 Supinfo Paris, Paris Academy of Computer Science
Supinfo, Ecole Supérieure d'Informatique et Paris Academy Of Computer Science are trade marks.
23, rue de Château LANDON - 75010 PARIS - Phone : +33 (0) 153359 700 Fax : +33 (0) 153359 701

Web site autided by :