|
From: Björn R. <br...@us...> - 2007-07-24 08:04:53
|
Update of /cvsroot/devil-linux/build/config/etc/initrd In directory sc8-pr-cvs12.sourceforge.net:/tmp/cvs-serv20943 Modified Files: linuxrc mount_cdrom Log Message: build/config/etc/initrd/mount_cdrom Index: linuxrc =================================================================== RCS file: /cvsroot/devil-linux/build/config/etc/initrd/linuxrc,v retrieving revision 1.94 retrieving revision 1.95 diff -u -d -r1.94 -r1.95 --- linuxrc 6 Jul 2007 04:04:39 -0000 1.94 +++ linuxrc 24 Jul 2007 08:04:46 -0000 1.95 @@ -179,6 +179,7 @@ # give klogd some time to start sleep 1 + # mount proc mount -n -t proc proc /proc @@ -257,7 +258,7 @@ if ask_yes_no ; then /probe_all_scsi_modules fi - if ! /mount_cdrom /cdrom noreboot ; then + if ! /mount_cdrom /cdrom -noreboot ; then $RED echo -e "Cannot find CD drive - try probing for SCSI controllers" $NORMAL @@ -321,6 +322,22 @@ /mount_cdrom /cdrom fi tar -C /shm -xjf /cdrom/config/etc.tar.bz2 + # + # we unmount here to be able to possibly activate run from ram + # if that's activated by the default config + # (bug reported by Dmitry Komarov) + sync + let i=0 + while (! umount /cdrom 2>/dev/null) && [ $i -lt 10 ]; do + # at least in qemu there exists a race condition + # when unmounting the cdrom + let i=i+1 + sleep 1 + done + # + # FIXME - need to solve this in a nicer way as we search for + # the cd/image twice which is quite ugly (fl) + # else tar -C /shm -xjf /floppy/$DL_CONFIG_FILE fi @@ -397,15 +414,19 @@ mount -n --move /shm /cdrom/shm #umount /shm +echo -n "Unmounting " + # unmount proc because the final system will mount it again +$GREEN; echo " proc"; $NORMAL umount /proc # start the system by swapping /dev/ram0 and /shm -echo 'Starting up final system...' +echo "Starting up final system..." cd /cdrom #change to new root and start up the real system pivot_root . initrd +cd / # see "man 2 pivot_root" exec /usr/sbin/chroot . /sbin/pre_init $DL_CONFIG_SOURCE $DL_CONFIG_FILE $@ <shm/dev/console >shm/dev/console 2>&1 # something went wrong Index: mount_cdrom =================================================================== RCS file: /cvsroot/devil-linux/build/config/etc/initrd/mount_cdrom,v retrieving revision 1.40 retrieving revision 1.41 diff -u -d -r1.40 -r1.41 --- mount_cdrom 23 Jul 2007 13:48:54 -0000 1.40 +++ mount_cdrom 24 Jul 2007 08:04:47 -0000 1.41 @@ -7,14 +7,239 @@ # # http://www.devil-linux.org # +#------------------------------------ +# usage: mount_cdrom [-silent] [-noreboot] mountpoint +# -silent reduce output to minimum +# -noreboot return error instead of halting on error +# # include our color definitions . colordefs -if [ "$3" != "silent" ]; then - $GREEN - echo "Searching for Devil-Linux CD-ROM" - $NORMAL +# parse command line options +mountpoint="" # where the cdrom/iso gets mounted +silent="" # empty = notsilent +noreboot="" # empty = reboot on error +while [ $# -gt 0 ]; do + case "$1" in + -silent ) silent=1;; + -noreboot ) noreboot=1;; + * ) [ -z "$mountpoint" ] && mountpoint="$1";; + esac + shift +done + +DELAY=200000 # usec +busy () { + # busy - print rotating busy indicator + # inspired by http://www.shelldorado.com/newsletter/issues/2001-1-Jan.html + # but this version works with plain sh + # (C) 2006 Friedrich Lobenstock <fl...@fl...> + # + # usage: + # busy& busypid=$! + # command_which_takes_a_long_time + # kill $busypid >/dev/null 2>&1 + + # define the characters which make up the rotating busy sign + local Indicator_1="|" + local Indicator_2="/" + local Indicator_3="-" + local Indicator_4="\\" + local n=4 # n characters represent one rotation + + local PRINTED=0 # did we print a character or not + + trap cleanup 1 2 3 6 15 + + cleanup () { + [ $PRINTED = 1 ] && echo -ne "\\b \\b" # cleanup in case + exit 0 + } + + local i=1 + while true; do + eval Indicator=\$Indicator_$i + echo -n "$Indicator" && PRINTED=1 + let i++ && [ $i = $n ] && i=1 + usleep ${DELAY} + echo -ne "\\b" && PRINTED=0 + done +} + +# helper function to start the busy indicator +busy_start () { + busy& busypid=$! +} + +# helper function to stop the busy indicator +busy_stop () { + kill $busypid >/dev/null 2>&1; usleep ${DELAY} +} + +run_from_ram () { + # + # usage: run_from_ram [--cdrom|--file] + # + # parameters: + # --cdrom try to load a cdrom to ram + # --file try to load an iso image file to ram + # + # returns: + # 0 systems is running from ram + # 1 either not configured to run from ram + # or there was an error, but we can still + # boot the standard way + # + + local IS_CDROM=""; local IS_FILE=""; local MEDIATYPE="" + while [ $# -gt 0 ]; do + case "$1" in + --cdrom ) IS_CDROM="yes"; MEDIATYPE="CDROM" + IS_FILE="" + ;; + --file ) IS_FILE="yes"; MEDIATYPE="FILE" + IS_CDROM="" + ;; + esac + shift + done + # we need either --cdrom or --file to be set + if ! [ "${IS_CDROM}" -o "${IS_FILE}" ]; then + $RED + echo "ERROR: run_from_ram was called with neither the --cdrom nor the --file option" + echo + echo 'Please report to bu...@de...' + echo + $NORMAL + sleep 10 + return 1 + fi + + # check if we already have a config loaded + if [ -e "/etc/Devil-release" -a "/etc/sysconfig/config" ]; then + # load main config file + . /etc/sysconfig/config + else + # nothing I can do about it, no config, no variable RUNFROMRAM + return 1 + fi + + # check if we should run from ram or not + [ -z "${RUNFROMRAM}" -o "${RUNFROMRAM}" != "yes" ] && return 1 + + ## FIXME + # we should probably define these somewhere more central + local RAMDISK=/shm/sys # this has to be under /shm as this one is mount moved in linuxrc + local FILEMOUNT=/cd + local ISOFILE=bootcd.iso + + # show that we are configured to run from ram + $YELLOW; echo 'System is configured to run from ram'; $NORMAL + + local IMAGE_SIZE; local IMAGE_SIZE_MB; local RAMDISK_SIZE + # get size of image so we can estimate the needed ramdisk space + case ${MEDIATYPE} in + CDROM ) IMAGE_SIZE=$(df ${mountpoint} | grep "${mountpoint}" | awk '{print $(NF-4)}');; + FILE ) IMAGE_SIZE=$(du -k ${FILEMOUNT}/${ISOFILE} | awk '{print $1}');; + esac + let IMAGE_SIZE_MB=IMAGE_SIZE*10/1024+5 # do correct rounding + let IMAGE_SIZE_MB=IMAGE_SIZE_MB/10 + # add some megs as a safety margin (also needed for safety check below) + let RAMDISK_SIZE=IMAGE_SIZE_MB+5 + + # create a ramdisk for the system ISO image + mkdir -p ${RAMDISK} + /sbin/mount -n -t tmpfs -o size=${RAMDISK_SIZE}m shmfs ${RAMDISK} + + echo -n "Copying system image (${IMAGE_SIZE_MB} MB) to ramdisk..." + busy_start + case ${MEDIATYPE} in + CDROM ) # don't keep it mounted while copying + /sbin/umount -n ${mountpoint} + # it's a CDROM drive therefore we use a blocksize of 2k + dd if=$disk of=${RAMDISK}/${ISOFILE} bs=2048 >/dev/null 2>&1 + ;; + FILE ) # it's a file so copy will do + cp ${FILEMOUNT}/${ISOFILE} ${RAMDISK}/${ISOFILE} >/dev/null 2>&1 + ;; + esac + busy_stop + echo done. + + # in case of an error we need to clean up + run_from_ram_cleanup () { + $YELLOW; echo "Falling back to standard mount..."; $NORMAL + sleep 10 + /sbin/umount -n ${mountpoint} > /dev/null 2>&1 + /sbin/umount -n ${RAMDISK} > /dev/null 2>&1 + # revert back to standard mount if needed + [ ${IS_CDROM} ] && /sbin/mount -n -t iso9660 -o ro $disk ${mountpoint} + } + + # check if ramdisk is full, then this is an indication that the image was to big during + # copying - this should never happen, but better save than sorry + if [ "$(df ${RAMDISK} | grep "${RAMDISK}" | awk '{print $(NF-2)}')" -eq 0 ]; then + $RED; + echo "ERROR: ramdisk size calculation error" + echo " the image to copy was bigger than expected" + echo + echo 'Please report to bu...@de...' + echo + $NORMAL + run_from_ram_cleanup + return 1 + fi + + # get size of the copied image + local REAL_SIZE=$(du -k ${RAMDISK}/${ISOFILE} | awk '{print $1}') + let REAL_SIZE=REAL_SIZE*10/1024+5 # do correct rounding + let REAL_SIZE=REAL_SIZE/10 + + # check if we at least match the image size estimated before + if [ ${REAL_SIZE} -lt ${IMAGE_SIZE_MB} ]; then + $RED; + echo "FATAL-ERROR: copying failed - only ${REAL_SIZE} MB out of ${IMAGE_SIZE_MB} MB copied" + echo ' a possible source of this problem could be:' + echo ' * read errors - media defective?' + echo ' * out of RAM - need to install more RAM?' + echo + $NORMAL + run_from_ram_cleanup + return 1 + fi + + # recalculate the needed ramdisk size + RAMDISK_SIZE=$(df -k ${RAMDISK} | grep "${RAMDISK}" | awk '{print $(NF-3)}') + + # mount ramdisk read-only and reduce to minimal size + /sbin/mount -n -o remount,ro,size=${RAMDISK_SIZE}k shmfs ${RAMDISK} + + # loop mount final ISO image from ramdisk + /sbin/mount -n -t iso9660 -o loop,ro ${RAMDISK}/${ISOFILE} ${mountpoint} + if [ $? -ne 0 ]; then + $RED; + echo "FATAL-ERROR: mounting the copied image failed" + echo + echo 'Please report to bu...@de...' + echo + $NORMAL + run_from_ram_cleanup + return 1 + fi + + # no need to keep the original location mounted + [ ${IS_FILE} ] && /sbin/umount -n ${FILEMOUNT} + + # finally done + $GREEN; echo 'System is now fully running from RAM'; $NORMAL + return 0 +} + +if [ ! $silent ]; then + $GREEN + echo "Searching for Devil-Linux CD-ROM" + $NORMAL fi # generate list of cdroms from devfs @@ -31,8 +256,8 @@ $NORMAL CDROMS=$DEVICE_USER fi - -if [ "$3" != "silent" ]; then + +if [ ! $silent ]; then $GREEN echo "Search list: $CDROMS" $NORMAL @@ -41,20 +266,24 @@ for disk in $CDROMS do echo -n "checking $disk " - if /sbin/mount -n -t iso9660 -o ro $disk $1 2> /dev/null; then - if [ -e $1/DEVIL-LINUX ] ; then - if [ "$3" != "silent" ]; then + if /sbin/mount -n -t iso9660 -o ro $disk ${mountpoint} 2> /dev/null; then + if [ -e ${mountpoint}/DEVIL-LINUX ] ; then + if [ ! $silent ]; then $YELLOW echo -e "Found on $disk" $NORMAL fi echo $disk > /shm/DL_DEVICE + + # run from ram if correct variable is set + run_from_ram --cdrom + exit 0 else $YELLOW echo "wrong media" $NORMAL - umount $1 + /sbin/umount ${mountpoint} fi else $RED @@ -77,7 +306,7 @@ for disk in $DISCS do - echo -n "checking $disk " + echo -n " checking $disk ... " if /sbin/mount -n -t auto -o rw,noatime $disk /cd 2> /dev/null; then if [ -e /cd/DEVIL-LINUX ] ; then $GREEN @@ -104,7 +333,7 @@ echo "Upgrading System Boot Files" $NORMAL - /sbin/mount -o loop -t iso9660 /cd/bootcd.iso /cdrom + /sbin/mount -o loop=/dev/loop0 -t iso9660 /cd/bootcd.iso /cdrom cp -fp /cdrom/boot/* /cd/boot/ 2> /dev/null cp -fp /cdrom/DEVIL-LINUX /cd/ @@ -113,12 +342,12 @@ chmod -R u+rw,g-rwx,o-rwx /cd/* sync - umount /cdrom &> /dev/null + /sbin/umount /cdrom &> /dev/null $GREEN echo "Mounting old version" $NORMAL - /sbin/mount -o loop -t iso9660 /cd/bootcd.iso.old $1 || return 1 + /sbin/mount -o loop=/dev/loop0 -t iso9660 /cd/bootcd.iso.old ${mountpoint} || return 1 echo $disk > /shm/DL_DEVICE dl_version=`cat /cd/DEVIL-LINUX 2> /dev/null` exit 0 @@ -130,19 +359,23 @@ $NORMAL fi if [ -e /cd/bootcd.iso ] ; then - # since this could be flash disk, lets make read-only. - # Should not write to this mount anymore anyway. It - # is attempted to umount it in pre_init but will fail - # because bootcd.iso is still mounted inside it. - # RO will make it less painfull. - /sbin/mount -o remount,ro,noatime $disk 2> /dev/null - /sbin/mount -o loop -t iso9660 /cd/bootcd.iso $1 || return 1 echo $disk > /shm/DL_DEVICE - dl_version=`cat /cd/DEVIL-LINUX 2> /dev/null` - if [ "$3" != "silent" ]; then - $YELLOW - echo -e "\nFound ISO ($dl_version) on $disk" - $NORMAL + + # run from ram if correct variable is set + if ! run_from_ram --file; then + # since this could be flash disk, lets make read-only. + # Should not write to this mount anymore anyway. It + # is attempted to umount it in pre_init but will fail + # because bootcd.iso is still mounted inside it. + # RO will make it less painfull. + /sbin/mount -o remount,ro,noatime $disk 2> /dev/null + /sbin/mount -o loop=/dev/loop0 -t iso9660 /cd/bootcd.iso ${mountpoint} || return 1 + dl_version=`cat /cd/DEVIL-LINUX 2> /dev/null` + if [ ! $silent ]; then + $YELLOW + echo -e "\nFound ISO ($dl_version) on $disk" + $NORMAL + fi fi exit 0 fi @@ -150,7 +383,7 @@ $YELLOW echo "wrong media" $NORMAL - umount /cd + /sbin/umount /cd fi else $RED @@ -160,13 +393,13 @@ done -if [ "$3" != "silent" ]; then +if [ ! $silent ]; then $RED echo "!!! Devil-Linux CD-ROM not found !!!" $NORMAL fi -[ "$2" = "noreboot" ] && exit 1 +[ $noreboot ] && exit 1 $RED echo |