X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=linuxrc;h=441ef54adda2faa5ee6f10db87caa8830b56894b;hb=d1b7d5b4bc51036ee0b961855895d6e0604a0573;hp=85ae3efaa63c76d35f575dac839f41f35555e524;hpb=7af6acfccfb742d4e8e8b1de840ec1e192587e38;p=grml-terminalserver.git diff --git a/linuxrc b/linuxrc index 85ae3ef..441ef54 100755 --- a/linuxrc +++ b/linuxrc @@ -2,7 +2,7 @@ # Filename: /linuxrc # Purpose: minirt for kernel 2.6 running on grml live-cd # Authors: (c) Klaus Knopper , (c) Michael Prokop -# Latest change: Mon Sep 18 23:19:53 CEST 2006 [mika] +# Latest change: Sun Mar 04 13:47:33 CET 2007 ####################################################################################### # hardcoded configurable options @@ -216,6 +216,10 @@ GRML_NAME="GRML" case "$CMDLINE" in *grml_dir=*) GRML_DIR="$grml_dir"; ;; esac case "$CMDLINE" in *grml_name=*) GRML_NAME="$grml_name"; ;; esac +# NFS +for i in $cmdline; do case "$i" in nfsdir=*|NFSDIR=*) eval $i;; esac; done +[ -n "$nfsdir" ] && NFS="$nfsdir" + if [ -n "$DEBUG" ]; then log_begin_msg "Bootoption debug detected. Printing kernel command line:" echo "" @@ -269,7 +273,7 @@ askmodules(){ c="" for m in "$@"; do if test -f "/modules/scsi/$m"; then - test -z "$c" && { echo -n " $m"; c="1"; } || { echo " $m"; c=""; } + test -z "$c" && { echo -n " $m"; c="1"; } || { echo " $m"; c=""; } fi done [ -n "$c" ] && echo "" @@ -392,7 +396,7 @@ if test -z "$NOUSB"; then if test -f /modules/div/usbcore.ko; then $INSMOD /modules/div/usbcore.ko >/dev/null 2>&1 FOUNDUSB="" - for i in $USB2 uhci-hcd.ko ohci-hcd.ko ; do + for i in $USB2 uhci-hcd.ko ohci-hcd.ko usbhid.ko ; do test -f /modules/div/$i && $INSMOD /modules/div/$i >/dev/null 2>&1 && FOUNDUSB="yes" done if test -n "$FOUNDUSB"; then @@ -419,7 +423,7 @@ fi if test -z "$NOFIREWIRE" ; then log_begin_msg "Checking for Firewire." if test -f /modules/div/ieee1394.ko ; then - $insmoD /modules/div/ieee1394.ko > /dev/null 2>&1 + $INSMOD /modules/div/ieee1394.ko > /dev/null 2>&1 FOUNDFIREWIRE="" test -f /modules/div/ohci1394.ko && $INSMOD /modules/div/ohci1394.ko > /dev/null 2>&1 && FOUNDFIREWIRE="yes" if test -n "$FOUNDFIREWIRE" ; then @@ -508,25 +512,58 @@ esac stage=2 rundebugshell -# NFS -if checkbootparam "nfsdir" ; then - NFS="$(getbootparam nfsdir)" -# if test -z $NFS -# then -# NFS=192.168.0.1 -# echo "${CRE}${BLUE}No NFS-server given, assuming default $NFS${NORMAL}" -# fi - echo "${RED}Debug: NFS = ${NFS}${NORMAL}" - log_begin_msg "${CRE} ${GREEN}*${NORMAL} Looking for CD-ROM in: ${MAGENTA}$NFS${NORMAL}" - if mountit -t nfs $NFS "-o ro" >/dev/null 2>&1 +if [ -n "$NFS" ]; then + tmp_="$(getbootparam nfsdir)" + log_begin_msg "Bootoption NFS found." ; echo "$SUCCESS" + + cdir + + # FIXME modprobe is buggy from busybox + log_begin_msg "Trying to load network driver(s)." ; echo + modLoad() + { + for mod in $@ ; do + tmp_="`modprobe -vn $mod 2>/dev/null`" + if [ $? -ne 0 ]; then + continue + fi + echo "$tmp_" | while read i; do + # be quiet by default, be verbose only with bootoption debuglinuxrc + [ -n "$DEBUG" ] && eval "$i" || eval "$i" 1>/dev/null 2>/dev/null + done + done + } + # modules.alias and modules.dep are in place so USE IT :)! + modLoad "$(for x in $(find /sys/devices/ -name modalias); do grep pci: $x; done |xargs)" + + # loading additional modules + modLoad sunrpc lockd af_packet nfs + + dhcp_iface_=$(getbootparam dhcp_iface) + if [ -z "$dhcp_iface_" ]; then + dhcp_iface_=`ifconfig -a | grep '^eth' | sed 's/ .*//'` + fi + + for INTERFACE in $dhcp_iface_ ; do + log_begin_msg "Requesting network configuration using udhcp for ${INTERFACE}:" ; echo + /static/timeout 10 /static/udhcpc --interface="${INTERFACE}" --foreground --quit --script=/static/udhcp-config.sh + # echo "press to start a system shell and configure your system" + # sh + done + + # recreate dir layout + remove extra modules + rdir + #rm -rf /mylib + + log_begin_msg "Looking for GRML in: ${MAGENTA}$NFS${NORMAL}" ; echo "$SUCCESS" + if mount -t nfs "$NFS" -o "async,ro,nolock" /cdrom #>/dev/null 2>&1 then if test -f /cdrom/$GRML_DIR/$GRML_NAME then - log_begin_msg "Accessing grml CD-ROM at ${MAGENTA}${NFS}${NORMAL}" ; echo " $SUCCESS" + log_begin_msg "Accessing grml CDROM at ${MAGENTA}$NFS${NORMAL}" ; echo "$SUCCESS" FOUND_GRML="$NFS" break fi - umount /cdrom fi fi @@ -576,7 +613,7 @@ remount_grml() [ -n "$SOURCE2" ] && umount $SOURCE2 # umount possible loop-device mount_grml $TARGET else - echo "${CRE} ${RED}Warning: Changing to $TARGET failed.${NORMAL}" + log_failure_msg "Warning: Changing to $TARGET failed." return 1 fi @@ -613,7 +650,7 @@ boot_from() fi if [ $? -ne 0 ]; then [ -n "$LOOP_SOURCE" ] && /bin/umount $LOOP_SOURCE - echo -n "${CRE} ${RED}Accessing grml CD-ROM failed. ${MAGENTA}$TARGET_DEV${RED} is not mountable.${NORMAL}" + log_failure_msg "Accessing grml CD-ROM failed. ${MAGENTA}$TARGET_DEV${NORMAL} is not mountable." sleep 2 return 1 fi @@ -621,7 +658,7 @@ boot_from() if [ -f $TARGET/$GRML_DIR/$GRML_NAME ]; then log_begin_msg "Accessing grml CD-ROM at ${MAGENTA}$TARGET_DEV${NORMAL}." ; echo " $SUCCESS" else - echo -n "${CRE} ${RED}Accessing grml CD-ROM failed. Could not find $GRML_DIR/$GRML_NAME on ${MAGENTA}$TARGET_DEV${RED}.${NORMAL}" + log_failure_msg "Accessing grml CD-ROM failed. Could not find $GRML_DIR/$GRML_NAME on ${MAGENTA}$TARGET_DEV${RED}.${NORMAL}" [ -n "$LOOP_SOURCE" ] && /bin/umount $LOOP_SOURCE umount $TARGET sleep 2 @@ -664,7 +701,7 @@ copy_to() fi done if test -z "$MOUNTED"; then - echo -n "${CRE} ${RED}Copying grml CD-ROM failed. ${MAGENTA}$TARGET_DEV_DESC${RED} is not mountable.${NORMAL}" + log_failure_msg "Copying grml CD-ROM failed. ${MAGENTA}$TARGET_DEV_DESC${NORMAL} is not mountable." sleep 2 return 1 fi @@ -682,7 +719,7 @@ copy_to() if [ $FOUNDSPACE -lt $SIZE ] then - echo -n "${CRE} ${RED}Copying grml CD-ROM failed. Not enough free space on ${MAGENTA}${TARGET_DEV_DESC}${RED}. Found: ${MAGENTA}${FOUNDSPACE}k${RED} Need: ${MAGENTA}${SIZE}k${RED} ${NORMAL}" + log_failure_msg "Copying grml CD-ROM failed. Not enough free space on ${MAGENTA}${TARGET_DEV_DESC}${NORMAL}. Found: ${MAGENTA}${FOUNDSPACE}k${NORMAL} Need: ${MAGENTA}${SIZE}k${NORMAL}" sleep 2 umount $TARGET return 1 @@ -690,7 +727,8 @@ copy_to() # do the real copy - echo "${CRE} ${GREEN}Copying grml CD-ROM to ${MAGENTA}$TARGET_DEV_DESC${GREEN}... Please be patient. ${NORMAL}" + log_begin_msg "Copying grml CD-ROM to ${TARGET_DEV_DESC}... Please be patient." + echo if [ -z "$use_cp" -a -x /usr/bin/rsync ] then # first cp the small files @@ -699,17 +737,24 @@ copy_to() [ -f $TARGET/$GRML_DIR/$GRML_NAME ] && /bin/rm -f $TARGET/$GRML_DIR/$GRML_NAME /usr/bin/rsync -a --progress --include="$GRML_DIR/$GRML_NAME" --include="$GRML_DIR/" --exclude="*" $COPY $TARGET # Copy grml to $TARGET #/usr/bin/rsync -avP $COPY $TARGET # Copy grml to $TARGET + # make sure to support directories from http://grml.org/config/ + for dir in scripts bootparams config debs ; do + if [ -d "/cdrom/$dir" ] ; then + log_begin_msg "Customization directory $dir found, copying to $TARGET" + cp -a /cdrom/$dir $TARGET/ && echo "$SUCCESS" || echo "$FAILED" + fi + done else /bin/cp -a -f $COPY $TARGET # Copy grml to $TARGET fi if [ $? -ne 0 ] then - echo -n "${CRE} ${RED}Copying grml CD-ROM failed. ${MAGENTA}$TARGET_DEV_DESC${RED} possibly has not enough space left.${NORMAL}" + log_failure_msg "Copying grml CD-ROM failed. ${MAGENTA}$TARGET_DEV_DESC${NORMAL} possibly has not enough space left." sleep 2 return 1 fi # remount r/o - /bin/mount -n -o remount,ro $TARGET + /bin/mount -n -o remount,ro $TARGET 1>/dev/null 2>&1 remount_grml } @@ -737,16 +782,16 @@ if test -n "$DO_REMOUNT" -a -n "$FOUND_GRML" ; then # first copy_to, then boot_from if [ -n "$COPYTO" ]; then - copy_to $COPYTO && REAL_TARGET="$TARGET" + copy_to $COPYTO && REAL_TARGET="$TARGET" fi if [ -n "$BOOTFROM" ]; then - boot_from - if [ "$?" -eq "0" ]; then - # set new source / target paths - REAL_TARGET="$TARGET" - SOURCE2="$LOOP_SOURCE" - SOURCE="/cdrom2" - TARGET="/cdrom3" + boot_from + if [ "$?" -eq "0" ]; then + # set new source / target paths + REAL_TARGET="$TARGET" + SOURCE2="$LOOP_SOURCE" + SOURCE="/cdrom2" + TARGET="/cdrom3" fi fi fi @@ -758,11 +803,19 @@ then cat /GRML/etc/ld.so.cache > /etc/ld.so.cache UNIONFS="" -$INSMOD /modules/unionfs.ko 1>/dev/null -grep -q unionfs /proc/filesystems && UNIONFS=yes - -# Enable kernel messages -echo "6" > /proc/sys/kernel/printk +if checkbootparam "unionfs" ; then + $INSMOD /modules/unionfs.ko 1>/dev/null + grep -q unionfs /proc/filesystems && UNIONFS=yes + unionfs='unionfs' + UNIONFS_FILETYPE='unionfs' + AUFS='' +else + $INSMOD /modules/aufs.ko 1>/dev/null + grep -q aufs /proc/filesystems && UNIONFS=yes + unionfs='unionfs (using aufs)' + UNIONFS_FILETYPE='aufs' + AUFS='yes' +fi # Set paths log_begin_msg "Setting paths" @@ -781,10 +834,9 @@ export PATH # From here, we should have all essential commands available. hash -r -# Did we remount the source media ? -if test -n "$REAL_TARGET"; -then - /bin/mount -n --move $REAL_TARGET /cdrom # move it back and go on to normal boot +# Did we remount the source media? +if test -n "$REAL_TARGET"; then + /bin/mount -n --move $REAL_TARGET /cdrom # move it back and go on to normal boot fi # Clean up /etc/mtab (and - just in case - make a nice entry for looped ISO) @@ -801,7 +853,11 @@ FOUNDMEM="$(awk '/MemTotal/{print $2}' /proc/meminfo)" TOTALMEM="$(awk 'BEGIN{m=0};/MemFree|Cached/{m+=$2};END{print m}' /proc/meminfo)" # Be verbose -log_begin_msg "Total memory found: $FOUNDMEM kB" ; echo " $SUCCESS" +if [ -n "$FOUNDMEM" ] ; then + log_begin_msg "Total memory found: $FOUNDMEM kB" ; echo " $SUCCESS" +else + log_failure_msg "Could not fetch memory information." ; echo " $FAILED" +fi # Now we need to use a little intuition for finding a ramdisk size # that keeps us from running out of space, but still doesn't crash the @@ -812,9 +868,9 @@ MINSIZE=20000 # At least this much memory minus 30% should remain when home and var are full. MINLEFT=16000 # Maximum ramdisk size -MAXSIZE="$(expr $TOTALMEM - $MINLEFT)" +[ -n "$TOTALMEM" ] && MAXSIZE="$(expr $TOTALMEM - $MINLEFT)" # Default ramdisk size for ramdisk -RAMSIZE="$(expr $TOTALMEM / 5)" +[ -n "$TOTALMEM" ] && RAMSIZE="$(expr $TOTALMEM / 5)" # Create additional dynamic ramdisk. test -z "$RAMSIZE" -o "$RAMSIZE" -lt "$MINSIZE" && RAMSIZE="$MINSIZE" @@ -829,11 +885,19 @@ mkdir -p /ramdisk/tmp /ramdisk/home/grml && chmod 1777 /ramdisk/tmp && chown grm stage=3 rundebugshell # unionfs -log_begin_msg "Creating unionfs and symlinks on ramdisk" +log_begin_msg "Creating $unionfs and symlinks on ramdisk" mkdir -p /UNIONFS -if test -n "$UNIONFS" && /bin/mount -t unionfs -o noatime${SECURE},dirs=/ramdisk=rw:/GRML=ro /UNIONFS /UNIONFS; then +if test -n "$UNIONFS" && /bin/mount -t $UNIONFS_FILETYPE -o noatime${SECURE},dirs=/ramdisk=rw:/GRML=ro /UNIONFS /UNIONFS ; then # We now have unionfs, copy some data from the initial ramdisk first cp -a /etc/fstab /etc/auto.mnt /etc/filesystems /etc/mtab /UNIONFS/etc/ + + # disable resolvconf on the terminalserver client + if [ -n "$NFS" ] ; then + rm /UNIONFS/etc/resolv.conf + cp -a /etc/resolv.conf /UNIONFS/etc + echo REPORT_ABSENT_SYMLINK=no >> /UNIONFS/etc/default/resolvconf + fi + for i in bin boot etc sbin var lib opt root usr; do # Move directories to unionfs if test -d /$i; then mv /$i /$i.old && \ @@ -843,8 +907,7 @@ if test -n "$UNIONFS" && /bin/mount -t unionfs -o noatime${SECURE},dirs=/ramdisk ln -snf /UNIONFS/$i /$i fi done - #echo "${GREEN}done${NORMAL}" - echo " $SUCCESS" + [ -n "$AUFS" ] && echo " $SUCCESS" || echo " $SUCCESS" log_begin_msg "Merging read-only system with read-writeable /ramdisk." for i in $(cd /UNIONFS; echo *); do # Create links for new stuff on /UNIONFS test "$i" = "home" -o "$i" = "tmp" && continue @@ -854,8 +917,10 @@ else echo "" log_failure_msg "ERROR: CANNOT UNITE READ-ONLY MEDIA AND INITIAL RAMDISK!" echo "$FAILED" - NOUNIONFS="yes" - /GRML/sbin/halt -f -n + sleep 2 + echo "Can not continue booting, dropping you to a busybox shell." + stage=4 + rundebugshell fi chown grml.grml /home/grml @@ -904,7 +969,7 @@ rm -f /linuxrc exit 0 else - echo "${CRE}${RED}Can't find grml filesystem, sorry.${NORMAL}" + log_failure_msg "Error: Can't find grml filesystem, sorry." echo " Are you booting via USB or firewire? ====================================