3 # Purpose: minirt for kernel 2.6 running on grml live-cd
4 # Authors: (c) Klaus Knopper <knoppix@knopper.net>, (c) Michael Prokop <mika@grml.org>
5 # Latest change: Thu May 10 11:29:02 CEST 2007 [mika]
6 #######################################################################################
8 # hardcoded configurable options
9 # Default maximum size of dynamic ramdisk in kilobytes
13 # Don't allow interrupt signals
17 INSMOD="/static/insmod"
18 # [ -x /modules/insmod ] && INSMOD="/modules/insmod"
21 # [ -x /modules/rmmod ] && RMMOD="/modules/rmmod"
24 # BUILTIN_FS="iso9660 ext2 vfat"
25 BUILTIN_FS="iso9660 ext2 ext3 reiserfs vfat xfs jfs reiser4"
28 # Usage: mountit src dst "options"
29 for fs in $BUILTIN_FS; do
33 # We REALLY need this for Knoppix on DOS-filesystems
34 shortname="shortname=winnt"
35 [ -n "$options" ] && options="$options,$shortname" || options="-o $shortname"
38 mount -t $fs $options $1 $2 >/dev/null 2>&1 && return 0
49 exec >/dev/console </dev/console 2>&1
51 # Mount /proc and /dev/pts
52 mount -t proc /proc /proc
54 # Disable kernel messages while probing modules in autodetect mode
55 echo "0" > /proc/sys/kernel/printk
57 mount -t devpts /dev/pts /dev/pts
59 mount -t sysfs /sys /sys >/dev/null 2>&1
61 # Read boot command line with builtin cat command (shell read function fails in Kernel 2.4.19-rc1)
62 CMDLINE="$(cat /proc/cmdline)"
66 case "$(cat $2)" in *$1*) return 0;; esac
72 case "$2" in *$1*) return 0;; esac
76 # Reread boot command line; echo last parameter's argument or return false.
78 stringinstring " $1=" "$CMDLINE" || return 1
79 result="${CMDLINE##*$1=}"
80 result="${result%%[ ]*}"
85 # Check boot commandline for specified option
87 stringinstring " $1" "$CMDLINE"
91 if checkbootparam "nocolor" ; then
92 echo "Disabling colors in bootsequence as requested on commandline."
96 # Erase to end of line
98 # Clear and reset Screen
101 # Reset fb color mode
104 # Erase to end of line
106 # Clear and reset Screen
110 # RED: Failure or error message
112 # GREEN: Success message
114 # YELLOW: Descriptions
116 # BLUE: System mesages
118 # MAGENTA: Found devices or drivers
126 # don't output anything if running with bootsplash feature
127 if checkbootparam "splash" ; then
129 echo "${WHITE}Welcome to"
131 echo "${RED} ____ ____ __ __ _ "
132 echo "${RED} / ___| _ \| \/ | | "
133 echo "${RED} | | _| |_) | |\/| | | "
134 echo "${RED} | |_| | _ <| | | | |___ "
135 echo "${RED} \____|_| \_\_| |_|_____|"
137 echo "${WHITE}grml.org - Linux for sysadmins and texttool users."
139 exec >/dev/null </dev/null 2>&1
142 # helper functions {{{
143 #log_success_msg () {
148 echo -n " ${RED}*${NORMAL} $@"
151 #log_warning_msg () {
152 # echo " ${BLUE}*${NORMAL} $@"
155 # int log_begin_message (char *message)
157 echo -n " ${GREEN}*${NORMAL} $@"
161 echo -n " ${YELLOW}*${NORMAL} $@"
164 # int log_end_message (int exitstatus)
165 SUCCESS=" ${BLUE}[ ${GREEN}ok ${BLUE}]${NORMAL}"
166 FAILED=" ${NORMAL}[${RED}fail${NORMAL}]"
169 # Clear screen with colormode reset
170 # echo "$CLEAR$RESET"
172 # Just go to the top of the screen
174 DISTRI="$(getbootparam 'distri' 2>/dev/null)"
175 if [ -n "$DISTRI" ] ; then
179 ${WHITE}based on grml.org.
184 ${RED} ____ ____ __ __ _
185 ${RED} / ___| _ \| \/ | |
186 ${RED} | | _| |_) | |\/| | |
187 ${RED} | |_| | _ <| | | | |___
188 ${RED} \____|_| \_\_| |_|_____|
190 ${WHITE}grml.org - Linux for sysadmins and texttool users.
196 echo "${WHITE}Welcome to"
199 # We need the builtin commands and /static only starting at this point
205 case "$CMDLINE" in *debuglinuxrc*) set -x; echo "linuxrc debugging activated"; DEBUG="yes"; ;; esac
206 case "$CMDLINE" in *BOOT_IMAGE=expert\ *) INTERACTIVE="yes"; :>/interactive; ;; esac
207 case "$CMDLINE" in *BOOT_IMAGE=vmware\ *) VMWARE="yes"; ;; esac
208 case "$CMDLINE" in *modules-disk*) INTERACTIVE="yes"; ;; esac
209 case "$CMDLINE" in *BOOT_IMAGE=debug\ *|*\ debug\ *) DEBUG="yes"; ;; esac
210 case "$CMDLINE" in *secure*) SECURE=",nosuid"; ;; esac
211 # Does the user want to skip scsi detection?
215 case "$CMDLINE" in *noscsi*|*nobootscsi*) NOSCSI="yes"; ;; esac
216 case "$CMDLINE" in *nousb\ *|*nobootusb*) NOUSB="yes"; ;; esac
217 case "$CMDLINE" in *nofirewire*|*nobootfirewire*) NOFIREWIRE="yes"; ;; esac
219 case "$CMDLINE" in *fromhd*) NOCD="yes"; ;; esac
220 case "$CMDLINE" in *fromdvd*) FROMDVD="yes"; ;; esac
221 case "$CMDLINE" in *idecd*|*atapicd*) IDECD="yes"; ;; esac
222 case "$CMDLINE" in *noideraid*) NOIDERAID="yes"; ;; esac
224 case "$CMDLINE" in *nousb2*) USB2="" NOUSB2="yes"; ;; esac
225 case "$CMDLINE" in *\ usb*) USB="yes"; ;; esac
229 case "$CMDLINE" in *grml_dir=*) GRML_DIR="$grml_dir"; ;; esac
230 case "$CMDLINE" in *grml_name=*) GRML_NAME="$grml_name"; ;; esac
231 case "$CMDLINE" in *small*) GRML_TYPE="small"; ;; esac
234 for i in $cmdline; do case "$i" in nfsdir=*|NFSDIR=*) eval $i;; esac; done
235 [ -n "$nfsdir" ] && NFS="$nfsdir"
237 if [ -n "$DEBUG" ]; then
238 log_begin_msg "Bootoption debug detected. Printing kernel command line:"
243 # Run a shell if in debug mode
244 # echo "${BLUE}Dropping you to a busybox shell for debugging.${NORMAL}"
247 if [ -n "$DEBUG" ]; then
248 log_begin_msg "Starting intermediate shell stage $stage as requested by \"debug\" option."
250 echo " ${GREEN}-${NORMAL} Just exit the shell to continue boot process...${NORMAL}"
251 if [ -x /static/sh ]; then
263 echo -n "${CRE}Please insert ${TYPE} modules disk and hit Return."
265 echo -n "${CRE}Mounting ${TYPE} modules disk... "
266 # We always mount over /modules/scsi (because it's there ;-)
267 if mountit /dev/fd0 /modules/scsi "-o ro"; then
268 echo "${GREEN}OK.${NORMAL}"
271 echo "${RED}NOT FOUND.${NORMAL}"
275 # Unmount module disk
278 echo -n "${CRE}Unmounting ${TYPE} modules disk... "
279 umount /modules/scsi 2>/dev/null
280 echo "${GREEN}DONE.${NORMAL}"
283 # Ask user for modules
286 echo "${TYPE} modules available:${WHITE}"
289 if test -f "/modules/scsi/$m"; then
290 test -z "$c" && { echo -n " $m"; c="1"; } || { echo " $m"; c=""; }
293 [ -n "$c" ] && echo ""
294 echo "Load ${TYPE} Modules?"
295 echo "[Enter full filename(s) (space-separated), Return for autoprobe, n for none] "
296 echo -n "insmod module(s)> "
298 case "$MODULES" in n|N) MODULES=""; ;; y|"") MODULES="$*"; ;; esac
301 # Try to load the given modules (full path or current directory)
304 test -n "$INTERACTIVE" && echo "6" > /proc/sys/kernel/printk
307 echo -n " Probing ${TYPE}... ${WHITE}$i${NORMAL}: "
308 if test -f /modules/scsi/$i.ko && $INSMOD /modules/scsi/$i.ko >/dev/null 2>&1 && echo " $SUCCESS" || echo " failed " ; then
309 case "$TYPE" in scsi|SCSI) FOUND_SCSI="yes"; ;; esac
312 test -n "$INTERACTIVE" && echo "0" > /proc/sys/kernel/printk
316 # Check for SCSI, use modules on bootfloppy first
317 # Trying to do kind of /proc/pci hardware detection
318 if checkbootparam oldscsi ; then
319 PROCPCI="`cat /proc/pci 2>/dev/null`"
320 case "$PROCPCI" in *[Aa][Ii][Cc]-*|*[Aa][Hh][Aa]-*) SCSI_PROBE="$SCSI_PROBE aic7xxx" ;; esac
321 case "$PROCPCI" in *[Bb][Uu][Ss][Ll][Oo][Gg][Ii][Cc]*) SCSI_PROBE="$SCSI_PROBE BusLogic" ;; esac
322 case "$PROCPCI" in *[Tt][Rr][Mm]-[Ss]1040*|*[Dd][Cc]395*|*[Dd][Cc]315*) SCSI_PROBE="$SCSI_PROBE dc395x" ;; esac
323 case "$PROCPCI" in *53[Cc]8*) SCSI_PROBE="$SCSI_PROBE sym53c8xx" ;; esac
324 case "$PROCPCI" in *53[Cc]9*) SCSI_PROBE="$SCSI_PROBE NCR53C9x" ;; esac
325 case "$PROCPCI" in *53[Cc]406*) SCSI_PROBE="$SCSI_PROBE NCR53c406a" ;; esac
326 case "$PROCPCI" in *[Ii][Nn][Ii][Tt][Ii][Oo]\ *|*[Ii][Nn][Ii]-[Aa]100[Uu]2[Ww]*) SCSI_PROBE="$SCSI_PROBE initio" ;; esac
327 case "$PROCPCI" in *[Mm][Pp][Tt]*[Ss][Cc][Ss][Ii]*) SCSI_PROBE="$SCSI_PROBE mptbase mptscsih" ;; esac
328 case "$PROCPCI" in *[Aa][Dd][Vv][Aa][Nn][Cc][Ee][Dd]\ [Ss][Yy][Ss]*) SCSI_PROBE="$SCSI_PROBE advansys" ;; esac
329 case "$PROCPCI" in *[Aa][Tt][Pp]8*|*[Aa][Ee][Cc]6*) SCSI_PROBE="$SCSI_PROBE atp870u" ;; esac
330 case "$PROCPCI" in *[Dd][Tt][Cc]*) SCSI_PROBE="$SCSI_PROBE dtc" ;; esac
331 case "$PROCPCI" in *[Ee][Aa][Tt][Aa]*) SCSI_PROBE="$SCSI_PROBE eata" ;; esac
332 case "$PROCPCI" in *[Ff]*[Dd][Oo][Mm][Aa][Ii][Nn]*) SCSI_PROBE="$SCSI_PROBE fdomain" ;; esac
333 case "$PROCPCI" in *[Gg][Dd][Tt]\ *) SCSI_PROBE="$SCSI_PROBE gdth" ;; esac
334 case "$PROCPCI" in *[Mm][Ee][Gg][Aa][Rr][Aa][Ii][Dd]*) SCSI_PROBE="$SCSI_PROBE megaraid_mm megaraid_mbox" ;; esac
335 case "$PROCPCI" in *[Qq][Ll][Oo][Gg][Ii][Cc]*) SCSI_PROBE="$SCSI_PROBE qlogicfas408 qlogicfas qlogicfc" ;; esac
336 case "$PROCPCI" in *53[Cc]974*) SCSI_PROBE="$SCSI_PROBE tmscsim" ;; esac
337 case "$PROCPCI" in *[Uu][Ll][Tt][Rr][Aa][Ss][Tt][Oo][Rr]*) SCSI_PROBE="$SCSI_PROBE ultrastor" ;; esac
338 case "$PROCPCI" in *3[Ww][Aa][Rr][Ee]*) SCSI_PROBE="$SCSI_PROBE 3w-xxxx" ;; esac
341 # New sysfs based SCSI detection (thanks, Jörg Schirottke)
343 SYS=$(for x in $(find /sys/devices/ -name modalias); do grep pci: $x 2>/dev/null; done|cut -f2 -d:)
344 while read id driver; do
345 for sysid in $SYS; do
347 if [ -z "$SCSI_PROBE" ]; then
350 SCSI_PROBE="$SCSI_PROBE $driver"
356 $(cat /modules/scsi/scsi-modules.txt)
360 if test -n "$INTERACTIVE"; then
361 # Let the user select interactively
362 askmodules SCSI $(cd /modules/scsi; echo *.ko)
364 # these are the autoprobe-safe modules
366 MODULES="$SCSI_PROBE"
369 if test -z "$NOSCSI" ; then
370 log_begin_msg "Scanning for SCSI devices."
371 $INSMOD /modules/scsi/firmware_class.ko 1>/dev/null
372 test -n "$MODULES" && loadmodules SCSI $MODULES && echo -n "" || echo " ${BLUE}[${NORMAL} none found ${BLUE}]${NORMAL} (try bootoption scsi=probe)"
374 log_warn_msg "Not scanning for SCSI devices as requested on commandline." && echo " $SUCCESS"
377 if checkbootparam scsi ; then
378 MODULE="$(getbootparam 'scsi' 2>/dev/null)"
379 if test "$MODULE" = "probe" ; then
380 log_begin_msg "Bootoption scsi=probe found. Trying to autoprobe SCSI modules:"
382 echo -n " Trying to load scsi_debug: " ; $INSMOD /modules/scsi/scsi_debug.ko 1>/dev/null && echo " $SUCCESS" || echo " [ failed ]"
383 for module in /modules/scsi/*.ko ; do
384 echo -n " Probing ${WHITE}${module}${NORMAL}..."
385 $INSMOD ${module} >/dev/null 2>&1 && echo " $SUCCESS" || echo " [ failed ]"
387 elif test "$MODULE" = "ask" ; then
388 askmodules SCSI $(cd /modules/scsi; echo *.ko)
389 test -z "$NOSCSI" && test -n "$MODULES" && loadmodules SCSI $MODULES
391 [ -n "$MODULE" ] || echo " ${RED}Neither a specific module nor option probe nor option ask for SCSI module given. Skipping.${NORMAL}"
392 [ -n "$MODULE" ] && echo -n " Trying to load module ${WHITE}${MODULE}${NORMAL}:" ; \
393 $INSMOD "/modules/scsi/${MODULE}.ko" 1>/dev/null && echo " $SUCCESS" || echo " [ failed ]"
398 if test -n "$VMWARE" ; then
399 log_begin_msg "Bootoption VMware detected. Trying to load SCSI modules:"
401 for module in mptbase mptscsih mptspi BusLogic ; do
402 echo -n " Trying to load ${WHITE}${module}${NORMAL}: "
403 $INSMOD /modules/scsi/${module}.ko >/dev/null 2>&1 && echo " $SUCCESS" || echo " [ failed ]"
407 # Check for USB, use modules on bootfloppy first
408 if test -z "$NOUSB"; then
409 log_begin_msg "Checking for USB."
410 if test -f /modules/div/usbcore.ko; then
411 $INSMOD /modules/div/usbcore.ko >/dev/null 2>&1
413 for i in $USB2 uhci-hcd.ko ohci-hcd.ko usbhid.ko ; do
414 test -f /modules/div/$i && $INSMOD /modules/div/$i >/dev/null 2>&1 && FOUNDUSB="yes"
416 if test -n "$FOUNDUSB"; then
417 test -f /modules/div/usb-storage.ko && $INSMOD /modules/div/usb-storage.ko >/dev/null 2>&1
420 echo " ${BLUE}[${NORMAL} not found ${BLUE}]${NORMAL}"
423 if [ -n "$NOUSB2" ] ; then
424 echo " Not loading usb2 module ehci-hcd as requested on commandline."
425 echo " Notice: to skip loading of USB in initrd at all use bootoption nousb"
429 log_warn_msg "Not scanning for USB devices as requested on commandline." && echo " $SUCCESS"
430 echo " Notice that bootoption nousb affects initrd only, it does *not*"
431 echo " avoid loading of usb modules in userspace afterwards"
432 echo " Boot using something like 'nousb blacklist=uhci-hcd' to avoid loading of usb modules at all"
436 # Check for Firewire, use modules on bootfloppy first
437 if test -z "$NOFIREWIRE" ; then
438 log_begin_msg "Checking for Firewire."
439 if test -f /modules/div/ieee1394.ko ; then
440 $INSMOD /modules/div/ieee1394.ko > /dev/null 2>&1
442 test -f /modules/div/ohci1394.ko && $INSMOD /modules/div/ohci1394.ko > /dev/null 2>&1 && FOUNDFIREWIRE="yes"
443 if test -n "$FOUNDFIREWIRE" ; then
444 test -f /modules/div/sbp2.ko && $INSMOD /modules/div/sbp2.ko > /dev/null 2>&1
447 echo " ${BLUE}[${NORMAL} not found ${BLUE}]${NORMAL}"
452 log_warn_msg "Not scanning for firewire devices as requested on commandline." && echo " $SUCCESS"
453 echo " Notice that bootoption nofirewire affects initrd only, it does *not*"
454 echo " avoid loading of firewire modules in userspace afterwards"
455 echo " Boot with something like 'nofirewire blacklist=ohci1394' to avoid loading of firewire modules at all"
457 # End of FIREWIRE check
459 # Unfortunately, hotpluggable devices tend to need some time in order to register
460 if test -n "$FOUNDUSB" -o -n "$FOUNDFIREWIRE"; then
461 log_begin_msg "Scanning for USB/Firewire devices."
463 if test -n "$USB"; then
469 if checkbootparam scandelay ; then
470 DELAY="$(getbootparam 'scandelay' 2>/dev/null)"
471 [ -z $DELAY ] && DELAY='10'
472 log_begin_msg "Delaying bootsequence as requested for ${WHITE}${DELAY}${NORMAL} seconds."
473 sleep $DELAY && echo " $SUCCESS"
476 # boot via pcmcia - not yet supported!
477 if checkbootparam bootpcmcia ; then
478 log_begin_msg "Bootoption bootpcmcia found. Trying to load ${WHITE}PCMCIA${NORMAL} modules..."
479 if $INSMOD /modules/div/pcmcia_core.ko 1>/dev/null ; then
480 $INSMOD /modules/div/firmware_class.ko 1>/dev/null && \
481 $INSMOD /modules/div/pcmcia.ko 1>/dev/null && \
482 $INSMOD /modules/div/rsrc_nonstatic.ko 1>/dev/null && \
483 $INSMOD /modules/div/yenta_socket.ko 1>/dev/null && echo " $SUCCESS"
489 # Check for misc modules in expert mode
490 if test -n "$INTERACTIVE" ; then
493 while test "$answer" != "n" -a "$answer" != "N" ; do
494 echo -n "${CYAN}Do you want to load additional modules from$another floppy disk? [${WHITE}Y${CYAN}/n] ${NORMAL}"
497 case "$answer" in n*|N*) break; ;; esac
498 if mountmodules new ; then
499 askmodules new $(cd /modules/scsi; echo *.ko)
500 test -n "$MODULES" && loadmodules new $MODULES
501 umountmodules current
505 # All interactively requested modules should be loaded now.
507 # Check for ide-scsi supported CD-Roms et al.
508 test -f /proc/scsi/scsi && FOUND_SCSI="yes"
510 # Disable kernel messages again
511 echo "0" > /proc/sys/kernel/printk
513 # We now enable DMA right here, for faster reading/writing from/to IDE devices
514 # in FROMHD or TORAM mode
515 case "$CMDLINE" in *\ nodma*) ;; *)
516 for d in $(cd /proc/ide 2>/dev/null && echo hd[a-z]); do
517 if test -d /proc/ide/$d; then
518 MODEL="$(cat /proc/ide/$d/model 2>/dev/null)"
519 test -z "$MODEL" && MODEL="[GENERIC IDE DEVICE]"
520 log_begin_msg "Enabling DMA acceleration for: ${MAGENTA}$d ${YELLOW}[${MODEL}]${NORMAL}"
521 echo "using_dma:1" >/proc/ide/$d/settings && echo ""
529 if [ -n "$NFS" ]; then
530 tmp_="$(getbootparam nfsdir)"
531 log_begin_msg "Bootoption NFS found." ; echo "$SUCCESS"
535 log_begin_msg "Trying to load network driver(s)." ; echo
539 if [ -n "$DEBUG" ] ; then
540 echo "Debug: trying to load $mod:"
543 modprobe $mod 2>/dev/null
547 # modules.alias and modules.dep are in place so USE IT :)!
548 find /sys/devices/ -name modalias |/static/xargs -r /static/grep -h pci: |while read i; do
551 # loading additional modules
552 modLoad sunrpc lockd af_packet nfs
554 dhcp_iface_=$(getbootparam dhcp_iface)
555 if [ -z "$dhcp_iface_" ]; then
556 dhcp_iface_=`ifconfig -a | grep '^eth' | sed 's/ .*//'`
559 # make sure we have a udhcpc executable, if it's not present
560 # assume that busybox provides one
561 if ! [ -x /static/udhcpc ] ; then
562 ln -s /static/busybox /static/udhcpc
565 for INTERFACE in $dhcp_iface_ ; do
566 log_begin_msg "Requesting network configuration using udhcp for ${INTERFACE}:" ; echo
567 /static/timeout 10 /static/udhcpc --interface="${INTERFACE}" --foreground --quit --script=/static/udhcp-config.sh
568 # echo "press <enter> to start a system shell and configure your system"
572 # recreate dir layout + remove extra modules
575 log_begin_msg "Looking for GRML in: ${MAGENTA}$NFS${NORMAL}" ; echo "$SUCCESS"
576 if mount -t nfs "$NFS" -o "async,ro,nolock" /cdrom #>/dev/null 2>&1
578 if test -f /cdrom/$GRML_DIR/$GRML_NAME
580 log_begin_msg "Accessing grml CDROM at ${MAGENTA}$NFS${NORMAL}" ; echo "$SUCCESS"
587 # Now that the right SCSI driver is (hopefully) loaded, try to find CD-ROM
590 if test -z $NFS ; then
592 test -n "$FOUND_SCSI" -a -z "$NOCD" && DEVICES="/dev/scd? /dev/scd?? $DEVICES"
593 # New: Also try parallel port CD-ROMs
594 DEVICES="$DEVICES /dev/pcd?"
595 # New: also check HD partitions for a GRML/GRML image
596 # notice: use /dev/sd? for usb-sticks without partition(s)
597 test -n "$FOUND_SCSI" -a -z "$NOSCSI" && DEVICES="$DEVICES /dev/sd?[1-9] /dev/sd?[1-9][0-9] /dev/sd?"
598 DEVICES="$DEVICES /dev/hd?[1-9] /dev/hd?[1-9][0-9]"
599 case "$CMDLINE" in *fromhd=/dev/*) DEVICES="$fromhd"; ;; esac
600 # make sure we dont' search for the booting device if cdrom=... is present
601 case "$CMDLINE" in *cdrom=/dev/*)
602 CDROMDEV="$(echo $CMDLINE | tr ' ' '\n' | sed -n '/cdrom=/s/.*=//p' | tail -1)"
603 DEVICES="$(echo $CDROMDEV | awk -F/ '{ print $1 "/" $2 "/" $3 }')"
606 for i in $DEVICES ; do
607 log_begin_msg "${CRE} ${GREEN}*${NORMAL} Looking for CD-ROM in: ${MAGENTA}$i${NORMAL}"
608 if mountit $i /cdrom "-o ro" >/dev/null 2>&1 ; then
610 if test -f /cdrom/$GRML_DIR/$GRML_NAME ; then
611 log_begin_msg "Accessing grml CD-ROM at: ${MAGENTA}$i${NORMAL}" ; echo " $SUCCESS"
621 # Rerun the grml-CDROM part 3 times at total
623 if [ -z "$FOUND_GRML" ] ; then
625 log_warn_msg "grml CD-ROM not yet found, sleeping for 5 seconds and trying again then."
626 sleep 5 && echo " $SUCCESS"
628 if [ -z "$FOUND_GRML" ] ; then
630 log_warn_msg "grml CD-ROM still not yet found, sleeping for 5 more seconds and trying once more again."
631 sleep 5 && echo " $SUCCESS"
635 # Harddisk-installed script part version has been removed
636 # (GRML can be booted directly from HD now).
639 if test -n "$FOUND_GRML" -a -f $1/$GRML_DIR/$GRML_NAME ; then
640 # echo "6" > /proc/sys/kernel/printk
641 mount -t squashfs $1/$GRML_DIR/$GRML_NAME /GRML -o loop,ro$SECURE || FOUND_GRML=""
647 if test -f $TARGET/$GRML_DIR/$GRML_NAME; then
648 umount /GRML # unmount it
649 umount $SOURCE # unmount CD
650 [ -n "$SOURCE2" ] && umount $SOURCE2 # umount possible loop-device
653 log_failure_msg "Warning: Changing to $TARGET failed." ; echo "$FAILED"
665 SOURCE_DEV=$(echo $CMDLINE | /usr/bin/tr ' ' '\n' | /bin/sed -n '/bootfrom=/s/.*=//p' | /usr/bin/tail -1)
667 LOOP_DEV=$(echo $SOURCE_DEV | /usr/bin/gawk -F/ '{ print $1 "/" $2 "/" $3 }')
668 ISO_PATH=$(echo $SOURCE_DEV | /bin/sed "s|$LOOP_DEV||g" )
669 case "$ISO_PATH" in /*.[iI][sS][oO]) ;; *) ISO_PATH="" ;; esac
673 /GRML/sbin/modprobe fuse
674 /GRML/sbin/modprobe ntfs
675 if [ -r /modules/div/ntfs.ko ] ; then
676 grep -q ntfs /proc/modules || $INSMOD /modules/div/ntfs.ko 1>/dev/null
678 log_failure_msg "No NTFS kernel module found." ; echo "$FAILED"
681 if [ -n "$ISO_PATH" ]; then
682 LOOP_SOURCE="$TARGET.loop"
683 LOOP_SOURCE2="$LOOP_SOURCE"
684 TARGET_DEV="$LOOP_SOURCE$ISO_PATH"
685 /bin/mkdir $LOOP_SOURCE
686 /bin/mount -o ro $LOOP_DEV $LOOP_SOURCE || LOOP_SOURCE=""
687 /bin/mount -n -o loop $LOOP_SOURCE2$ISO_PATH $TARGET
689 TARGET_DEV="$SOURCE_DEV"
690 /bin/mount -n -o ro $SOURCE_DEV $TARGET
692 if [ $? -ne 0 ]; then
693 [ -n "$LOOP_SOURCE" ] && /bin/umount $LOOP_SOURCE
694 log_failure_msg "Accessing grml CD-ROM failed. ${MAGENTA}$TARGET_DEV${NORMAL} is not mountable." ; echo "$FAILED"
699 if [ -f "$TARGET/$GRML_DIR/$GRML_NAME" ]; then
700 log_begin_msg "Accessing grml CD-ROM at ${MAGENTA}$TARGET_DEV${NORMAL}." ; echo " $SUCCESS"
702 log_failure_msg "Accessing grml CD-ROM failed. Could not find $GRML_DIR/$GRML_NAME on ${MAGENTA}$TARGET_DEV${RED}.${NORMAL}" ; echo "$FAILED"
703 [ -n "$LOOP_SOURCE" ] && /bin/umount $LOOP_SOURCE
716 COPY="$SOURCE/$GRML_DIR"
718 # look if we copy to hd or to ram
719 SIZE="$(/usr/bin/du -s $COPY | /usr/bin/gawk '{print int($1*1.1)}')"
720 test -n "$SIZE" || SIZE="800000"
724 TARGET_DEV="/dev/shm"
725 TARGET_DEV_DESC="ramdisk"
726 FOUNDSPACE="$(/usr/bin/gawk '/MemTotal/{print $2}' /proc/meminfo)"
727 /bin/mount -n -t tmpfs -o size=${SIZE}k $TARGET_DEV $TARGET
730 TARGET_DEV=$(echo $CMDLINE | /usr/bin/tr ' ' '\n' | /bin/sed -n '/tohd=/s/.*=//p' | /usr/bin/tail -1)
731 TARGET_DEV_DESC="$TARGET_DEV"
733 /GRML/sbin/modprobe fuse
734 /GRML/sbin/modprobe ntfs
735 FS="ext3 ext2 reiserfs reiser4 vfat ntfs"
739 if /GRML/bin/mount -o rw -t "$i" "$TARGET_DEV" "$TARGET"; then
744 if test -z "$MOUNTED"; then
745 log_failure_msg "Copying grml CD-ROM failed. ${MAGENTA}$TARGET_DEV_DESC${NORMAL} is not mountable." ; echo "$FAILED"
749 # check for enough free space
751 [ -f $TARGET/$GRML_DIR/$GRML_NAME ] && USED_SPACE=$(/usr/bin/du -s $TARGET/$GRML_DIR/$GRML_NAME | /usr/bin/gawk '{ print $1 }')
752 FOUNDSPACE="$(/bin/df -k $TARGET | /usr/bin/tail -1 | /usr/bin/gawk '{ print $4+int('$USED_SPACE') }')"
760 if [ $FOUNDSPACE -lt $SIZE ] ; then
761 log_failure_msg "Copying grml CD-ROM failed. Not enough free space on ${MAGENTA}${TARGET_DEV_DESC}${NORMAL}:" ; echo "$FAILED"
762 log_failure_msg "Found: ${MAGENTA}${FOUNDSPACE}k${NORMAL} Need: ${MAGENTA}${SIZE}k${NORMAL}" ; echo "$FAILED"
769 log_begin_msg "Copying grml CD-ROM to ${TARGET_DEV_DESC}... Please be patient."
771 if [ -z "$use_cp" -a -x /usr/bin/rsync ] ; then
772 # first cp the small files
773 /usr/bin/rsync -a --exclude="$GRML_DIR/$GRML_NAME" $COPY $TARGET # Copy grml to $TARGET
774 # then the big file with nice progress meter
775 [ -f $TARGET/$GRML_DIR/$GRML_NAME ] && /bin/rm -f $TARGET/$GRML_DIR/$GRML_NAME
776 /usr/bin/rsync -a --progress --include="$GRML_DIR/$GRML_NAME" --include="$GRML_DIR/" --exclude="*" $COPY $TARGET # Copy grml to $TARGET
777 #/usr/bin/rsync -avP $COPY $TARGET # Copy grml to $TARGET
778 # make sure to support directories from http://grml.org/config/
779 for dir in scripts bootparams config debs ; do
780 if [ -d "/cdrom/$dir" ] ; then
781 log_begin_msg "Customization directory $dir found, copying to $TARGET"
782 cp -a /cdrom/$dir $TARGET/ && echo "$SUCCESS" || echo "$FAILED"
786 /bin/cp -a -f $COPY $TARGET # Copy grml to $TARGET
788 if [ $? -ne 0 ] ; then
789 log_failure_msg "Copying grml CD-ROM failed. ${MAGENTA}$TARGET_DEV_DESC${NORMAL} possibly has not enough space left." ; echo "$FAILED"
794 /bin/mount -n -o remount,ro $TARGET 1>/dev/null 2>&1
806 case "$CMDLINE" in *toram*) DO_REMOUNT="yes"; COPYTO="ram"; ;; esac
807 case "$CMDLINE" in *tohd=*) DO_REMOUNT="yes"; COPYTO="hd"; ;; esac
808 case "$CMDLINE" in *bootfrom=*) DO_REMOUNT="yes"; BOOTFROM="yes" ;; esac
810 # Remount later after copying/isoloading/driverloading?
811 # pre-test if everything succeeded
812 if test -n "$DO_REMOUNT" -a -n "$FOUND_GRML" ; then
814 cat /GRML/etc/ld.so.cache > /etc/ld.so.cache
820 # first copy_to, then boot_from
821 if [ -n "$COPYTO" ]; then
822 copy_to $COPYTO && REAL_TARGET="$TARGET"
824 if [ -n "$BOOTFROM" ]; then
826 if [ "$?" -eq "0" ]; then
827 # set new source / target paths
828 REAL_TARGET="$TARGET"
829 SOURCE2="$LOOP_SOURCE"
836 # Final test if everything succeeded.
837 if test -n "$FOUND_GRML" ; then
839 cat /GRML/etc/ld.so.cache > /etc/ld.so.cache
842 if checkbootparam "unionfs" || test ! -r /modules/aufs.ko ; then
843 $INSMOD /modules/unionfs.ko 1>/dev/null
844 grep -q unionfs /proc/filesystems && UNIONFS=yes
846 UNIONFS_FILETYPE='unionfs'
849 $INSMOD /modules/aufs.ko 1>/dev/null
850 grep -q aufs /proc/filesystems && UNIONFS=yes
851 unionfs='unionfs (using aufs)'
852 UNIONFS_FILETYPE='aufs'
857 log_begin_msg "Setting paths"
858 PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:."
861 # Make space: We don't need the modules anymore from here.
862 /GRML/bin/rm -rf /modules
864 /GRML/bin/cp -a /GRML/etc/alternatives /etc/ 2>/dev/null
867 /GRML/bin/rm -f /sbin
868 /GRML/bin/ln -sf /GRML/sbin /sbin
870 # From here, we should have all essential commands available.
873 # Did we remount the source media?
874 if test -n "$REAL_TARGET"; then
875 /bin/mount -n --move $REAL_TARGET /cdrom # move it back and go on to normal boot
878 # Clean up /etc/mtab (and - just in case - make a nice entry for looped ISO)
879 egrep " /GRML | /cdrom " /proc/mounts 2>/dev/null | sed 's|/dev/loop0 /cdrom \(.*\) 0 0|'$LOOP_SOURCE$ISO_PATH' /cdrom/ \1,loop=/dev/loop0 0 0|g' >> /etc/mtab
882 /GRML/bin/rm -rf /modules /static
885 # New in Kernel 2.4.x: tempfs with variable ramdisk size.
886 # We check for available memory anyways and limit the ramdisks
887 # to a reasonable size.
888 FOUNDMEM="$(awk '/MemTotal/{print $2}' /proc/meminfo)"
889 TOTALMEM="$(awk 'BEGIN{m=0};/MemFree|Cached/{m+=$2};END{print m}' /proc/meminfo)"
892 if [ -n "$FOUNDMEM" ] ; then
893 log_begin_msg "Total memory found: $FOUNDMEM kB" ; echo " $SUCCESS"
895 log_failure_msg "Could not fetch memory information." ; echo " $FAILED"
898 # Now we need to use a little intuition for finding a ramdisk size
899 # that keeps us from running out of space, but still doesn't crash the
900 # machine due to lack of Ram
902 # Minimum size of additional ram partitions
904 # At least this much memory minus 30% should remain when home and var are full.
906 # Maximum ramdisk size
907 [ -n "$TOTALMEM" ] && MAXSIZE="$(/usr/bin/expr $TOTALMEM - $MINLEFT)"
908 # Default ramdisk size for ramdisk
909 [ -n "$TOTALMEM" ] && RAMSIZE="$(/usr/bin/expr $TOTALMEM / 5)"
911 # check for available RAM
912 # check for bootoption small and/or grml-small
913 if [ -n "$FOUNDMEM" ] ; then
914 if [ "$GRML_TYPE" = "small" ] ; then
915 if [ "$FOUNDMEM" -lt 25000 ] ; then
916 log_begin_msg "Bootoption *small detected, but you need at least 32MB of RAM available." ; echo " $FAILED"
917 log_begin_msg "Dropping you to a shell, continue on your own risk." ; echo " $FAILED"
921 if [ "$FOUNDMEM" -lt 58000 ] ; then
922 log_begin_msg "You need at least 64MB of RAM available for grml." ; echo " $FAILED"
923 log_begin_msg "Dropping you to a shell, continue on your own risk." ; echo " $FAILED"
929 # Create additional dynamic ramdisk.
930 test -z "$RAMSIZE" -o "$RAMSIZE" -lt "$MINSIZE" && RAMSIZE="$MINSIZE"
932 # tmpfs/varsize version, can use swap
933 RAMSIZE=$(/usr/bin/expr $RAMSIZE \* 4)
934 log_begin_msg "Creating /ramdisk (dynamic size=${RAMSIZE}k) on shared memory"
935 # We need /bin/mount here for the -o size= option
936 /bin/mount -t tmpfs -o "size=${RAMSIZE}k" /ramdisk /ramdisk && echo "$SUCCESS"
937 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
942 log_begin_msg "Creating $unionfs and symlinks on ramdisk"
944 if test -n "$UNIONFS" && /bin/mount -t $UNIONFS_FILETYPE -o noatime${SECURE},dirs=/ramdisk=rw:/GRML=ro /UNIONFS /UNIONFS ; then
946 if [ -f /GRML/lib/ld-linux.so.2 ] ; then
947 LDLINUX=/GRML/lib/ld-linux.so.2
949 elif [ -f /GRML/lib64/ld-linux-x86-64.so.2 ] ; then
950 LDLINUX=/GRML/lib64/ld-linux-x86-64.so.2
955 # We now have unionfs, copy some data from the initial ramdisk first
956 cp -a /etc/fstab /etc/auto.mnt /etc/filesystems /etc/mtab /UNIONFS/etc/
957 # disable resolvconf on the terminalserver client
958 if [ -n "$NFS" ] ; then
959 rm /UNIONFS/etc/resolv.conf
960 cp -a /etc/resolv.conf /UNIONFS/etc
961 echo REPORT_ABSENT_SYMLINK=no >> /UNIONFS/etc/default/resolvconf
963 for i in bin boot etc sbin var opt root usr $EMUL $LIB64 lib ; do # Move directories to unionfs
965 /bin/mv /$i /$i.old && \
966 # /GRML/lib/ld-linux.so.2 --library-path /GRML/lib /GRML/bin/ln -snf /UNIONFS/$i /$i && \
967 $LDLINUX --library-path $GRMLLIB /GRML/bin/ln -snf /UNIONFS/$i /$i 1>/dev/null 2>/dev/null
970 ln -snf /UNIONFS/$i /$i
973 [ -n "$AUFS" ] && echo " $SUCCESS" || echo " $SUCCESS"
974 log_begin_msg "Merging read-only system with read-writeable /ramdisk."
975 for i in $(cd /UNIONFS; echo *); do # Create links for new stuff on /UNIONFS
976 test "$i" = "home" -o "$i" = "tmp" && continue
977 test -L "/$i" || test -d "/$i" || test -f "/$i" || ln -snf "/UNIONFS/$i" /$i
978 done && echo " $SUCCESS" || echo " $FAILED"
981 log_failure_msg "ERROR: CANNOT UNITE READ-ONLY MEDIA AND INITIAL RAMDISK!" ; echo "$FAILED"
982 log_failure_msg "Can not continue booting, dropping you to a shell." ; echo "$FAILED"
986 chown grml.grml /home/grml
988 # chmod 1777 /var/tmp
990 rm -rf /var/tmp/ ; mkdir /var/tmp ; chown root.root /var/tmp ; chmod 1777 /var/tmp
992 # Create empty utmp and wtmp
996 # Make SURE that these are files, not links!
997 rm -rf /etc/ftpusers /etc/passwd /etc/shadow /etc/group \
998 /etc/ppp /etc/isdn /etc/ssh /etc/ioctl.save \
999 /etc/inittab /etc/network /etc/sudoers \
1000 /etc/init /etc/localtime /etc/dhcpc /etc/pnm2ppa.conf 2>/dev/null
1001 cp -a /GRML/etc/ftpusers /GRML/etc/passwd /GRML/etc/shadow /GRML/etc/group \
1002 /GRML/etc/ppp /GRML/etc/isdn /GRML/etc/ssh \
1003 /GRML/etc/inittab /GRML/etc/network /GRML/etc/sudoers \
1004 /GRML/sbin/init /GRML/etc/dhcpc /etc/ 2>/dev/null
1006 # Extremely important, init crashes on shutdown if this is only a link
1008 :> /etc/pnm2ppa.conf
1009 # Must exist for samba to work
1010 [ -d /var/lib/samba ] && :> /var/lib/samba/unexpected.tdb
1011 # Diet libc bug workaround
1012 # cp -f /GRML/etc/localtime /etc/localtime
1013 # echo "${BLUE}Done.${NORMAL}"
1015 # Now tell kernel where the real modprobe lives
1016 echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
1018 # Change root device from /dev/fd0 to /dev/ram0
1019 echo "0x100" > /proc/sys/kernel/real-root-dev
1021 /bin/umount /sys # (remount in grml-autoconfig)
1025 # Give control to the init process.
1026 log_begin_msg "Starting init process. "
1027 [ -r /mountit ] && rm -f /mountit
1032 log_failure_msg "Error: Can't find grml filesystem, sorry."
1034 Are you booting via USB or firewire?
1035 ====================================
1036 Try to boot with bootparam scandelay which delays the
1037 bootup sequence so modules should have enough time
1038 to initialize devices.
1040 Usage examples on bootprompt of grml-iso:
1042 grml scandelay -> adds the default delay of 10 seconds
1043 grml scandelay=13 -> adds a delay of 13 seconds
1045 Are you booting via SCSI?
1046 ====================================
1047 Use the bootparam scsi.
1048 Usage examples on bootprompt of grml-iso:
1050 grml scsi=probe -> autoprobing of scsi modules
1051 grml scsi=ask -> list modules and prompt for module which should be loaded
1052 grml scsi=modulename -> loads specified module (without .ko extension)
1053 expert -> activate expert mode, similar to scsi=ask
1055 Are you getting SquashFS/zlib errors?
1056 =====================================
1057 Try to boot with \"grml nodma\"
1061 Make sure the ISO itself is ok.
1062 Check the md5sum of downloaded ISO.
1063 Used a CD-RW? Make sure the medium is ok!
1065 Please report any problems you notice to the grml-team!
1066 http://grml.org/contact/
1068 echo "${RED}Now dropping you to the busybox shell.${NORMAL}"
1069 echo "${RED}Press reset button to quit.${NORMAL}"
1073 echo "6" > /proc/sys/kernel/printk