# Filename: /linuxrc
# Purpose: minirt for kernel 2.6 running on grml live-cd
# Authors: (c) Klaus Knopper <knoppix@knopper.net>, (c) Michael Prokop <mika@grml.org>
-<<<<<<< /home/mika/grml/hg/grml-terminalserver/linuxrc
-# Latest change: Don Nov 16 14:46:00 CET 2006 [mika]
-=======
-# Latest change: Mon Sep 18 23:19:53 CEST 2006 [mika]
->>>>>>> /tmp/linuxrc~other.LuZLNY
+# Latest change: Fre Mär 16 15:55:37 CET 2007 [mika]
#######################################################################################
# hardcoded configurable options
echo "${WHITE}grml.org - Linux for users of texttools and sysadmins."
echo "${NORMAL}"
-# We only need the builtin commands and /static at this point
+# We need the builtin commands and /static only starting at this point
PATH=/static
export PATH
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 ""
# Ask user for modules
askmodules(){
-<<<<<<< /home/mika/grml/hg/grml-terminalserver/linuxrc
TYPE="$1"; shift
echo "${TYPE} modules available:${WHITE}"
c=""
echo -n "insmod module(s)> "
read MODULES
case "$MODULES" in n|N) MODULES=""; ;; y|"") MODULES="$*"; ;; esac
-=======
- TYPE="$1"; shift
- echo "${TYPE} modules available:${WHITE}"
- c=""
- for m in "$@"; do
- if test -f "/modules/scsi/$m"; then
- test -z "$c" && { echo -n " $m"; c="1"; } || { echo " $m"; c=""; }
- fi
- done
- [ -n "$c" ] && echo ""
- echo "Load ${TYPE} Modules?"
- echo "[Enter full filename(s) (space-separated), Return for autoprobe, n for none] "
- echo -n "insmod module(s)> "
- read MODULES
- case "$MODULES" in n|N) MODULES=""; ;; y|"") MODULES="$*"; ;; esac
->>>>>>> /tmp/linuxrc~other.LuZLNY
}
# Try to load the given modules (full path or current directory)
echo ""
for i in "$@"; do
echo -n " Probing ${TYPE}... ${WHITE}$i${NORMAL}: "
- if test -f /modules/scsi/$i.ko && $INSMOD -f /modules/scsi/$i.ko >/dev/null 2>&1 && echo " $SUCCESS" || echo " failed " ; then
+ if test -f /modules/scsi/$i.ko && $INSMOD /modules/scsi/$i.ko >/dev/null 2>&1 && echo " $SUCCESS" || echo " failed " ; then
case "$TYPE" in scsi|SCSI) FOUND_SCSI="yes"; ;; esac
fi
done
if test -z "$NOSCSI" ; then
log_begin_msg "Scanning for SCSI devices."
- $INSMOD -f /modules/scsi/firmware_class.ko 1>/dev/null
+ $INSMOD /modules/scsi/firmware_class.ko 1>/dev/null
test -n "$MODULES" && loadmodules SCSI $MODULES && echo -n "" || echo " ${BLUE}[${NORMAL} none found ${BLUE}]${NORMAL} (try bootoption scsi=probe)"
else
log_warn_msg "Not scanning for SCSI devices as requested on commandline." && echo " $SUCCESS"
if test "$MODULE" = "probe" ; then
log_begin_msg "Bootoption scsi=probe found. Trying to autoprobe SCSI modules:"
echo ""
- echo -n " Trying to load scsi_debug: " ; $INSMOD -f /modules/scsi/scsi_debug.ko 1>/dev/null && echo " $SUCCESS" || echo " [ failed ]"
+ echo -n " Trying to load scsi_debug: " ; $INSMOD /modules/scsi/scsi_debug.ko 1>/dev/null && echo " $SUCCESS" || echo " [ failed ]"
for module in /modules/scsi/*.ko ; do
echo -n " Probing ${WHITE}${module}${NORMAL}..."
- $INSMOD -f ${module} >/dev/null 2>&1 && echo " $SUCCESS" || echo " [ failed ]"
+ $INSMOD ${module} >/dev/null 2>&1 && echo " $SUCCESS" || echo " [ failed ]"
done
elif test "$MODULE" = "ask" ; then
askmodules SCSI $(cd /modules/scsi; echo *.ko)
else
[ -n "$MODULE" ] || echo " ${RED}Neither a specific module nor option probe nor option ask for SCSI module given. Skipping.${NORMAL}"
[ -n "$MODULE" ] && echo -n " Trying to load module ${WHITE}${MODULE}${NORMAL}:" ; \
- $INSMOD -f "/modules/scsi/${MODULE}.ko" 1>/dev/null && echo " $SUCCESS" || echo " [ failed ]"
+ $INSMOD "/modules/scsi/${MODULE}.ko" 1>/dev/null && echo " $SUCCESS" || echo " [ failed ]"
fi
fi
# End of SCSI check
echo ""
for module in mptbase mptscsih mptspi BusLogic ; do
echo -n " Trying to load ${WHITE}${module}${NORMAL}: "
- $INSMOD -f /modules/scsi/${module}.ko >/dev/null 2>&1 && echo " $SUCCESS" || echo " [ failed ]"
+ $INSMOD /modules/scsi/${module}.ko >/dev/null 2>&1 && echo " $SUCCESS" || echo " [ failed ]"
done
fi
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
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
# boot via pcmcia
if checkbootparam bootpcmcia ; then
log_begin_msg "Bootoption bootpcmcia found. Trying to load ${WHITE}PCMCIA${NORMAL} modules..."
- if $INSMOD -f /modules/div/pcmcia_core.ko 1>/dev/null ; then
- $INSMOD -f /modules/div/firmware_class.ko 1>/dev/null && \
- $INSMOD -f /modules/div/pcmcia.ko 1>/dev/null && \
- $INSMOD -f /modules/div/rsrc_nonstatic.ko 1>/dev/null && \
- $INSMOD -f /modules/div/yenta_socket.ko 1>/dev/null && echo " $SUCCESS"
+ if $INSMOD /modules/div/pcmcia_core.ko 1>/dev/null ; then
+ $INSMOD /modules/div/firmware_class.ko 1>/dev/null && \
+ $INSMOD /modules/div/pcmcia.ko 1>/dev/null && \
+ $INSMOD /modules/div/rsrc_nonstatic.ko 1>/dev/null && \
+ $INSMOD /modules/div/yenta_socket.ko 1>/dev/null && echo " $SUCCESS"
else
echo " [ failed ]"
fi
stage=2
rundebugshell
-# NFS
-<<<<<<< /home/mika/grml/hg/grml-terminalserver/linuxrc
if [ -n "$NFS" ]; then
tmp_="$(getbootparam nfsdir)"
- echo -n "checkbootparam nfsdir "
- checkbootparam "nfsdir" && echo "OK" || echo "FAILED"
- echo "getbootparam nfsdir=\"$tmp_\""
-
- # put the mylibs into /lib for discover and udhcpc
- cdir
+ log_begin_msg "Bootoption NFS found." ; echo "$SUCCESS"
- # starting hw-detection for network card
- echo "Starting hw-detection"
- kernel_version_=`uname -r`
- modules_to_load=$(/static/discover --disable-bus all --enable-bus pci --type network --normalize-whitespace --data-path=linux/module/name --data-version=$kernel_version_ | grep -v '^ $' | uniq)
- echo "trying to load the following network modules: \"$modules_to_load\""
+ /static/cdir
- # FIXME modprobe is buggy from busybox
- modules_to_load=`echo $modules_to_load | xargs`
+ log_begin_msg "Trying to load network driver(s)." ; echo
modLoad()
{
for mod in $@ ; do
- tmp_="`modprobe -vn $mod`"
- if [ $? -ne 0 ]; then
- continue
+ if [ -n "$DEBUG" ] ; then
+ echo "Debug: trying to load $mod:"
+ modprobe -v $mod
+ else
+ modprobe $mod 2>/dev/null
fi
- eval "$tmp_"
done
}
- modLoad "$modules_to_load"
+ # 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 |/static/xargs)"
# loading additional modules
modLoad sunrpc lockd af_packet nfs
- /static/udhcpc --foreground --quit --script=/static/udhcp-config.sh
- #echo "press <enter> to start a system shell and configure your system"
- #sh
+ dhcp_iface_=$(getbootparam dhcp_iface)
+ if [ -z "$dhcp_iface_" ]; then
+ dhcp_iface_=`ifconfig -a | grep '^eth' | sed 's/ .*//'`
+ fi
+
+ # make sure we have a udhcpc executable, if it's not present
+ # assume that busybox provides one
+ if ! [ -x /static/udhcpc ] ; then
+ ln -s /static/busybox /static/udhcpc
+ 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 <enter> to start a system shell and configure your system"
+ # sh
+ done
- # recreate the old dir structures
- rdir
- #rm -rf /myusr /mylib
+ # recreate dir layout + remove extra modules
+ /static/rdir
- log_begin_msg "${RED}Debug: NFS = ${NFS}${NORMAL}"
- log_begin_msg -n "${CRE}${BLUE}Looking for GRML in: ${MAGENTA}$NFS${NORMAL} "
+ 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
-=======
-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
->>>>>>> /tmp/linuxrc~other.LuZLNY
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
# load filesystems
/GRML/sbin/modprobe fuse
/GRML/sbin/modprobe ntfs
- $INSMOD -f /modules/div/ntfs.ko 1>/dev/null
+ $INSMOD /modules/div/ntfs.ko 1>/dev/null
if [ -n "$ISO_PATH" ]; then
LOOP_SOURCE="$TARGET.loop"
TARGET_DEV=$(echo $CMDLINE | /usr/bin/tr ' ' '\n' | /bin/sed -n '/tohd=/s/.*=//p' | /usr/bin/tail -1)
TARGET_DEV_DESC="$TARGET_DEV"
# load filesystems
-<<<<<<< /home/mika/grml/hg/grml-terminalserver/linuxrc
/GRML/sbin/modprobe fuse
/GRML/sbin/modprobe ntfs
FS="ext3 ext2 reiserfs reiser4 vfat ntfs"
if test -z "$MOUNTED"; then
log_failure_msg "Copying grml CD-ROM failed. ${MAGENTA}$TARGET_DEV_DESC${NORMAL} is not mountable."
sleep 2
-=======
- /GRML/sbin/modprobe fuse
- /GRML/sbin/modprobe ntfs
- FS="ext3 ext2 reiserfs reiser4 vfat ntfs"
-
- MOUNTED=""
- for i in $FS; do
- if /GRML/bin/mount -o rw -t "$i" "$TARGET_DEV" "$TARGET"; then
- MOUNTED="true"
- break
- 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}"
- sleep 2
->>>>>>> /tmp/linuxrc~other.LuZLNY
return 1
fi
# check for enough free space
fi
# do the real copy
-<<<<<<< /home/mika/grml/hg/grml-terminalserver/linuxrc
log_begin_msg "Copying grml CD-ROM to ${TARGET_DEV_DESC}... Please be patient."
echo
-=======
-
- echo "${CRE} ${GREEN}Copying grml CD-ROM to ${MAGENTA}$TARGET_DEV_DESC${GREEN}... Please be patient. ${NORMAL}"
->>>>>>> /tmp/linuxrc~other.LuZLNY
if [ -z "$use_cp" -a -x /usr/bin/rsync ]
then
# first cp the small files
return 1
fi
# remount r/o
-<<<<<<< /home/mika/grml/hg/grml-terminalserver/linuxrc
/bin/mount -n -o remount,ro $TARGET 1>/dev/null 2>&1
-=======
- /bin/mount -n -o remount,ro $TARGET
->>>>>>> /tmp/linuxrc~other.LuZLNY
remount_grml
}
SOURCE="/cdrom"
TARGET="/cdrom2"
-<<<<<<< /home/mika/grml/hg/grml-terminalserver/linuxrc
# first copy_to, then boot_from
if [ -n "$COPYTO" ]; then
SOURCE2="$LOOP_SOURCE"
SOURCE="/cdrom2"
TARGET="/cdrom3"
-=======
-
- # first copy_to, then boot_from
- if [ -n "$COPYTO" ]; then
- 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"
->>>>>>> /tmp/linuxrc~other.LuZLNY
fi
fi
fi
# Final test if everything succeeded.
-if test -n "$FOUND_GRML"
-then
+if test -n "$FOUND_GRML" ; then
# copy library cache
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"
# From here, we should have all essential commands available.
hash -r
-<<<<<<< /home/mika/grml/hg/grml-terminalserver/linuxrc
# 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
->>>>>>> /tmp/linuxrc~other.LuZLNY
fi
# Clean up /etc/mtab (and - just in case - make a nice entry for looped ISO)
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
# 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="$(/usr/bin/expr $TOTALMEM - $MINLEFT)"
# Default ramdisk size for ramdisk
-RAMSIZE="$(expr $TOTALMEM / 5)"
+[ -n "$TOTALMEM" ] && RAMSIZE="$(/usr/bin/expr $TOTALMEM / 5)"
# Create additional dynamic ramdisk.
test -z "$RAMSIZE" -o "$RAMSIZE" -lt "$MINSIZE" && RAMSIZE="$MINSIZE"
mkdir -p /ramdisk
# tmpfs/varsize version, can use swap
-RAMSIZE=$(expr $RAMSIZE \* 4)
+RAMSIZE=$(/usr/bin/expr $RAMSIZE \* 4)
log_begin_msg "Creating /ramdisk (dynamic size=${RAMSIZE}k) on shared memory"
# We need /bin/mount here for the -o size= option
/bin/mount -t tmpfs -o "size=${RAMSIZE}k" /ramdisk /ramdisk && echo "$SUCCESS"
-mkdir -p /ramdisk/tmp /ramdisk/home/grml && chmod 1777 /ramdisk/tmp && chown grml.grml /ramdisk/home/grml && ln -snf /ramdisk/home /home && mv /tmp /tmp.old && ln -s /ramdisk/tmp /tmp && rm -rf /tmp.old
+mkdir -p /ramdisk/tmp /ramdisk/home/grml && chmod 1777 /ramdisk/tmp && chown grml.grml /ramdisk/home/grml && ln -snf /ramdisk/home /home && /bin/mv /tmp /tmp.old && ln -s /ramdisk/tmp /tmp && rm -rf /tmp.old
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 && \
+ /bin/mv /$i /$i.old && \
/GRML/lib/ld-linux.so.2 --library-path /GRML/lib /GRML/bin/ln -snf /UNIONFS/$i /$i && \
rm -rf /$i.old
else
ln -snf /UNIONFS/$i /$i
fi
done
- 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
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
# Change root device from /dev/fd0 to /dev/ram0
echo "0x100" > /proc/sys/kernel/real-root-dev
-umount /sys # (remount in grml-autoconfig)
+/bin/umount /sys # (remount in grml-autoconfig)
stage=4
rundebugshell
exit 0
else
-<<<<<<< /home/mika/grml/hg/grml-terminalserver/linuxrc
log_failure_msg "Error: Can't find grml filesystem, sorry."
echo "
Are you booting via USB or firewire?
# Allow signals
trap 1 2 3 15
exec /static/sh
-=======
- echo "${CRE}${RED}Can't find grml filesystem, sorry.${NORMAL}"
- echo "
-Are you booting via USB or firewire?
-====================================
-Try to boot with bootparam scandelay which delays the
-bootup sequence so modules should have enough time
-to initialize devices.
-
-Usage examples on bootprompt of grml-iso:
-
-grml scandelay -> adds the default delay of 10 seconds
-grml scandelay=13 -> adds a delay of 13 seconds
-
-Are you booting via SCSI?
-====================================
-Use the bootparam scsi.
-Usage examples on bootprompt of grml-iso:
-
-grml scsi=probe -> autoprobing of scsi modules
-grml scsi=ask -> list modules and prompt for module which should be loaded
-grml scsi=modulename -> loads specified module (without .ko extension)
-expert -> activate expert mode, similar to scsi=ask
-
-Are you getting SquashFS/zlib errors?
-=====================================
-Try to boot with \"grml nodma\"
-
-Still problems?
-===============
-Make sure the ISO itself is ok.
-Check the md5sum of downloaded ISO.
-Used a CD-RW? Make sure the medium is ok!
-
-Please report any problems you notice to the grml-team!
-http://grml.org/contact/
-"
- echo "${RED}Now dropping you to the busybox shell.${NORMAL}"
- echo "${RED}Press reset button to quit.${NORMAL}"
- echo ""
- PS1="grml# "
- export PS1
- echo "6" > /proc/sys/kernel/printk
- # Allow signals
- trap 1 2 3 15
- exec /static/sh
->>>>>>> /tmp/linuxrc~other.LuZLNY
fi
# EOF