Changeset 1052

Show
Ignore:
Timestamp:
10/15/06 10:48:16 (2 years ago)
Author:
tushar
Message:

Moved mk_initrd+devfs to OLD

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/OLD/mk_initrd+devfs.txt

    r656 r1052  
    1 TITLE:          Initial Ram-disk's with devfs 
    2 LFS VERSION:    3.3 (or higher with at least 2.4.19 kernel and devfs enabled) 
    3 AUTHOR:         Martial Daumas <martial@nasgaia.org> 
     1AUTHOR: Martial Daumas <martial@nasgaia.org> 
    42 
    5 SYNOPSIS: 
    6         How to create a very simple mk_initrd command that works nice with LFS and devfs. 
     3DATE: 2003-09-18 
    74 
    8 HINT: 
    9 HINT            ver 1.0 2002-10-26 
     5LICENSE: GNU Free Documentation License Version 1.2 
    106 
    11         THIS HINT IS IN THE PROCESS OF BEING WRITTEN. IT IS NOT COMPLETE. 
    12         IF YOU HAVE ANY SUGGESTIONS, CORRECTIONS AND OTHER COMMENTS FEEL FREE 
    13         TO MAIL THEM TO ME. 
     7SYNOPSIS: How to create a basic mk_initrd command that works nice with LFS and devfs. 
    148 
    15  
    16 TABLE OF CONTENTS 
    17 ================= 
    18  
    19 1. Why using an initrd 
    20 2. Overview 
    21 3. Create the configuration file 
    22 4. Create the linurxc script 
    23 5. Create the mk_initrd command 
    24 6. Using mk_initrd 
    25 7. A word on booting with grub 
    26 8. Ideas to make it better 
    27 9. Thanks 
    28  
    29 1. Why using an initrd 
    30 ======================= 
    31  
    32 Initial Ram-disk (aka initrd) is a minimal linux system that is run before the  
    33 actual root partition is mounted, it contains a file called linuxrc (either a  
    34 simple script as well as a more complicated compiled C/C++ program) which is  
     9DESCRIPTION: 
     10Initial Ram-disk (AKA initrd) is a minimal linux system that is run before the  
     11actual root partition is mounted, it contains an executable file called linuxrc  
     12(either a simple script as well as a more complicated compiled program) which is  
    3513automatically run, and when it's finished, normal boot sequence goes on. This  
    3614is mostly needed to load kernel modules needed to mount the root partition, thus 
     
    4018If you use LFS for your own usage, you generally know in advance what will 
    4119be the modules needed to get your root partition mounted, so you can simply  
    42 have theses supports compiled in the kernel, and forget about initrd. Initrd 
    43 can be helpful in the following circumstances: 
     20have theses supports compiled in the kernel, and forget about initrd,  
     21and this hint. Initrd can be helpful in the following circumstances: 
    4422 
    4523-You want to distribute a pre-compiled kernel and keep it as small and scalable 
    4624 as possible and you build a modular kernel, so that only needed modules are 
    47  loaded in memory (that was case). 
     25 loaded in memory (that's my case). 
    4826 
    49 -You are building an embedded system, for example on a CD-ROM, and you don't 
    50  know in advance on which hardware it will be run, in which case linuxrc 
    51  can be used to proceed tests or interactive actions, or further settings. 
     27-You are building an embedded system, for example on a live CD-ROM, and you  
     28 don't know in advance on what kind of hardware it will be run, in which  
     29 case linuxrc can be handy to proceed tests or interactive actions, or  
     30 further tweakings. 
    5231  
    5332-Mounting your root partition requires features that are only available as  
    5433 a separate module for some reason. 
    5534  
    56 -Some features are impossible to compile at the same time in the kernels
     35-Some features are impossible to compile at the same time in the kernel
    5736 due to conflicts, once again initrd can help. 
    5837 
    59  
    60 2. Overview 
    61 =========== 
    62  
    63 In previous versions of the kernel, creating an intitrd was possibly complicated 
    64 task, mainly in writing a correct linuxrc.  This hint in intended for those 
    65 using devfs, with a kernel version 2.4.19 (and later). 
     38In previous versions of the kernel, creating an initrd was possibly  
     39complicated task, mainly in writing a correct linuxrc.  This hint is  
     40intended for those using devfs, with a 2.4.x kernel, version 2.4.19 
     41and later. 2.6 kernel is not covered here but this hint will be updated  
     42soon. 
    6643 
    6744You can build an initrd by hands easily, but here we'll rather create a 
    68 mk_initrd command (as found on other distros), that is strictly minimal, and  
    69 can be reused whenever you setup change. 
     45mk_initrd command (as found on some other distros), that is strictly minimal,  
     46and can be reused whenever you setup change. This is primarily intended to 
     47explain how thing works. 
    7048 
     49PREREQUISITES: 
     50- linux kernel 2.4.19 or later, compiled with maximum modules use. 
     51- the ash shell (optionnal). 
     52- sufficient knowledge of how kernel works at boot time, as well 
     53as modules and boot loaders usage. 
     54- You also need the latest versions of these files (subject to possible  
     55updates): 
    7156 
    72 3. Create the configuration file 
     57        http://nasgaia.org/~martial/lfs/initrd.conf 
     58        http://nasgaia.org/~martial/lfs/linuxrc 
     59        http://nasgaia.org/~martial/lfs/mk_initrd 
     60 
     61HINT: 
     621. Create the configuration file 
    7363================================ 
    7464 
    75 This file cans be use to scale the initrd to your needs. Create an empty file: 
    76 /etc/initrd.conf and copy the following lines in it: 
    77  
    78 --------------------------- /etc/initrd.conf ------------------------------  
    79 #!/bin/bash 
    80  
    81 LFS_INITRD_BINARIES="/bin/ash:/bin/ash /bin/cat:/bin/cat /sbin/insmod:/bin/insmod" 
    82 LFS_INITRD_SHLIBS="/lib/ld-2.2.5.so:/lib/ld-2.2.5.so /lib/libc.so.6:/lib/libc.so.6 " 
    83 LFS_INITRD_LNS="/bin/insmod:/bin/modprobe /lib/ld-2.2.5.so:/lib/ld-linux.so.2" 
    84 LFS_INITRD_LINUXRC="/usr/share/mk_initrd/linuxrc" 
    85 LFS_INITRD_NAME="/boot/initrd.gz" 
    86 LFS_INITRD_BLOCKSIZE="1k" 
    87 LFS_INITRD_SIZE="4096" 
    88 LFS_INITRD_TMP="/var/tmp" 
    89 LFS_MOD_DIR="/lib/modules" 
    90 --------------------------- end of /etc/initrd.conf ----------------------- 
     65This file cans be use to scale the initrd to your needs.  Copy the 
     66initrd.conf file in /etc, remember to edit it as needed to suit your 
     67libraries version. 
    9168 
    9269Syntax:  
     
    10582later on in linuxrc.  
    10683 
    107 4. Create the linurxc script 
     842. Create the linuxrc script 
    10885============================ 
    10986 
     
    11693(which eases a _lot_ the whole process). 
    11794 
     95Note: the value of the root partition is stored in the kernel at compile 
     96time, it that value is not correct (ie: you compiled the kernel somewhere 
     97else), see rdev(8) to change it. 
     98 
    11899Create a /usr/share/mk_initrd directory to store linuxrc with: 
    119100mkdir -p /usr/share/mk_initrd 
    120101 
    121 Now create an empty /usr/share/mk_initrd/linuxrc file, and copy this in it: 
     102Now copy the file linuxrc  as /usr/share/mk_initrd/linuxrc - please make 
     103it executable as needed (chmod +x). 
    122104 
    123 --------------------------- /usr/share/mk_initrd/linuxrc ------------------------------  
    124 #!/bin/ash 
    125 echo "Entering LFS initrd..." 
    126  
    127 cd /lib/modules && 
    128  
    129 for i in `cat /PROBE_ORDER`; do 
    130  echo "Will probe: $i " 
    131  insmod -v ./$i || echo "Fail !" 
    132 done 
    133  
    134 cd / 
    135  
    136 echo "Leaving LFS initrd " 
    137 ---------------------- end of /usr/share/mk_initrd/linuxrc ---------------------------- 
    138  
    139  
    140 5.Create the mk_initrd command 
     1053.Create the mk_initrd command 
    141106============================== 
    142107 
     
    144109of that script is explained later. 
    145110 
    146 Create en empty /usr/sbin/mk_initrd , copy this lines in it
     111Copy mk_initrd in /usr/sbin/ and make it executable
    147112 
    148 --------------------------- /usr/sbin/mk_initrd ------------------------------ 
    149 #!/bin/bash 
    150  
    151 usage()  
    152 { echo "mk_initrd: Create an initrd" 
    153   echo "USAGE: mk_initrd module1 module2 ..." 
    154   echo 
    155   echo "Be sure to have a floppy in the floppy drive before you run" 
    156   echo "this command. The floppy will be automatically formated" 
    157   echo 
    158   echo "Replace moduleN with the full path(es) to the modules you want" 
    159   echo "to include in the initrd. They will be probed in the specified order" 
    160   echo 
    161   echo "EXAMPLE command for a reiserfs-root initrd:" 
    162   echo "mk_initrd /lib/modules/`uname -r`/kernel/fs/reiserfs/reiserfs.o" 
    163   echo 
    164   exit 0 
    165  } 
    166    
    167 RANVAL1=$RANDOM 
    168  
    169 CONF_FILE=/etc/initrd.conf 
    170  
    171 [ "$1" == "--help" ] && usage 
    172 [ $# == 0 ] && usage 
    173  
    174  
    175 if ! [ -r $CONF_FILE ]; then 
    176  echo "Missing file (or wrong perms): $CONF_FILE - give up" 
    177  exit 1 
    178 fi 
    179  
    180 source $CONF_FILE  
    181  
    182  
    183 if [ -e "$LFS_INITRD_NAME" ]; then 
    184  
    185 echo "There's already a file: $LFS_INITRD_NAME, please make a choice: 
    186  
    187 1 Rename it $LFS_INITRD_NAME.`date -I`.$RANVAL1  and proceed 
    188 2 Delete $LFS_INITRD_NAME and proceed 
    189 3 Give up 
    190  
    191 Type a number:" 
    192  
    193 read choice  
    194         case $choice in 
    195                 1) 
    196                 mv $LFS_INITRD_NAME $LFS_INITRD_NAME.`date -I`.$RANVAL1 && 
    197                 echo "Backed up as $LFS_INITRD_NAME.`date -I`.$RANVAL1: OK" 
    198                 ;; 
    199                  
    200                 2) rm -f $LFS_INITRD_NAME && 
    201                 echo "Deletion of $LFS_INITRD_NAME: OK" 
    202                 ;; 
    203                  
    204                 3)  
    205                 exit 0 
    206                 ;; 
    207                  
    208                 *) 
    209                 exit 1 
    210                 ;; 
    211         esac 
    212 fi 
    213  
    214 RANVAL2=$RANDOM 
    215  
    216 mkdir -p $LFS_INITRD_TMP/initrd-$RANVAL2 || exit 1 
    217 echo "Creating needed Dir: $LFS_INITRD_TMP/initrd-$RANVAL2" 
    218  
    219 echo "Copying needed binaries:" 
    220 for i in $LFS_INITRD_BINARIES; do 
    221  src_bin=`echo $i | cut -f1 -d ':'` 
    222  dest_bin="$LFS_INITRD_TMP/initrd-$RANVAL2`echo $i | cut -f2 -d ':'`" 
    223   
    224  mkdir -p `dirname $dest_bin` && 
    225  cp $src_bin $dest_bin && 
    226  echo "$src_bin -> $dest_bin" 
    227 done 
    228 echo  
    229  
    230 echo "Copying needed shared libs:" 
    231 for i in $LFS_INITRD_SHLIBS; do 
    232  src_lib=`echo $i | cut -f1 -d ':'` 
    233  dest_lib="$LFS_INITRD_TMP/initrd-$RANVAL2`echo $i | cut -f2 -d ':'`" 
    234  
    235  mkdir -p `dirname $dest_lib` && 
    236  cp $src_lib $dest_lib && 
    237  echo "$src_lib -> $dest_lib" 
    238 done 
    239 echo 
    240  
    241 echo "Creating needed symlinks:" 
    242 for i in $LFS_INITRD_LNS; do 
    243  src_link=`echo $i | cut -f1 -d ':'` 
    244  dest_link="$LFS_INITRD_TMP/initrd-$RANVAL2`echo $i | cut -f2 -d ':'`" 
    245   
    246  mkdir -p `dirname $dest_link` && 
    247  ln -sf $src_link $dest_link && 
    248  echo "$src_link <- $dest_link" 
    249 done 
    250 echo 
    251  
    252 echo "Copying needed kernel modules:" 
    253 mkdir -p $LFS_INITRD_TMP/initrd-$RANVAL2$LFS_MOD_DIR 
    254  
    255 for i in $@; do 
    256 cp $i $LFS_INITRD_TMP/initrd-$RANVAL2$LFS_MOD_DIR && 
    257 echo "$i -> $LFS_INITRD_TMP/initrd-$RANVAL2$LFS_MOD_DIR/`basename $i`" 
    258 done 
    259  
    260 echo "Creating the file specifying module(s) probe order: 
    261 $LFS_INITRD_TMP/initrd-$RANVAL2/PROBE_ORDER, containing :" 
    262  
    263 for i in $@; do 
    264   short_modname=`basename $i` 
    265  
    266   echo $short_modname >> $LFS_INITRD_TMP/initrd-$RANVAL2/PROBE_ORDER 
    267   echo "$short_modname" 
    268 done 
    269 echo 
    270  
    271 echo "Creating additional directories" 
    272 mkdir -p $LFS_INITRD_TMP/initrd-$RANVAL2/bin  
    273 mkdir -p $LFS_INITRD_TMP/initrd-$RANVAL2/dev  
    274 mkdir -p $LFS_INITRD_TMP/initrd-$RANVAL2/lib/modules  
    275 mkdir -p $LFS_INITRD_TMP/initrd-$RANVAL2/root  
    276 mkdir -p $LFS_INITRD_TMP/initrd-$RANVAL2/sbin  
    277 mkdir -p $LFS_INITRD_TMP/initrd-$RANVAL2/usr/lib  
    278  
    279 cat $LFS_INITRD_LINUXRC > $LFS_INITRD_TMP/initrd-$RANVAL2/linuxrc && 
    280 chown 0.0 $LFS_INITRD_TMP/initrd-$RANVAL2/linuxrc && 
    281 chmod 755 $LFS_INITRD_TMP/initrd-$RANVAL2/linuxrc && 
    282 echo "Copying linuxrc into initrd" 
    283  
    284 # this empty file can be used by init to check if /initrd needs to be 
    285 # manually unmounted 
    286 touch $LFS_INITRD_TMP/initrd-$RANVAL2/LFS_INITRD  
    287  
    288 RANVAL3=$RANDOM 
    289 dd if=/dev/zero of=$LFS_INITRD_TMP/initrd.im-$RANVAL3 \ 
    290 bs=$LFS_INITRD_BLOCKSIZE count=$LFS_INITRD_SIZE || exit 1 
    291 echo "Creating empty image file: $LFS_INITRD_TMP/initrd.im-$RANVAL3" 
    292  
    293 mke2fs -F -m 0 -L LFS_initrd $LFS_INITRD_TMP/initrd.im-$RANVAL3 && 
    294 echo "Creating an ext2 FS in the image file" 
    295  
    296 RANVAL4=$RANDOM 
    297 mkdir -p $LFS_INITRD_TMP/initrd.mnt-$RANVAL4 && 
    298 echo "Creating temporary mount point: \ 
    299 $LFS_INITRD_TMP/initrd.mnt-$RANVAL4" 
    300  
    301 mount $LFS_INITRD_TMP/initrd.im-$RANVAL3 \ 
    302 $LFS_INITRD_TMP/initrd.mnt-$RANVAL4 -o loop && 
    303 echo "Mounting empty initrd image file on \ 
    304 $LFS_INITRD_TMP/initrd.mnt-$RANVAL4" 
    305  
    306 cp -a $LFS_INITRD_TMP/initrd-$RANVAL2/* $LFS_INITRD_TMP/initrd.mnt-$RANVAL4 && 
    307 echo "Copying initrd content in the image file" 
    308  
    309 umount $LFS_INITRD_TMP/initrd.mnt-$RANVAL4 && 
    310 echo "Unmount the image file" 
    311  
    312 gzip $LFS_INITRD_TMP/initrd.im-$RANVAL3 && 
    313 echo "Initrd image file gzipped" 
    314  
    315 mv $LFS_INITRD_TMP/initrd.im-$RANVAL3.gz $LFS_INITRD_NAME && 
    316 echo "Moving it as $LFS_INITRD_NAME" 
    317  
    318 echo "Cleaning up the mess in $LFS_INITRD_TMP" 
    319 rm -Rf $LFS_INITRD_TMP/initrd-$RANVAL2  
    320 rm -Rf $LFS_INITRD_TMP/initrd.im-$RANVAL3 
    321 rm -Rf $LFS_INITRD_TMP/initrd.mnt-$RANVAL4 
    322  
    323 echo "Initrd creation over" 
    324  
    325 exit 0 
    326 --------------------------- /usr/sbin/mk_initrd -------------------------------- 
    327  
    328 Now please make it executable with: 
    329  
    330 chmod 755 /usr/sbin/mk_initrd 
    331  
    332  
    333 6. Using mk_initrd 
     1134. Using mk_initrd 
    334114================== 
    335115 
     
    347127a more complicated (or safer) manner. 
    348128 
    349 7. A word on booting with grub 
     1295. A word on booting with grub 
    350130============================== 
    351131 
     
    361141add devfs=mount on the kernel line (or append line with lilo). 
    362142 
    363 8. Ideas to make it better 
     1436. Ideas to make it better 
    364144========================== 
    365145 
     
    367147the kernel, or use special boot option), you might want to use initrd in other 
    368148contexts, and it worth having more available commands; give BusyBox a try, you 
    369 can obtain a nice set of Unix commands in something like 200Ko (dynamically linked 
    370 against glibc). 
     149can obtain a nice set of Unix commands in something like 200Ko (dynamically  
     150linked against glibc, even less against ulibc or dietlibc). 
    371151 
    372 9. Thanks 
    373 ========= 
    374  
     152ACKNOWLEDGEMENTS: 
    375153I especially wish to thank Richard Lightman for his help and explanations on how 
    376154initrd now works, I'd certainly still be stuck with outdated docs without him :-) 
    377155 
    378  
    379 That's all, hope it'll work for you. 
     156CHANGELOG: 
     157[2002-10-26] 
     158        * initial release 
     159[2003-09-16] 
     160        * new hints format update 
     161        * English correctness updates 
     162[2003-09-18] 
     163        * making separate files for scripts