|
From: Friedrich L. <fr...@us...> - 2006-05-30 23:12:42
|
Update of /cvsroot/devil-linux/build/config/etc/initrd In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv20637/config/etc/initrd Modified Files: Tag: rel-1-2-patches mount_cdrom Log Message: added initial support for RUNFROMRAM Index: mount_cdrom =================================================================== RCS file: /cvsroot/devil-linux/build/config/etc/initrd/mount_cdrom,v retrieving revision 1.25.2.16 retrieving revision 1.25.2.17 diff -u -d -r1.25.2.16 -r1.25.2.17 --- mount_cdrom 30 May 2006 22:53:14 -0000 1.25.2.16 +++ mount_cdrom 30 May 2006 23:12:37 -0000 1.25.2.17 @@ -29,6 +29,181 @@ 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 () { + + 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 + echo "run_from_ram: neither --cdrom nor --file option were given" + return 0 + fi + + if [ "${IS_FILE}" ]; then + $YELLOW; + echo "NOTE: Currently we only support Run-from-RAM with a CDROM as media" + echo " support is planned for a later release" + $NORMAL; + return 0 + fi + + # check if we already have a config loaded + if [ -e "/etc/Devil-release" ]; then + # load main config file + . /etc/sysconfig/config + else + # nothing I can do about it, no config no variable RUNFROMRAM + return 0 + fi + + # check if we should run from ram or not + if [ -z "${RUNFROMRAM}" -o "${RUNFROMRAM}" != "yes" ]; then + # user does not want to + return 0 + fi + + local RAMDISK=/shm/sys + local ISOFILE=bootcd.iso + + # load system into ram + $YELLOW + echo 'System is configured to run from ram' + $NORMAL + + local IMAGE_SIZE=$(df ${mountpoint} | grep "${mountpoint}" | awk '{print $(NF-4)}') + let IMAGE_SIZE_MB=IMAGE_SIZE*10/1024+5 # do correct rounding + let IMAGE_SIZE_MB=IMAGE_SIZE_MB/10 + let RAMDISK_SIZE=IMAGE_SIZE_MB+5 # add some megs as a safety margin + + # create a ramdisk for the system ISO image + mkdir -p ${RAMDISK} + mount -n -t shm -o size=${RAMDISK_SIZE}m shmfs ${RAMDISK} + + # don't keep it mounted while copying + umount ${mountpoint} + + echo -n "Copying system image (${IMAGE_SIZE_MB} MB) to ramdisk..." + busy_start + # it's a CDROM drive therefore we use a blocksize of 2k + dd if=$disk of=${RAMDISK}/${ISOFILE} bs=2048 >/dev/null 2>&1 + busy_stop + echo done. + + # revert back to standard mount + run_from_ram_cleanup () { + $YELLOW; echo "Falling back to standard mount..."; $NORMAL + sleep 10 + umount ${mountpoint} > /dev/null 2>&1 + umount ${RAMDISK} > /dev/null 2>&1 + mount -n -t iso9660 -o ro $disk ${mountpoint} + } + + 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 + + local REAL_SIZE=$(du ${RAMDISK}/${ISOFILE} | awk '{print $1}') + let REAL_SIZE=REAL_SIZE*10/1024+5 # do correct rounding + let REAL_SIZE=REAL_SIZE/10 + + if [ "${REAL_SIZE}" -lt "${IMAGE_SIZE_MB}" ]; then + $RED; + echo "FATAL-ERROR: copying failed - ${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 + + # mount read-only again + mount -n -o remount,ro ${RAMDISK} + # loop mount final ISO image from ramdisk + 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 + + # finally done + $GREEN; echo 'System is now fully running from RAM'; $NORMAL +} if [ ! $silent ]; then $GREEN @@ -63,6 +238,10 @@ $NORMAL fi echo $disk > /shm/DL_DEVICE + + # run from ram if correct variable is set + run_from_ram --cdrom + exit 0 else $YELLOW @@ -142,6 +321,10 @@ $NORMAL fi if [ -e /mnt/bootcd.iso ] ; then + + # run from ram if correct variable is set + run_from_ram --file + # 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 |