source: /cluster/svnroot/bccd-ng/trunk/trees/KNOPPIX/boot/isolinux/minirt/linuxrc @ 2573

Last change on this file since 2573 was 2573, checked in by skylar, 10 years ago

fixing runinram rsync by calling ld.so directly (#346)

  • Property svn:executable set to *
File size: 30.8 KB
Line 
1#!/static/sh
2#
3# KNOPPIX General Startup Script
4# (C) Klaus Knopper <knoppix@knopper.net>
5# License: GPL V2.
6#
7# This script needs some of the builtin ash commands (if, test, ...)
8# mount/umount, insmod/rmmod are also a builtin in ash-knoppix.
9#
10
11# Just informational: This is a CD or DVD edition
12MEDIUM="CD"
13
14# hardcoded configurable options
15# Default maximum size of dynamic ramdisk in kilobytes
16RAMSIZE=1000000
17# End of options
18
19# Don't allow interrupt signals
20trap "" 1 2 3 11 15
21
22MODULE_DIRS="/cdrom/KNOPPIX/modules /cdrom2/KNOPPIX/modules /modules"
23
24# "Safe" SCSI modules in the right order for autoprobe
25# Warning: The sym53c8xx.ko and g_NCR* cause a kernel Oops if no such adapter
26# is present.
27#
28# NB: It looks like that ncr53c8xx.ko is more stable than 53c7,8xx.ko for
29# a ncr53c810 controller (at least on my installation box it's more
30# immune to SCSI timeouts)
31# Removed 53c7,8xx -> crashes if no device attached.
32# Removed AM53C974 -> crashes tmscsim if adapter found
33# Added initio.ko on request (untested)
34#SCSI_MODULES="aic7xxx.ko aic7xxx_old.ko BusLogic.ko \
35#ncr53c8xx.ko NCR53c406a.ko \
36#initio.ko mptscsih.ko \
37#advansys.ko aha1740.ko aha1542.ko aha152x.ko \
38#atp870u.ko dtc.ko eata.ko fdomain.ko gdth.ko \
39#megaraid.ko pas16.ko pci2220i.ko pci2000.ko psi240i.ko \
40#qlogicfas.ko qlogicfc.ko qlogicisp.ko \
41#seagate.ko t128.ko tmscsim.ko u14-34f.ko ultrastor.ko wd7000.ko \
42#a100u2w.ko 3w-xxxx.ko"
43# Obsoleted by /proc/pci lookups
44
45# Misc functions
46
47
48# Dynamic program loader
49# /KNOPPIX is already mounted when this is used.
50DYNLOADER="/KNOPPIX/lib/ld-linux.so.2"
51
52# Builin filesystems
53BUILTIN_FS="iso9660 ext2 reiserfs vfat ntfs"
54
55mountit(){
56# Usage: mountit src dst "options"
57# Uses builtin mount of ash.knoppix
58for fs in $BUILTIN_FS; do
59 if test -b $1; then
60  options="$3"
61  case "$fs" in
62   vfat)
63    # We REALLY need this for Knoppix on DOS-filesystems
64    shortname="shortname=winnt"
65    [ -n "$options" ] && options="$options,$shortname" || options="-o $shortname"
66    ;;
67   ntfs)
68    ntfsopts="force,silent,umask=0,no_def_opts,allow_other,streams_interface=windows"
69    [ -n "$options" ] && ntfsopts="$options,$ntfsopts" || ntfsopts="-o $ntfsopts"
70    test -x /static/ntfs-3g && /static/ntfs-3g $1 $2 $ntfsopts >/dev/null 2>&1 && return 0
71    ;;
72  esac
73  mount -t $fs $options $1 $2 >/dev/null 2>&1 && return 0
74 fi
75done
76return 1
77}
78
79FOUND_SCSI=""
80FOUND_KNOPPIX=""
81INTERACTIVE=""
82
83# Clean input/output
84exec >/dev/console </dev/console 2>&1
85
86# Reset fb color mode
87RESET="]R"
88# ANSI COLORS
89# Erase to end of line
90CRE=" [K"
91# Clear and reset Screen
92CLEAR="c"
93# Normal color
94NORMAL="[0;39m"
95# RED: Failure or error message
96RED="[1;31m"
97# GREEN: Success message
98GREEN="[1;32m"
99# YELLOW: Descriptions
100YELLOW="[1;33m"
101# BLUE: System mesages
102BLUE="[1;34m"
103# MAGENTA: Found devices or drivers
104MAGENTA="[1;35m"
105# CYAN: Questions
106CYAN="[1;36m"
107# BOLD WHITE: Hint
108WHITE="[1;37m"
109
110# Clear screen with colormode reset
111# echo "$CLEAR$RESET"
112# echo "$CLEAR"
113# Just go to the top of the screen
114# echo -n "[H[J"
115echo ""
116# Be verbose
117echo "${WHITE}Welcome to the ${CYAN}K${MAGENTA}N${YELLOW}O${WHITE}P${RED}P${GREEN}I${BLUE}X${WHITE} live GNU/Linux on ${MEDIUM}"'!'"${NORMAL}"
118echo ""
119echo ""
120
121# We only need the builtin commands and /static at this point
122PATH=/static
123export PATH
124
125umask 022
126
127# Mount /proc and /dev/pts
128mount -t proc /proc /proc
129
130# Disable kernel messages while probing modules in autodetect mode
131echo "0" > /proc/sys/kernel/printk
132
133# Kernel 2.6
134mount -t sysfs /sys /sys >/dev/null 2>&1
135
136# Read boot command line with builtin cat command (shell read function fails in Kernel 2.4.19-rc1)
137CMDLINE="$(cat /proc/cmdline)"
138
139# Check if we are in interactive startup mode
140case "$CMDLINE" in *BOOT_IMAGE=expert\ *) INTERACTIVE="yes"; :>/interactive; ;; esac
141case "$CMDLINE" in *modules-disk*) INTERACTIVE="yes"; ;; esac
142case "$CMDLINE" in *BOOT_IMAGE=debug\ *|*\ debug*) DEBUG="yes"; ;; esac
143# Does the user want to skip scsi detection?
144NOSCSI=""
145case "$CMDLINE" in *noscsi*|*nobootscsi*) NOSCSI="yes"; ;; esac
146case "$CMDLINE" in *nousb*|*nobootusb*) NOUSB="yes"; ;; esac
147case "$CMDLINE" in *nofirewire*|*nobootfirewire*) NOFIREWIRE="yes"; ;; esac
148NOCD=""
149case "$CMDLINE" in *fromhd*) NOCD="yes"; ;; esac
150case "$CMDLINE" in *fromdvd*) FROMDVD="yes"; ;; esac
151case "$CMDLINE" in *idecd*|*atapicd*) IDECD="yes"; ;; esac
152case "$CMDLINE" in *noideraid*) NOIDERAID="yes"; ;; esac
153USB2="ehci-hcd"
154case "$CMDLINE" in *nousb2*) USB2=""; ;; esac
155
156KNOPPIX_DIR="KNOPPIX"
157KNOPPIX_NAME="KNOPPIX"
158case "$CMDLINE" in *knoppix_dir=*) KNOPPIX_DIR="$knoppix_dir"; ;; esac
159case "$CMDLINE" in *knoppix_name=*) KNOPPIX_NAME="$knoppix_name"; ;; esac
160
161# Print kernel info
162read a b KERNEL relax >/dev/null 2>&1 </proc/version
163echo "${GREEN}Running Linux Kernel ${YELLOW}$KERNEL${GREEN}.${NORMAL}"
164
165# Get total ramsize, and available real ram in kB. We need this later.
166# Note that FREEMEM is incorrect, we should add MemCached,
167# but the difference should be minimal at this point.
168TOTALMEM=64000
169FREEMEM=32000
170while read info amount kb; do
171 case "$info" in
172   MemTotal:)   test "$amount" -gt "0" >/dev/null 2>&1 && TOTALMEM="$amount";;
173   MemFree:)    test "$amount" -gt "0" >/dev/null 2>&1 && FREEMEM="$amount";;
174 esac
175done </proc/meminfo
176
177# Print meminfo.
178echo "${CRE}${BLUE}Total Memory available: ${YELLOW}${TOTALMEM}kB${BLUE}, Memory free: ${YELLOW}${FREEMEM}kB${BLUE}.${NORMAL}"
179
180# New in Knoppix 5.1: cloop preload cache
181# Default values
182case "$MEDIUM" in
183 *[Cc][Dd]*) CLOOP_PRELOAD="preload=64" ;;
184 *[Dd][Vv][Dd]*) CLOOP_PRELOAD="preload=128" ;;
185 *) CLOOP_PRELOAD="preload=32" ;;
186esac
187
188# cloop improves seek performance when caching the directory index
189# (first few MB) of each cloop file.
190# Default values depending on ramsize, override with cloop_preload=numblocks at boot.
191if test "$TOTALMEM" -lt 128000; then
192 # up to 128MB: No preload.
193 CLOOP_PRELOAD=""
194elif test "$TOTALMEM" -lt 256000; then
195 # less than 256MB: About 4MB preload w/ blocksize 128k
196 CLOOP_PRELOAD="preload=32"
197elif test "$TOTALMEM" -lt 512000; then
198 # less than 512MB: About 8MB preload w/ blocksize 128k
199 CLOOP_PRELOAD="preload=64"
200elif test "$TOTALMEM" -lt 1024000; then
201 # less than 1GB: About 16MB preload w/ blocksize 128k
202 CLOOP_PRELOAD="preload=128"
203else
204 # 1GB Ram or more
205 # About 32MB w/ blocksize 128k
206 CLOOP_PRELOAD="preload=256"
207fi
208
209case "$CMDLINE" in *\ nocache*|*\ nocloop_preload*|*\ nopreload*) CLOOP_PRELOAD="" ;; esac
210
211[ -n "$cloop_preload" ] && CLOOP_PRELOAD="preload=$cloop_preload"
212
213# Run a shell if in debug mode
214stage=1
215rundebugshell(){
216if [ -n "$DEBUG" ]; then
217echo "${CRE}${BLUE}Starting intermediate Shell stage $stage as requested by \"debug\" option.${NORMAL}"
218echo "${CRE}${BLUE}Type \"exit\" to continue with normal bootup.${NORMAL}"
219[ -x /static/ash ] && /static/ash || /bin/bash
220fi
221}
222
223# Mount module disk
224mountmodules(){
225TYPE="$1"; shift
226echo -n "${CRE}${CYAN}Please insert ${TYPE} modules disk and hit Return. ${NORMAL}"
227read a
228echo -n "${CRE}${BLUE}Mounting ${TYPE} modules disk... ${NORMAL}"
229# We always mount over /modules (because it's there ;-)
230if mountit /dev/fd0 /modules "-o ro"; then
231echo "${GREEN}OK.${NORMAL}"
232return 0
233fi
234echo "${RED}NOT FOUND.${NORMAL}"
235return 1
236}
237
238# Unmount module disk
239umountmodules(){
240TYPE="$1"; shift
241echo -n "${CRE}${BLUE}Unmounting ${TYPE} modules disk... ${NORMAL}"
242umount /modules 2>/dev/null
243echo "${GREEN}DONE.${NORMAL}"
244}
245
246# Ask user for modules
247askmodules(){
248TYPE="$1"; shift
249echo "${BLUE}${TYPE} modules available:${WHITE}"
250c=""; for m in "$@"; do
251if test -r "/modules/$m"; then
252test -z "$c"  && { echo -n "    $m"; c="1"; } || { echo "               $m"; c=""; }
253fi
254done
255[ -n "$c" ] && echo ""
256echo "${CYAN}Load ${TYPE} Modules?${NORMAL}"
257echo "${CYAN}[Enter full filename(s) (space-separated), Return for autoprobe, ${WHITE}n${CYAN} for none] ${NORMAL}"
258echo -n "${CYAN}insmod module(s)> ${NORMAL}"
259read MODULES
260case "$MODULES" in n|N) MODULES=""; ;; y|"")  MODULES="$*"; ;; esac
261}
262
263# Try to load the given module with optional parameters
264# module can be a full path or a module.ko name
265# (in which case $MODULE_DIRS is searched).
266# loadmodule module options...
267loadmodule() {
268 MODULE="$1"; shift
269 INSMOD=""
270 # Find insmod in CURRENT file system configuration
271 for p in $MODULE_DIRS /static; do
272  checkfor="$p/insmod"
273  if test -x "$checkfor"; then
274   INSMOD="$checkfor"; break
275  fi
276 done
277 # At last resort, try builtin insmod
278 test -z "$INSMOD" && INSMOD="insmod" # builtin insmod
279 LOAD=""
280 for p in $MODULE_DIRS; do
281  for ext in "" ".ko" ".o"; do
282   checkfor="$p/$MODULE$ext"
283   if test -r "$checkfor"; then
284    LOAD="$checkfor"
285    break 2
286   fi
287  done
288 done
289 test -n "$LOAD" || return 1
290 # Fork a new process to avoid crashing our main shell
291 echo "$INSMOD -f $LOAD" "$@" | /static/ash
292 return $?
293}
294
295# Load many modules at once
296# loadmodules TYPE(comment) module ...
297loadmodules(){
298 TYPE="$1"; shift
299 test -n "$INTERACTIVE" && echo "6" > /proc/sys/kernel/printk
300 for m in "$@"; do
301  echo -n "${CRE}${BLUE}Probing ${TYPE}... ${MAGENTA}$m${NORMAL}"
302  if loadmodule "$m" >/dev/null 2>&1; then
303   case "$TYPE" in scsi|SCSI) FOUND_SCSI="yes"; ;; esac
304  fi
305 done
306 test -n "$INTERACTIVE" && echo "0" > /proc/sys/kernel/printk
307 echo -n "${CRE}"
308}
309
310unloadmodule() {
311 MODULE="$1"
312 RMMOD=""
313 # Find rmmod in CURRENT file system configuration
314 for p in $MODULE_DIRS /static; do
315  checkfor="$p/rmmod"
316  if test -x "$checkfor"; then
317   RMMOD="$checkfor"; break
318  fi
319 done
320 # At last resort, try builtin rmmod
321 test -z "$RMMOD" && RMMOD="rmmod" # builtin rmmod
322 # For a new process to avoid crashing our main shell
323 echo "$RMMOD" "$MODULE" | /static/ash
324 return $?
325}
326
327# Check for SCSI, use modules on bootfloppy first
328ISA_SCSI="aha1740.ko aha1542.ko aha152x.ko pas16.ko psi240i.ko qlogicfas.ko qlogicfc.ko seagate.ko t128.ko u14-34f.ko wd7000.ko"
329SCSI_PROBE="$ISA_SCSI"
330# Trying to do kind of /proc/pci hardware detection
331# SCSI detection using /sys/devices
332for d in /sys/devices/*/*; do
333 if test -r "$d"/class -a -r "$d"/vendor -a -r "$d"/device; then
334  read CLASS  < "$d"/class 2>/dev/null
335  case "$CLASS" in 0x0100*)
336   read VENDOR < "$d"/vendor 2>/dev/null
337   read DEVICE < "$d"/device 2>/dev/null
338   case "$VENDOR:$DEVICE" in
339    *1000:*00[0-2]?) SCSI_PROBE="$SCSI_PROBE sym53c8xx.ko" ;;
340    *1000:*040?|*1000:*196?|*101e:*196?|*1028:*000[ef]|*1028:*0013) SCSI_PROBE="$SCSI_PROBE megaraid_mbox.ko" ;;
341    *1000:*04[1-9]?|*1028:*0015) SCSI_PROBE="$SCSI_PROBE megaraid_sas.ko" ;;
342    *1001:*9100|*1101:*) SCSI_PROBE="$SCSI_PROBE initio.ko" ;;
343    *9004:*|*9005:*00??) SCSI_PROBE="$SCSI_PROBE aic7xxx.ko" ;;
344    *1011:*|*1028:*000[1-9a]|*9005:*02[08]?) SCSI_PROBE="$SCSI_PROBE aacraid.ko" ;;
345    *1014:*002e|*1014:*01bd|*9005:*0250) SCSI_PROBE="$SCSI_PROBE ips.ko" ;;
346    *1014:*0[1-2]8?|*1069:*|*9005:*0503) SCSI_PROBE="$SCSI_PROBE ipr.ko" ;;
347    *1022:*) SCSI_PROBE="$SCSI_PROBE tmscsim.ko" ;;
348    *1044:*) SCSI_PROBE="$SCSI_PROBE dpt_i2o.ko" ;;
349    *1077:*1???) SCSI_PROBE="$SCSI_PROBE qla1280.ko" ;;
350    *1077:*21??) SCSI_PROBE="$SCSI_PROBE qla2xxx.ko qla2100.ko" ;;
351    *1077:*22??) SCSI_PROBE="$SCSI_PROBE qla2xxx.ko qla2200.ko" ;;
352    *1077:*23[0-1]?) SCSI_PROBE="$SCSI_PROBE qla2xxx.ko qla2300.ko" ;;
353    *1077:*232?) SCSI_PROBE="$SCSI_PROBE qla2xxx.ko qla2322.ko" ;;
354    *1077:*24??) SCSI_PROBE="$SCSI_PROBE qla2xxx.ko" ;;
355    *1077:*63??) SCSI_PROBE="$SCSI_PROBE qla2xxx.ko qla6312.ko" ;;
356    *10df:*) SCSI_PROBE="$SCSI_PROBE lpfc.ko" ;;
357    *10fc:*|*1145:*) SCSI_PROBE="$SCSI_PROBE nsp32.ko" ;;
358    *1101:*) SCSI_PROBE="$SCSI_PROBE a100u2w.ko" ;;
359    *1119:*|*8086:*) SCSI_PROBE="$SCSI_PROBE gdth.ko" ;;
360    *1191:*) SCSI_PROBE="$SCSI_PROBE atp870u.ko" ;;
361    *134a:*) SCSI_PROBE="$SCSI_PROBE dmx3191d.ko" ;;
362    *1de1:*) SCSI_PROBE="$SCSI_PROBE dc395x.ko" ;;
363    *9005:*8???) SCSI_PROBE="$SCSI_PROBE aic79xx.ko" ;;
364    *104b:*) SCSI_PROBE="$SCSI_PROBE BusLogic.ko" ;;
365    *1[0d]e1:*) SCSI_PROBE="$SCSI_PROBE dc395x.ko" ;;
366    *1000:*00[34]?) SCSI_PROBE="$SCSI_PROBE mptscsih.ko" ;;
367    *10cd:*) SCSI_PROBE="$SCSI_PROBE advansys.ko" ;;
368    *1191:*) SCSI_PROBE="$SCSI_PROBE atp870u.ko" ;;
369    *134a:*) SCSI_PROBE="$SCSI_PROBE dtc.ko" ;;
370    *1d44:*) SCSI_PROBE="$SCSI_PROBE eata.ko" ;;
371    *1036:*) SCSI_PROBE="$SCSI_PROBE fdomain.ko" ;;
372    *1256:*4201) SCSI_PROBE="$SCSI_PROBE pci2220i.ko" ;;
373    *1256:*5201) SCSI_PROBE="$SCSI_PROBE pci2000.ko" ;;
374    *1022:*) SCSI_PROBE="$SCSI_PROBE tmscsim.ko" ;;
375    *6356:*) SCSI_PROBE="$SCSI_PROBE ultrastor.ko" ;;
376    *13c1:*) SCSI_PROBE="$SCSI_PROBE 3w-xxxx.ko" ;;
377   esac
378   ;;
379  esac
380 fi
381done
382
383# Load fuse, we may need it to access ntfs filesystems
384loadmodule fuse >/dev/null 2>&1
385
386if test -n "$INTERACTIVE"; then
387 # Let the user select interactively
388 askmodules SCSI $(cd /modules; echo *.ko)
389else
390 # these are the autoprobe-safe modules
391 MODULES="$SCSI_PROBE"
392fi
393test -z "$NOSCSI" && test -n "$MODULES" && loadmodules SCSI $MODULES
394# End of SCSI check
395
396# Check for IDE-Raid devices
397if test -z "$NOIDERAID"; then
398 ( { loadmodule ataraid.ko && loadmodule silraid.ko; } || loadmodule medley.ko || loadmodule pdcraid.ko ) >/dev/null 2>&1
399fi
400# End of IDE-Raid check
401
402# Check for USB, use modules on bootfloppy first
403if test -z "$NOUSB"; then
404 echo -n "${CRE}${BLUE}Checking for USB...${NORMAL}"
405 if loadmodule usbcore.ko >/dev/null 2>&1; then
406  FOUNDUSB=""
407  for i in $USB2 uhci-hcd ohci-hcd; do
408   loadmodule $i >/dev/null 2>&1 && FOUNDUSB="yes"
409  done
410  if test -n "$FOUNDUSB"; then
411   loadmodule libusual.ko >/dev/null 2>&1
412   loadmodule ff-memless.ko >/dev/null 2>&1
413   loadmodule usbhid.ko >/dev/null 2>&1
414   loadmodule usb-libusual.ko >/dev/null 2>&1
415   loadmodule ub.ko >/dev/null 2>&1 || loadmodule usb-storage.ko >/dev/null 2>&1
416  else
417   # For an unknown reason, unloading usbcore hangs sometimes
418   # rmmod usbcore >/dev/null 2>&1
419   true
420  fi
421 fi
422 echo -n "${CRE}"
423fi
424# End of USB check
425
426# Check for Firewire, use modules on bootfloppy first
427if test -z "$NOFIREWIRE"; then
428 echo -n "${CRE}${BLUE}Checking for Firewire...${NORMAL}"
429 if loadmodule ieee1394.ko >/dev/null 2>&1; then
430  FOUNDFIREWIRE=""
431  for i in ohci1394.ko; do
432   echo -n "${CRE}${BLUE}Loading $i...${NORMAL}"
433   loadmodule "$i" >/dev/null 2>&1 && FOUNDFIREWIRE="yes"
434  done
435  if test -n "$FOUNDFIREWIRE"; then
436   echo -n "${CRE}${BLUE}Loading sbp2.ko...${NORMAL}"
437   loadmodule sbp2.ko serialize_io=1 >/dev/null 2>&1
438  else
439   # For an unknown reason, unloading ieee1394 hangs sometimes
440   # echo -n "${CRE}${BLUE}Unloading ieee1394...${NORMAL}"
441   # rmmod ieee1394 >/dev/null 2>&1
442   true
443  fi
444 fi
445 echo -n "${CRE}"
446fi
447# End of FIREWIRE check
448
449# Unfortunately, hotpluggable devices tend to need some time in order to register
450if test -n "$FOUNDUSB" -o -n "$FOUNDFIREWIRE"; then
451 echo -n "${CRE}${BLUE}Scanning for USB/Firewire devices... ${NORMAL}"
452 if test -n "$FOUNDFIREWIRE"; then
453  # Wait for driver to register
454  sleep 2
455  # Kernel 2.6 does this automatically
456  case "$(cat /proc/version 2>/dev/null)" in *version\ 2.6.*) ;; *) for host in 0 1 2 3 4 5 6 7; do for channel in 0 1; do for id in 0 1 2 3 4 5 6 7; do echo "scsi add-single-device $host $channel $id 0" >/proc/scsi/scsi 2>/dev/null; done; done; done ;; esac
457 fi
458 sleep 6
459 echo "${BLUE}Done.${NORMAL}"
460fi
461
462# Check for misc modules in expert mode
463if test -n "$INTERACTIVE"; then
464 another=""; answer=""
465 while test "$answer" != "n" -a "$answer" != "N"; do
466  echo -n "${CYAN}Do you want to load additional modules from$another floppy disk? [${WHITE}Y${CYAN}/n] ${NORMAL}"
467  another=" another"
468  read answer
469  case "$answer" in n*|N*) break; ;; esac
470  if mountmodules new; then
471   askmodules new $(cd /modules; echo *.ko)
472   test -n "$MODULES" && loadmodules new $MODULES
473   umountmodules current
474  fi
475 done
476fi
477# All interactively requested modules should be loaded now.
478
479# Give USB-Storage devices some more time to register
480if test -d /proc/scsi/usb-storage; then
481 echo -n "${CRE}${BLUE}Allowing slow USB-devices some more time to register...${NORMAL}"
482 ash -c "sleep 6"
483 echo "${BLUE}Ok.${NORMAL}"
484fi
485
486# Check for ide-scsi supported CD-Roms et al.
487test -r /proc/scsi/scsi && FOUND_SCSI="yes"
488
489# Disable kernel messages again
490echo "0" > /proc/sys/kernel/printk
491
492# We now enable DMA right here, for faster reading/writing from/to IDE devices
493# in FROMHD or TORAM mode
494case "$CMDLINE" in *\ nodma*) ;; *)
495 for d in $(cd /proc/ide 2>/dev/null && echo hd[a-z]); do
496 if test -d /proc/ide/$d; then
497  MODEL="$(cat /proc/ide/$d/model 2>/dev/null)"
498  test -z "$MODEL" && MODEL="[GENERIC IDE DEVICE]"
499  echo "${BLUE}Enabling DMA acceleration for: ${MAGENTA}$d      ${YELLOW}[${MODEL}]${NORMAL}"
500  echo "using_dma:1" >/proc/ide/$d/settings
501 fi
502 done
503 ;;
504esac
505
506stage=1
507rundebugshell
508
509# Now that the right SCSI driver is (hopefully) loaded, try to find CDROM
510DEVICES="/dev/hd?"
511test -n "$FOUND_SCSI" -a -z "$NOCD" && DEVICES="/dev/scd? /dev/scd?? $DEVICES"
512test -n "$FOUNDUSB$FOUNDFIREWIRE" -a -z "$NOCD" && DEVICES="/dev/sr? $DEVICES"
513# New: Also try parallel port CD-Roms [for Mike].
514DEVICES="$DEVICES /dev/pcd?"
515# New: also check HD partitions for a KNOPPIX/KNOPPIX image
516test -n "$FOUND_SCSI" -a -z "$NOSCSI" && DEVICES="$DEVICES /dev/sd? /dev/sd?[1-9] /dev/sd?[1-9][0-9]"
517DEVICES="$DEVICES /dev/ub?[1-9] /dev/ub?[1-9][0-9] /dev/ub? /dev/hd?[1-9] /dev/hd?[1-9][0-9]"
518case "$CMDLINE" in *fromhd=/dev/*) DEVICES="$fromhd"; ;; esac
519for i in $DEVICES; do
520 echo -n "${CRE}${BLUE}Looking for ${MEDIUM} in: ${MAGENTA}$i${NORMAL}   "
521 if mountit $i /cdrom "-o ro" >/dev/null 2>&1; then
522  if test -r /cdrom/$KNOPPIX_DIR/$KNOPPIX_NAME; then
523   echo -n "${CRE}${GREEN}Accessing KNOPPIX ${MEDIUM} at ${MAGENTA}$i${GREEN}...${NORMAL}"
524   FOUND_KNOPPIX="$i"
525   break
526  fi
527  umount /cdrom
528 fi
529done
530
531# Harddisk-installed script part version has been removed
532# (KNOPPIX can be booted directly from HD now).
533
534mount_knoppix()
535{
536 if test -n "$FOUND_KNOPPIX" -a -r "$1/$KNOPPIX_DIR/$KNOPPIX_NAME"; then
537  # Recheck for modules dir.
538  # If /cdrom/boot/modules is gone, try /cdrom/KNOPPIX/modules
539  # DEBUG
540  # echo "6" > /proc/sys/kernel/printk
541  loadmodule cloop.ko file="$1/$KNOPPIX_DIR/$KNOPPIX_NAME" $CLOOP_PRELOAD || \
542    loadmodule cloop.ko file="$1/$KNOPPIX_DIR/$KNOPPIX_NAME"
543  mountit /dev/cloop /KNOPPIX "-o ro" || FOUND_KNOPPIX=""
544  # Allow multi-image KNOPPIX mounts
545  if [ -n "$FOUND_KNOPPIX" -a -x "$DYNLOADER" -a -x /KNOPPIX/sbin/losetup ]; then
546   echo ""
547   echo -n "${CRE} ${GREEN}Found primary KNOPPIX compressed image at ${MAGENTA}$1/$KNOPPIX_DIR/$KNOPPIX_NAME${GREEN}.${NORMAL}"
548   for c in 1 2 3 4 5 6 7; do
549    if test -r "$1/$KNOPPIX_DIR/$KNOPPIX_NAME$c"; then
550     if "$DYNLOADER" --library-path /KNOPPIX/lib /KNOPPIX/sbin/losetup "/dev/cloop$c" "$1/$KNOPPIX_DIR/$KNOPPIX_NAME$c"; then
551      if "$DYNLOADER" --library-path /KNOPPIX/lib /KNOPPIX/bin/mkdir -m 755 -p "/KNOPPIX$c"; then
552       if mountit "/dev/cloop$c" "/KNOPPIX$c" "-o ro"; then
553        echo ""
554        echo -n "${CRE} ${GREEN}Found additional KNOPPIX compressed image at ${MAGENTA}$1/$KNOPPIX_DIR/$KNOPPIX_NAME$c${GREEN}.${NORMAL}"
555       else
556        "$DYNLOADER" --library-path /KNOPPIX/lib /KNOPPIX/bin/rmdir "/KNOPPIX$c" 2>/dev/null
557       fi
558      else
559       "$DYNLOADER" --library-path /KNOPPIX/lib /KNOPPIX/bin/losetup -d "/dev/cloop$c" 2>/dev/null
560      fi
561     fi
562    fi
563   done
564   /KNOPPIX/bin/ln -snf /KNOPPIX/sbin /sbin && hash -r
565  fi
566 fi
567}
568
569remount_knoppix()
570{
571 if test -r $TARGET/$KNOPPIX_DIR/$KNOPPIX_NAME; then
572  umount /KNOPPIX
573  for c in 0 1 2 3 4 5 6 7; do
574   umount "/$KNOPPIX_NAME$c" >/dev/null 2>&1
575  done
576  unloadmodule cloop # release CD
577  umount $SOURCE  # unmount CD
578  [ -n "$SOURCE2" ] && umount $SOURCE2  # umount possible loop-device
579  mount_knoppix $TARGET
580 else
581  echo "${CRE}${RED}Warning: Changing to $TARGET failed.${NORMAL}"
582  return 1
583 fi
584 return 0
585}
586
587boot_from()
588{
589 # preparations
590 /bin/mkdir $TARGET
591 SOURCE_DEV=$(echo $CMDLINE | /usr/bin/tr ' ' '\n' | /bin/sed -n '/bootfrom=/s/.*=//p' | /usr/bin/tail -1)
592 LOOP_DEV=$(echo $SOURCE_DEV | /usr/bin/gawk -F/ '{ print $1 "/" $2 "/" $3 }')
593 ISO_PATH=$(echo $SOURCE_DEV | /bin/sed "s|$LOOP_DEV||g" )
594 case "$ISO_PATH" in /*.[iI][sS][oO]) ;; *) ISO_PATH="" ;; esac
595 LOOP_SOURCE=""
596
597 # load filesystems
598 for i in reiserfs jbd ext3 ntfs fuse; do
599  /KNOPPIX/sbin/modprobe $i >/dev/null 2>&1
600 done
601 FS="reiserfs ext3 ntfs"
602 
603 if [ -n "$ISO_PATH" ]; then
604  LOOP_SOURCE="$TARGET.loop"
605  LOOP_SOURCE2="$LOOP_SOURCE"
606  TARGET_DEV="$LOOP_SOURCE$ISO_PATH"
607  /bin/mkdir $LOOP_SOURCE
608  /KNOPPIX/sbin/modprobe loop
609  # Try out own mount first.
610  mountit $LOOP_DEV $LOOP_SOURCE "-o ro"
611  if [ "$?" != "0" ]; then
612   for i in $FS; do
613    case "$i" in ntfs) PLAIN="-i" ;; *) PLAIN="" ;; esac
614    /bin/mount $PLAIN -o ro -t $i $LOOP_DEV $LOOP_SOURCE >/dev/null 2>&1 && break
615   done
616  fi
617  test "$?" = "0" || LOOP_SOURCE=""
618  /bin/mount -n -o loop $LOOP_SOURCE2$ISO_PATH $TARGET >/dev/null 2>&1
619 else
620  TARGET_DEV="$SOURCE_DEV"
621  mountit $SOURCE_DEV $TARGET "-o ro"
622  if [ "$?" != "0" ]; then
623   for i in $FS; do
624    case "$i" in ntfs) PLAIN="-i" ;; *) PLAIN="" ;; esac
625    /bin/mount $PLAIN -n -o ro -t $i $SOURCE_DEV $TARGET >/dev/null 2>&1
626   done
627  fi
628 fi
629 if [ "$?" != "0" ]; then
630  [ -n "$LOOP_SOURCE" ] && { /bin/umount $LOOP_SOURCE || umount $LOOP_SOURCE; } >/dev/null 2>&1
631  echo -n "${CRE}${RED}Accessing KNOPPIX ${MEDIUM} failed. ${MAGENTA}$TARGET_DEV${RED} is not mountable.${NORMAL}"
632  sleep 2
633  return 1
634 fi
635 if test -r $TARGET/$KNOPPIX_DIR/$KNOPPIX_NAME ; then
636  echo -n "${CRE}${GREEN}Accessing KNOPPIX ${MEDIUM} at ${MAGENTA}$TARGET_DEV${GREEN}...${NORMAL}"
637 else
638  echo -n "${CRE}${RED}Accessing KNOPPIX ${MEDIUM} failed. Could not find $KNOPPIX_DIR/$KNOPPIX_NAME on ${MAGENTA}$TARGET_DEV${RED}.${NORMAL}"
639  [ -n "$LOOP_SOURCE" ] && { /bin/umount -l $LOOP_SOURCE || umount $LOOP_SOURCE; } >/dev/null 2>&1
640  umount $TARGET
641  sleep 2
642  return 1
643 fi
644 # remount the CD
645 remount_knoppix
646}
647
648copy_to()
649{
650 # preparations
651 /bin/mkdir $TARGET
652 COPY="$SOURCE/$KNOPPIX_DIR"
653 # look if we copy to hd or to ram
654 SIZE="$(/usr/bin/du -s $COPY | /usr/bin/gawk '{print int($1*1.1)}')"
655 test -n "$SIZE" || SIZE="800000"
656 case "$1" in
657  ram)
658   TARGET_DEV="/dev/shm"
659   TARGET_DEV_DESC="ramdisk"
660   FOUNDSPACE="$(/usr/bin/gawk '/MemTotal/{print $2}' /proc/meminfo)"
661   /bin/mount -n -t tmpfs -o size=${SIZE}k $TARGET_DEV $TARGET
662  ;;
663  hd)
664   TARGET_DEV=$(echo $CMDLINE | /usr/bin/tr ' ' '\n' | /bin/sed -n '/tohd=/s/.*=//p' | /usr/bin/tail -1)
665   TARGET_DEV_DESC="$TARGET_DEV"
666
667   # load filesystems
668   for i in reiserfs jbd ext3 ntfs fuse; do
669    /KNOPPIX/sbin/modprobe $i >/dev/null 2>&1
670   done
671 
672   FS="ext3 ext2 reiserfs vfat ntfs fuse"
673   /KNOPPIX/bin/cp -au /KNOPPIX/dev/fuse /dev/ >/dev/null 2>&1
674   MOUNTED=""
675   for filesystem in $FS; do
676    if /KNOPPIX/bin/mount -o rw -t "$filesystem" "$TARGET_DEV" "$TARGET" >/dev/null 2>&1; then
677     MOUNTED="true"
678     break
679    fi
680   done
681   if test -z "$MOUNTED"; then
682    echo -n "${CRE}${RED}Copying KNOPPIX ${MEDIUM} failed. ${MAGENTA}$TARGET_DEV_DESC${RED} is not mountable.${NORMAL}"
683    sleep 2
684    return 1
685   fi
686   # check for enough free space
687   USED_SPACE=0
688   test -r $TARGET/$KNOPPIX_DIR/$KNOPPIX_NAME && USED_SPACE=$(/usr/bin/du -s $TARGET/$KNOPPIX_DIR/$KNOPPIX_NAME | /usr/bin/gawk '{ print $1 }')
689   FOUNDSPACE="$(/bin/df -k $TARGET | /usr/bin/tail -1 | /usr/bin/gawk '{ print $4+int('$USED_SPACE') }')"
690  ;;
691  *)
692   return 1
693  ;;
694 esac
695 # sanity check
696 if [ $FOUNDSPACE -lt $SIZE ]; then
697  echo -n "${CRE}${RED}Copying KNOPPIX ${MEDIUM} failed. Not enough free space on ${MAGENTA}${TARGET_DEV_DESC}${RED}. Found: ${MAGENTA}${FOUNDSPACE}k${RED} Need: ${MAGENTA}${SIZE}k${RED} ${NORMAL}"
698  sleep 2
699  umount $TARGET
700  return 1
701 fi
702 # do the real copy
703 echo "${CRE}${GREEN}Copying KNOPPIX ${MEDIUM} to ${MAGENTA}$TARGET_DEV_DESC${GREEN}... Please be patient. ${NORMAL}"
704 if [ -z "$COPY_COMMAND" -a -x /usr/bin/rsync ]; then
705  # first cp the small files
706  /lib/ld-2.7.so /KNOPPIX/usr/bin/rsync -a --exclude="$KNOPPIX_DIR/$KNOPPIX_NAME*" $COPY $TARGET # Copy Knoppix to $TARGET
707  # then the big files with nice progress meter
708  /lib/ld-2.7.so /KNOPPIX/usr/bin/rsync -a --progress --include="$KNOPPIX_DIR/$KNOPPIX_NAME*" --include="$KNOPPIX_DIR/" --exclude="*" $COPY $TARGET
709 else
710  "$COPY_COMMAND" $COPY $TARGET
711 fi
712 if [ "$?" -ne "0" ]; then
713  echo -n "${CRE}${RED}Copying KNOPPIX ${MEDIUM} failed. ${MAGENTA}$TARGET_DEV_DESC${RED} possibly has not enough space left.${NORMAL}"
714  sleep 2
715  return 1
716 fi
717 # remount r/o
718 case "$filesystem" in
719  ntfs) umount "$TARGET" ; sleep 2 ; { mountit "$TARGET_DEV" "$TARGET" "-o ro" || /KNOPPIX/bin/mount -i -t ntfs -o ro "$TARGET_DEV" "$TARGET"; } ;;
720     *) /KNOPPIX/bin/mount -n -o remount,ro "$TARGET" ;;
721 esac
722 remount_knoppix
723}
724
725mount_knoppix /cdrom
726
727COPYTO=""
728BOOTFROM=""
729DO_REMOUNT=""
730REAL_TARGET=""
731UNIONFS=""
732
733case "$CMDLINE" in *toram*) DO_REMOUNT="yes"; COPYTO="ram"; ;; esac
734case "$CMDLINE" in *tohd=*) DO_REMOUNT="yes"; COPYTO="hd"; ;; esac
735case "$CMDLINE" in *bootfrom=*) DO_REMOUNT="yes"; BOOTFROM="yes" ;; esac
736 
737# Remount later after copying/isoloading/driverloading?
738# pre-test if everything succeeded
739if  test -n "$DO_REMOUNT" -a -n "$FOUND_KNOPPIX"; then
740 # copy library cache
741 cat /KNOPPIX/etc/ld.so.cache > /etc/ld.so.cache
742 echo ""
743
744 SOURCE="/cdrom"
745 TARGET="/cdrom2"
746 
747 # first copy_to, then boot_from
748 if [ -n "$COPYTO" ]; then
749  copy_to $COPYTO && REAL_TARGET="$TARGET"
750 fi
751 if [ -n "$BOOTFROM" ]; then
752  boot_from
753  if [ "$?" -eq "0" ]; then
754   # set new source / target paths
755   REAL_TARGET="$TARGET"
756   SOURCE2="$LOOP_SOURCE"
757   SOURCE="/cdrom2"
758   TARGET="/cdrom3"
759  fi
760 fi
761fi
762 
763# Final test if everything succeeded.
764if test -n "$FOUND_KNOPPIX"; then
765 # copy library cache
766 cat /KNOPPIX/etc/ld.so.cache > /etc/ld.so.cache
767 echo ""
768 UNIONFS=""
769 loadmodule aufs.ko 2>/dev/null && UNIONFS="yes"
770 /KNOPPIX/bin/dmesg|/KNOPPIX/bin/grep -iq aufs && UNIONFS="yes"
771 # Enable kernel messages
772 echo "6" > /proc/sys/kernel/printk
773 # Set paths
774 echo -n "${CRE}${BLUE}Setting paths...${NORMAL}"
775 PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:."
776 export PATH
777 # Make space: We don't need the modules anymore from here.
778 /KNOPPIX/bin/rm -rf /modules
779 # Debian weirdness
780 /KNOPPIX/bin/cp -a /KNOPPIX/etc/alternatives /etc/ 2>/dev/null
781 # Replace /sbin
782 /KNOPPIX/bin/rm -f /sbin
783 /KNOPPIX/bin/ln -sf /KNOPPIX/sbin /sbin
784 # From here, we should have all essential commands available.
785 hash -r
786 # Did we remount the source media ?
787 if  test -n "$REAL_TARGET"; then
788  /bin/mount -n --move $REAL_TARGET /cdrom # move it back and go on to normal boot
789 fi
790 # Clean up /
791 /KNOPPIX/bin/rm -rf /modules /static
792 # New in Kernel 2.4.x: tmpfs with variable ramdisk size.
793 # We check for available memory anyways and limit the ramdisks
794 # to a reasonable size.
795 # Be verbose
796 # Now we need to use a little intuition for finding a ramdisk size
797 # that keeps us from running out of space, but still doesn't crash the
798 # machine due to lack of Ram
799 # Minimum size of additional ram partitions
800 MINSIZE=20000
801 # At least this much memory minus 30% should remain when home and var are full.
802 MINLEFT=16000
803 # Maximum ramdisk size
804 MAXSIZE="$(expr $TOTALMEM - $MINLEFT)"
805 # Default ramdisk size for ramdisk
806 RAMSIZE="$(expr $TOTALMEM / 5)"
807 # Create additional dynamic ramdisk.
808 test -z "$RAMSIZE" -o "$RAMSIZE" -lt "$MINSIZE" && RAMSIZE="$MINSIZE"
809 mkdir -p /ramdisk
810 # tmpfs/varsize version, can use swap
811 RAMSIZE=$(expr $RAMSIZE \* 4)
812 echo -n "${CRE}${BLUE}Creating ${YELLOW}/ramdisk${BLUE} (dynamic size=${RAMSIZE}k) on ${MAGENTA}shared memory${BLUE}...${NORMAL}"
813 # We need /bin/mount here for the -o size= option
814 /bin/mount -t tmpfs -o "size=${RAMSIZE}k,mode=755" /ramdisk /ramdisk
815 mkdir -p /ramdisk/tmp
816 chmod 1777 /ramdisk/tmp
817 ln -snf /ramdisk/home /home
818 mv /tmp /tmp.old && ln -s /ramdisk/tmp /tmp && rm -rf /tmp.old
819 echo "${BLUE}Done.${NORMAL}"
820 stage=2
821 rundebugshell
822 echo -n "${CRE}${BLUE}Creating unified filesystem and symlinks on ramdisk...${NORMAL}"
823 mkdir -p /UNIONFS
824 UNION="/ramdisk"
825 # Add all KNOPPIX images to the union
826 for c in "" 1 2 3 4 5 6 7; do
827  [ -d "/KNOPPIX$c" ] && UNION="$UNION:/KNOPPIX$c"
828 done
829 echo "UNIONFS: $UNIONFS UNION: $UNION"
830 # Do the actual mount
831 if test -n "$UNIONFS" && /bin/mount -t aufs -o "br:$UNION" /UNIONFS /UNIONFS; then
832  # We now have aufs, copy some data from the initial ramdisk first
833  cp -a /etc/fstab /etc/auto.mnt /etc/filesystems /etc/mtab /UNIONFS/etc/
834  # /dev is a special case, it is now normally handled via udev
835  UNIONDEV=""
836  case "$CMDLINE" in *noudev*) UNIONDEV="dev"; ;; esac
837  for i in bin boot etc $UNIONDEV sbin var lib opt root usr; do # Move directories to union
838   if test -d /$i; then
839    mv /$i /$i.old && \
840    /KNOPPIX/lib/ld-linux.so.2 --library-path /KNOPPIX/lib /KNOPPIX/bin/ln -snf /UNIONFS/$i /$i && \
841    rm -rf /$i.old
842   else
843    ln -snf /UNIONFS/$i /$i
844   fi
845  done
846  for i in $(cd /UNIONFS; echo *); do # Create links for new stuff on /UNIONFS
847   test "$i" = "home" -o "$i" = "tmp" && continue
848   test -L "/$i" || test -d "/$i" || test -f "/$i" || ln -snf "/UNIONFS/$i" /$i
849  done
850 else
851  echo -n "${CRE}${RED}ERROR: CANNOT UNITE READ-ONLY MEDIA AND INITIAL RAMDISK!${NORMAL}"
852  /KNOPPIX/sbin/halt -f -n
853 fi
854 echo ""
855 echo "${GREEN}>> Read-only ${MEDIUM} system successfully merged with read-write /ramdisk.${NORMAL}"
856 # CUPS wants writable files. :-/
857 cp -a /KNOPPIX/etc/cups/*.conf /etc/cups/ 2>/dev/null
858 # resolv.conf must be writable as well
859 cp -a /KNOPPIX/etc/dhcpc/resolv.conf /etc/dhcpc/ 2>/dev/null
860 # Create empty utmp and wtmp
861 :> /var/run/utmp
862 :> /var/run/wtmp
863 # Make SURE that these are files, not links!
864 rm -rf /etc/ftpusers /etc/passwd /etc/shadow /etc/gshadow /etc/group \
865        /etc/ppp /etc/isdn /etc/ssh /etc/ioctl.save \
866        /etc/inittab /etc/network /etc/sudoers \
867        /etc/init /etc/localtime /etc/dhcpc /etc/pnm2ppa.conf 2>/dev/null
868 cp -a /KNOPPIX/etc/ftpusers /KNOPPIX/etc/passwd /KNOPPIX/etc/shadow /etc/gshadow /KNOPPIX/etc/group \
869       /KNOPPIX/etc/ppp /KNOPPIX/etc/isdn /KNOPPIX/etc/ssh \
870       /KNOPPIX/etc/inittab /KNOPPIX/etc/network /KNOPPIX/etc/sudoers \
871       /KNOPPIX/sbin/init /KNOPPIX/etc/dhcpc /etc/ 2>/dev/null
872 # Extremely important, init crashes on shutdown if this is only a link
873 :> /etc/ioctl.save
874 :> /etc/pnm2ppa.conf
875 # Must exist for samba to work
876 [ -d /var/lib/samba ] && :> /var/lib/samba/unexpected.tdb
877 # Kernel 2.6.9 bug?
878 chmod 1777 /tmp /var/tmp
879 # Diet libc bug workaround
880 /bin/cp -f /KNOPPIX/etc/localtime /etc/localtime
881 echo "${BLUE}Done.${NORMAL}"
882 # Mount devpts, should be done much later
883 # mount -t devpts /dev/pts /dev/pts 2>/dev/null
884 # Clean up /etc/mtab (and - just in case - make a nice entry for looped ISO)
885 /bin/egrep " /KNOPPIX[0-9]* | /cdrom " /proc/mounts | sed 's|/dev/loop0 /cdrom \(.*\) 0 0|'$LOOP_SOURCE$ISO_PATH' /cdrom/ \1,loop=/dev/loop0 0 0|g' >> /etc/mtab
886 # Now tell kernel where the real modprobe lives
887 echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
888 # Change root device from /dev/fd0 to /dev/ram0
889 echo "0x100" > /proc/sys/kernel/real-root-dev
890 stage=3
891 rundebugshell
892 # Give control to the init process.
893 echo "${CRE}${BLUE}Starting init process.${NORMAL}"
894 rm -f /linuxrc
895 exit 0
896else
897 echo "${CRE}${RED}Can't find KNOPPIX filesystem, sorry.${NORMAL}"
898 echo "${RED}Dropping you to a (very limited) shell.${NORMAL}"
899 echo "${RED}Press reset button to quit.${NORMAL}"
900 echo ""
901 echo "Additional builtin commands avaliable:"
902 echo " cat        mount     umount"
903 echo " insmod     rmmod     lsmod"
904 echo ""
905 PS1="knoppix# "
906 export PS1
907 echo "6" > /proc/sys/kernel/printk
908 # Allow signals
909 trap 1 2 3 11 15
910 exec /static/ash
911fi
Note: See TracBrowser for help on using the repository browser.