Changeset 2068

Show
Ignore:
Timestamp:
09/22/07 08:26:07 (1 year ago)
Author:
alexander
Message:

Added code to handle the rootflafs option to initramfs.
Added nice warnings that catch common errors.
Added /sbin to the PATH of the debugging shell.
Added "ls" to the list of available programs.

Made sure that "generic" IDE drivers are loaded only if "all_generic_ide"
option is present, and only after chipset-specific drivers.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/packages/initramfs/Makefile

    r2029 r2068  
    2727        cp /etc/udev/rules.d/{05-*,2*,60-*} $(WDIR)/etc/udev/rules.d 
    2828        sed -i 's/, *GROUP="[^"]*"//' $(WDIR)/etc/udev/rules.d/* 
     29        echo "blacklist generic" >$(WDIR)/etc/modprobe.conf 
     30        echo "blacklist ata_generic" >>$(WDIR)/etc/modprobe.conf 
    2931        sed -e s/@VERSION@/$(VERSION)/ -e s/@LINKER@/$(LINKER)/ init.in >$(WDIR)/init 
    3032        chmod 755 $(WDIR)/init 
     
    3234        mknod -m 640 $(WDIR)/dev/console c 5 1 
    3335        mknod -m 664 $(WDIR)/dev/null c 1 3 
    34         cp /bin/{sh,dd,cat,cp,killall,mkdir,mount,umount,sed,sleep,ln,rm,uname} $(WDIR)/bin 
     36        cp /bin/{sh,dd,cat,cp,killall,ls,mkdir,mount,umount,sed,sleep,ln,rm,uname} $(WDIR)/bin 
     37        cp /lib/{librt.so.1,libpthread.so.0} $(WDIR)/lib 
    3538        cp /lib/{libblkid.so.1,libc.so.6,libdl.so.2,$(LINKER)} $(WDIR)/lib 
    3639        cp /lib/{libncursesw.so.5,libreadline.so.5,libhistory.so.5} $(WDIR)/lib 
  • trunk/packages/initramfs/init.in

    r2029 r2068  
    11#!/bin/sh 
     2 
     3PATH=/bin:/usr/bin:/sbin:/usr/sbin 
     4export PATH 
    25 
    36EXPECTED_LABEL="lfslivecd-@VERSION@" 
     
    1215rootfstype=auto 
    1316ro="ro" 
     17rootflags= 
    1418noresume=0 
    1519resume= 
     
    2933} 
    3034 
     35problem() { 
     36        cat <<"EOF" 
     37The problem may be caused by the fact that ISA IDE and SCSI adapters are 
     38no longer attempted to be autodetected. If you use such hardware, load the 
     39proper driver manually with the "modprobe" command and exit from this shell. 
     40For old IDE controllers, the correct module name is "ide-generic", or, if 
     41you want to use the new libata-based driver, "pata-legacy". To avoid this 
     42message next time you boot this CD, use a kernel command line like this: 
     43linux load=ide-generic 
     44 
     45This problem can be also caused by a slow SCSI controller or USB/FireWire 
     46CD-ROM that needs more time to be detected. If you see any kernel messages 
     47below, this is the case. In this case, it is sufficient to type "exit", 
     48and the CD will continue the boot process. To avoid this message next 
     49ime you boot this CD, use a kernel command line like this: 
     50linux rootdelay=20 
     51 
     52Dropping you to a shell. 
     53 
     54EOF 
     55        sh 
     56} 
     57 
    3158do_resume() { 
    3259        case "$resume" in 
     
    3764                if [ -b ${resume} ] ; then 
    3865                        eval echo $( stat -L -c '$(( 0x%t )):$(( 0x%T ))' ${resume} ) >/sys/power/resume 
     66                        # MC syntax highlighting is buggy ' 
    3967                else 
    40                         echo "Cannot resume from device $resume, which doesn't exist" 
     68                        cat <<EOF 
     69The specified resume device ${resume} doesn't exist. 
     70Please fix this problem and exit this shell. If you don't want to resume, 
     71type "exit". 
     72 
     73EOF 
     74                        problem 
     75                        # Retry 
     76                        if [ -b ${resume} ] ; then 
     77                                eval echo $( stat -L -c '$(( 0x%t )):$(( 0x%T ))' ${resume} ) >/sys/power/resume 
     78                                # MC syntax highlighting is buggy ' 
     79                        else 
     80                                cat <<EOF 
     81The specified resume device ${resume} still doesn't exist. 
     82Assuming that you don't want to resume. 
     83EOF 
     84                        fi 
    4185                fi 
    4286                ;; 
     
    81125                bs=1 count=1 skip=8 seek=47482 conv=notrunc 2>/dev/null 
    82126        umount -n /.tmpfs/.cdrom 
    83         /sbin/losetup /dev/loop2 /.tmpfs/.fakecd.iso 
     127        losetup /dev/loop2 /.tmpfs/.fakecd.iso 
    84128        if [ -d /.tmpfs/.partition ] ; then 
    85                 /sbin/losetup -d /dev/loop3 
     129                losetup -d /dev/loop3 
    86130                umount -n /.tmpfs/.partition && rm -rf /.tmpfs/.partition 
    87131        fi 
     
    103147} 
    104148 
     149 
    105150do_mount_cd() { 
    106         i=1 
    107         while [ ! -L /dev/lfs-cd ] ; do 
     151        while [ ! -b /dev/lfs-cd ] ; do 
    108152                find_cd 
    109153 
    110                 if [ ! -L /dev/lfs-cd ] ; then 
    111                         echo "LFS LiveCD not found." 
    112                         TRIES=5 
    113                         DELAY=6    # 30 seconds total 
    114  
    115                         for (( ; i<=$TRIES ; i++ )) ; do 
    116                                 [ -L /dev/lfs-cd ] && break 
    117  
    118                                 echo -n "Retry attempt $i of $TRIES... " 
    119                                 sleep $DELAY 
    120                                 find_cd 
    121  
    122                                 [ -L /dev/lfs-cd ] && echo "success!" || echo "failed!" 
    123                         done 
    124                 fi 
    125  
    126                 if [ ! -L /dev/lfs-cd ] ; then 
    127                         echo "" 
    128                         echo "LFS LiveCD could not find its device, perhaps due to" 
    129                         echo "unsupported or undetected hardware. Or maybe this is" 
    130                         echo "just a slow SCSI or USB controller that needs more time" 
    131                         echo "to settle (workaround: add rootdelay=30 to the kernel" 
    132                         echo "command line in the boot loader)." 
    133                         echo "" 
    134                         echo "Dropping you to a shell." 
    135                         echo "Please load the needed modules and, optionally, make" 
    136                         echo "/dev/lfs-cd a symlink pointing to the correct device." 
    137                         echo "" 
    138                         sh 
     154                if [ ! -b /dev/lfs-cd ] ; then 
     155                        cat <<"EOF" 
     156 
     157LFS LiveCD could not find its device, perhaps due to unsupported or 
     158undetected hardware. Please fix this problem and exit this shell. 
     159 
     160EOF 
     161                        problem 
    139162                fi 
    140163        done 
     
    143166        if [ "$toram" = 1 ] ; then copy_cd_to_ram ; fi 
    144167        mount -n -t iso9660 -o ro /dev/lfs-cd /.tmpfs/.cdrom 
    145         /sbin/losetup /dev/loop0 /.tmpfs/.cdrom/root.ext2 
    146         SIZE=`/sbin/blockdev --getsize /dev/loop0` 
     168        losetup /dev/loop0 /.tmpfs/.cdrom/root.ext2 
     169        SIZE=`blockdev --getsize /dev/loop0` 
    147170        OVERHEAD=$(( 0x1000 + $SIZE * 2 )) 
    148171        OVLSIZE=$(( $SIZE + ( $OVERHEAD + 511 ) / 512 )) 
    149172        dd if=/dev/null of=/.tmpfs/.overlay bs=512 seek=$OVLSIZE 2>/dev/null 
    150         /sbin/losetup /dev/loop1 /.tmpfs/.overlay 
    151         echo "0 $SIZE snapshot /dev/loop0 /dev/loop1 p 8" | /sbin/dmsetup create lfs-cd 
     173        losetup /dev/loop1 /.tmpfs/.overlay 
     174        echo "0 $SIZE snapshot /dev/loop0 /dev/loop1 p 8" | dmsetup create lfs-cd 
    152175        mount -n -t ext2 /dev/mapper/lfs-cd /.root 
    153176        mount -n --move /.tmpfs /.root/dev/shm 
     
    166189                rm -f /.root/etc/udev/rules.d/76-network.rules 
    167190        fi 
     191        ( IFS="," ; for module in $load ; do 
     192                echo "$module" >>/.root/etc/sysconfig/modules 
     193        done ) 
     194 
    168195} 
    169196 
     
    173200        DEVICE=${DEVICE%%:*} 
    174201        mkdir /.tmpfs/.partition 
    175         mount -n -t "$rootfstype" -o "$rootflags" "$DEVICE" /.tmpfs/.partition 
    176         /sbin/losetup /dev/loop3 "/.tmpfs/.partition/$FILE" 
     202        while [ ! -b "$DEVICE" ] ; do 
     203                cat <<EOF 
     204 
     205The device ${DEVICE}, which is supposed to contain a file 
     206with the ISO9660 image of the LFS LiveCD, does not exist. 
     207Please fix this problem and exit this shell. 
     208 
     209EOF 
     210                problem 
     211        done 
     212        if ! mount -n -t "$rootfstype" -o "$rootflags" "$DEVICE" /.tmpfs/.partition ; then 
     213                cat <<EOF 
     214 
     215Could not mount device ${DEVICE} 
     216(but it does exist, please mention this when asking for support). 
     217Sleeping forever. Please reboot and fix the kernel command line. 
     218 
     219Maybe you have put the ISO9660 image of the LiveCD onto a partition 
     220formatted with an unsupported file system? 
     221 
     222Or maybe filesystem type autodetection went wrong, in which case 
     223you should add rootfstype=... to the kernel command line. 
     224 
     225Available partitions: 
     226EOF 
     227                cat /proc/partitions 
     228                while true ; do sleep 10000 ; done 
     229        fi 
     230        if [ ! -f "/.tmpfs/.partition/$FILE" ] ; then 
     231                cat <<EOF 
     232 
     233The file ${FILE} does not exist on the device ${DEVICE}. 
     234Sleeping forever. Please reboot and fix the kernel command line. 
     235 
     236Maybe you have specified a wrong device or file name? Does the following 
     237list of files on the partition look right? 
     238EOF 
     239                ( cd /.tmpfs/.partition ; ls ) 
     240                umount -n /.tmpfs/.partition 
     241                while true ; do sleep 10000 ; done 
     242        fi 
     243        losetup /dev/loop3 "/.tmpfs/.partition/$FILE" 
    177244        ln -sf /dev/loop3 /dev/lfs-cd 
    178245        do_mount_cd 
     
    189256                do_mount_iso 
    190257                ;; 
     258        /dev/*) 
     259                while [ ! -b "$root" ] ; do 
     260                        cat <<EOF 
     261The device ${root}, which is supposed to contain the 
     262root file system, does not exist. 
     263Please fix this problem and exit this shell. 
     264 
     265EOF 
     266                        problem  
     267                done 
     268                if ! mount -n -t "$rootfstype" -o "$rootflags" "$root" /.root ; then 
     269                        cat <<EOF 
     270 
     271Could not mount device ${root} 
     272Sleeping forever. Please reboot and fix the kernel command line. 
     273 
     274Maybe the device is formatted with an unsupported file system? 
     275 
     276Or maybe filesystem type autodetection went wrong, in which case 
     277you should add the rootfstype=... parameter to the kernel command line. 
     278 
     279Available partitions: 
     280EOF 
     281                        cat /proc/partitions 
     282                        while true ; do sleep 10000 ; done 
     283                fi 
     284                ;; 
    191285        *:*) 
    192286                ( IFS=":" ; mknod /dev/root b $root ) 
    193                 mount -n -t "$rootfstype" -o "$rootflags" /dev/root /.root 
    194                 ;; 
    195         /dev/*) 
    196                 mount -n -t "$rootfstype" -o "$rootflags" "$root" /.root 
     287                if ! mount -n -t "$rootfstype" -o "$rootflags" /dev/root /.root ; then 
     288                        cat <<EOF 
     289 
     290Could not mount device $root 
     291Sleeping forever. Please reboot and fix the kernel command line. 
     292 
     293Maybe the device is formatted with an unsupported file system? 
     294 
     295Or maybe filesystem type autodetection went wrong, in which case 
     296you should add the rootfstype=... parameter to the kernel command line. 
     297 
     298Available partitions: 
     299EOF 
     300                        cat /proc/partitions 
     301                        while true ; do sleep 10000 ; done 
     302                fi 
    197303                ;; 
    198304        "") 
     
    243349        rootfstype=*) 
    244350                rootfstype=${param#rootfstype=} 
     351                ;; 
     352        rootflags=*) 
     353                rootflags=${param#rootflags=} 
    245354                ;; 
    246355        ro) 
     
    279388                done 
    280389                echo "install ata_piix /sbin/modprobe piix ; /sbin/modprobe -i ata_piix" >>/etc/modprobe.conf 
    281                 echo "blacklist ata_generic" >>/etc/modprobe.conf 
    282390                ;; 
    283391        1) 
     
    311419        echo "options generic all_generic_ide=1" >>/etc/modprobe.conf 
    312420        echo "options ata-generic all_generic_ide=1" >>/etc/modprobe.conf 
    313 else 
     421fi 
     422 
     423udevd --daemon 
     424 
     425( IFS="," ; for module in $load ; do 
     426        modprobe "$module" 
     427done ) 
     428 
     429udevtrigger 
     430udevsettle 
     431if [ "$all_generic_ide" = 1 ] ; then 
    314432        if [ "$PATA" = 0 ] ; then 
    315                 echo "blacklist generic" >>/etc/modprobe.conf 
     433                modprobe generic 
    316434        else 
    317                 echo "blacklist ata-generic" >>/etc/modprobe.conf 
    318         fi 
     435                modprobe ata_generic 
     436        fi 
     437        udevsettle 
    319438fi 
    320439 
    321 /sbin/udevd --daemon 
    322  
    323 ( IFS="," ; for module in $load ; do 
    324         /sbin/modprobe "$module" 
    325 done ) 
    326  
    327 /sbin/udevtrigger 
    328 /sbin/udevsettle 
    329440if [ -n "$rootdelay" ] ; then sleep "$rootdelay" ; fi 
    330441