2 # Filename: autoconfig.functions
3 # Purpose: basic system configuration and hardware setup for grml system
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
9 # {{{ path, variables, signals, umask, zsh
10 export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin"
15 # old linuxrc version:
16 [ -d /cdrom ] && export LIVECD_PATH=/cdrom
17 # new initramfs layout:
18 [ -d /live/image ] && export LIVECD_PATH=/live/image
20 # Ignore these signals in non-interactive mode: INT, TERM, SEGV
21 [ -z "$PS1" ] && trap "" 2 3 11
25 if [ -n "$ZSH_VERSION" ] ; then
31 # avoid 'no matches found: ...'
32 iszsh && setopt no_nomatch # || echo "Warning: not running under zsh!"
35 # {{{ Read in boot parameters
36 if [ -z "$CMDLINE" ]; then
37 # if CMDLINE was set from the outside, we're debugging.
38 # otherwise, take CMDLINE from Kernel and config files.
39 CMDLINE="$(cat /proc/cmdline)"
40 [ -d /cdrom/bootparams/ ] && CMDLINE="$CMDLINE $(cat /cdrom/bootparams/* | tr '\n' ' ')"
41 [ -d /live/image/bootparams/ ] && CMDLINE="$CMDLINE $(cat /live/image/bootparams/* | tr '\n' ' ')"
45 ### {{{ Utility Functions
47 # Get a bootoption's parameter: read boot command line and either
48 # echo last parameter's argument or return false.
52 result="${CMDLINE##* $1=}"
53 result="${result%%[ ]*}"
61 # Check boot commandline for specified option
63 [ -n "$1" ] || ( echo "Error: missing argument to checkbootparam()" ; return 1 )
64 # make sure we match beginning and end of line as well
65 # but don't match 'vg' if we want to check for 'vga'
66 if echo "$CMDLINE" | grep -qw "$1" ; then
73 # Check wheter a configuration variable (like $CONFIG_TOHD) is
77 [yY][eE][sS]) return 0 ;; # it's set to 'yes'
78 [tT][rR][uU][eE]) return 0 ;; # it's set to 'true'
79 *) return 1 ;; # default
83 # Are we using grml-small?
85 grep -q small /etc/grml_version 2>>$DEBUG && return 0 || return 1
88 # execute flite only if it's present
90 [ -x /usr/bin/flite ] && flite -o play -t "$*"
94 # {{{ filesystems (proc, pts, sys) and fixes
96 [ -f /proc/version ] || mount -t proc /proc /proc 2>/dev/null
100 grep -q "/dev/pts" /proc/mounts || mount -t devpts /dev/pts /dev/pts 2>/dev/null
104 [ -d /sys/devices ] || mount -t sysfs /sys /sys 2>/dev/null
108 # {{{ Check if we are running in live mode or from HD
110 [ -e /etc/grml_cd ] || INSTALLED="yes"
114 checkbootparam 'testcd' >>$DEBUG 2>&1 && TESTCD="yes"
117 # {{{ source lsb-functions , color handling
118 if checkbootparam 'nocolor'; then
120 . /etc/grml/lsb-functions
121 einfo "Disabling colors in bootsequence as requested on commandline." ; eend 0
123 . /etc/grml/lsb-functions
130 checkbootparam 'debug' && BOOTDEBUG="yes"
131 checkbootparam "BOOT_IMAGE=debug" && BOOTDEBUG="yes"
134 if [ -n "$BOOTDEBUG" ]; then
135 einfo "Starting intermediate shell stage $stage as requested by \"debug\" option."
136 if [ grep -q "debug=noscreen" "$CMDLINE" ] ; then
137 einfo "Notice that the shell does not provide job handling: ctrl-z, bg and fg won't work!"
138 einfo "Just exit the shell to continue boot process..."
142 if [ -r /etc/grml/screenrc ] ; then
143 einfo "Starting GNU screen to be able to use a full featured shell environment."
144 einfo "Just exit the shells (and therefore screen) to continue boot process..."
145 /bin/zsh -c "screen -c /etc/grml/screenrc"
147 einfo "Notice that the shell does not provide job handling: ctrl-z, bg and fg won't work!"
148 einfo "Just exit the shell to continue boot process..."
160 if checkbootparam 'log' || checkbootparam 'debug' ; then
161 export DEBUG="/tmp/grml.log.`date +%Y%m%d`"
163 einfo "Bootparameter log found. Log files: ${DEBUG} and /var/log/boot"
165 einfo "Starting bootlogd." # known to be *very* unreliable :(
166 bootlogd -r -c 1>>$DEBUG 2>&1 ; eend $?
174 # {{{ set firmware timeout via bootparam
176 if checkbootparam 'fwtimeout' ; then
177 TIMEOUT="$(getbootparam 'fwtimeout' 2>>$DEBUG)"
178 einfo "Bootoption fwtimeout found. (Re)Loading firmware_class module."
179 rmmod firmware_class 1>>$DEBUG 2>&1
180 modprobe firmware_class ; eend $?
182 if [ -z "$TIMEOUT" ] ; then
183 TIMEOUT="100" # linux kernel default: 10
185 if [ -f /sys/class/firmware/timeout ] ; then
186 einfo "Setting timeout for firmware loading to ${TIMEOUT}."
187 echo 100 > /sys/class/firmware/timeout ; eend $?
192 ### {{{ language configuration / localization
195 einfo "Activating language settings:"
198 # people can specify $LANGUAGE and $CONSOLEFONT in a config file:
199 [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig
201 grep -q ' lang=.*-utf8' /proc/cmdline && UTF8='yes' || UTF8=''
203 # check for bootoption which overrides config from /etc/grml/autoconfig:
204 BOOT_LANGUAGE="$(getbootparam 'lang' 2>>$DEBUG)"
205 [ -n "$BOOT_LANGUAGE" ] && LANGUAGE="$BOOT_LANGUAGE"
207 # set default to 'en' in live-cd mode if $LANGUAGE is not yet set:
208 if [ -z "$INSTALLED" ] ; then
209 [ -n "$LANGUAGE" ] || LANGUAGE='us'
212 # if bootoption lang is used update /etc/default/locale, otherwise *not*!
213 if [ -n "$BOOT_LANGUAGE" -a -x /usr/sbin/grml-setlang ] ; then
214 if checkgrmlsmall ; then
215 /usr/sbin/grml-setlang "POSIX"
217 /usr/sbin/grml-setlang "$LANGUAGE"
222 if [ -z "$CONSOLEFONT" ] ; then
223 if ! checkbootparam 'nodefaultfont' >>$DEBUG 2>&1 ; then
224 # [ -n "$UTF8" ] && CONSOLEFONT='LatArCyrHeb-16' || CONSOLEFONT='Lat15-Terminus16'
225 # if [ -r /usr/share/consolefonts/Lat15-Terminus16.psf.gz ] ; then
226 if [ -r /usr/share/consolefonts/Uni3-Terminus16.psf.gz ] ; then
227 CONSOLEFONT='Uni3-Terminus16'
229 ewarn "/usr/share/consolefonts/Uni3-Terminus16.psf.gz not available. Please upgrade package console-terminus." ; eend 1
234 # export it now, so error messages get translated, too
235 if checkgrmlsmall ; then
236 export LANG='C' # grml-small does not provide any further locales
238 [ -r /etc/default/locale ] && . /etc/default/locale
242 # configure keyboard layout, read in already set values first:
243 [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
245 # now allow keyboard override by boot commandline for later use:
246 KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
247 [ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD"
248 # notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead:
249 [[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys
250 [[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys
252 # modify /etc/sysconfig/keyboard only in live-cd mode:
253 if [ -z "$INSTALLED" ] ; then
255 local LANGUAGE="$BOOT_LANGUAGE"
256 . /etc/grml/language-functions
257 # allow setting xkeyboard explicitly different than console keyboard
258 KXKEYBOARD="$(getbootparam 'xkeyboard' 2>>$DEBUG)"
259 if [ -n "$KXKEYBOARD" ]; then
260 XKEYBOARD="$KXKEYBOARD"
261 KDEKEYBOARD="$KXKEYBOARD"
262 elif [ -n "$KKEYBOARD" ]; then
263 XKEYBOARD="$KKEYBOARD"
264 KDEKEYBOARD="$KKEYBOARD"
267 # duplicate of previous code to make sure /etc/grml/language-functions
268 # does not overwrite our values....
269 # now allow keyboard override by boot commandline for later use:
270 KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
271 [ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD"
272 # notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead:
273 [[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys
274 [[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys
276 # write keyboard related variables to file for later use
277 [ -d /etc/sysconfig ] || mkdir /etc/sysconfig
278 if ! [ -e /etc/sysconfig/keyboard ] ; then
279 echo "KEYTABLE=\"$KEYTABLE\"" > /etc/sysconfig/keyboard
280 echo "XKEYBOARD=\"$XKEYBOARD\"" >> /etc/sysconfig/keyboard
281 echo "KDEKEYBOARD=\"$KDEKEYBOARD\"" >> /etc/sysconfig/keyboard
282 echo "KDEKEYBOARDS=\"$KDEKEYBOARDS\"" >> /etc/sysconfig/keyboard
286 [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
288 # activate unicode console if running within utf8 environment
289 if [ -r /etc/default/locale ] ; then
290 if grep -q "LANG=.*UTF" /etc/default/locale ; then
291 einfo "Setting up unicode environment."
292 unicode_start 2>>$DEBUG ; eend $?
296 # Set default keyboard before interactive setup
297 if [ -n "$KEYTABLE" ] ; then
298 einfo "Running loadkeys for ${WHITE}${KEYTABLE}${NORMAL} in background"
299 loadkeys -q $KEYTABLE &
303 # we have to set up all consoles, therefore loop it over all ttys:
304 NUM_CONSOLES=$(fgconsole --next-available)
305 NUM_CONSOLES=$(expr ${NUM_CONSOLES} - 1)
306 [ ${NUM_CONSOLES} -eq 1 ] && NUM_CONSOLES=6
307 CUR_CONSOLE=$(fgconsole)
309 if [ -n "$CHARMAP" ] ; then
310 einfo "Running consolechars for ${CHARMAP}"
311 for vc in `seq 0 ${NUM_CONSOLES}` ; do
312 consolechars --tty=/dev/tty${vc} -m ${CHARMAP} ; RC=$?
314 [ -n "$CUR_CONSOLE" ] && chvt $CUR_CONSOLE
318 if checkbootparam 'noconsolefont' ; then
319 ewarn "Skipping setting console font as requested on boot commandline." ; eend 0
321 if [ -n "$CONSOLEFONT" ] ; then
322 einfo "Running consolechars using ${CONSOLEFONT}"
323 for vc in `seq 0 ${NUM_CONSOLES}` ; do
324 consolechars --tty=/dev/tty${vc} -f $CONSOLEFONT ; RC=$?
326 [ -n "$CUR_CONSOLE" ] && chvt $CUR_CONSOLE
337 if checkbootparam 'hostname' ; then
338 HOSTNAME="$(getbootparam 'hostname' 2>>$DEBUG)"
339 einfo "Setting hostname to $HOSTNAME as requested."
340 sed -i "s/^127.0.0.1.*localhost/127.0.0.1 $HOSTNAME localhost/" /etc/hosts
341 hostname $HOSTNAME ; eend $?
343 hostname --file /etc/hostname
348 # fstabuser (needed when running from harddisk with username != grml {{{
350 [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig
351 if [ -n "$CONFIG_FSTAB_USER" ] ; then
352 fstabuser="$CONFIG_FSTAB_USER"
354 fstabuser=$(getent passwd 1000 | cut -d: -f1)
356 # if not yet set fall back to default 'grml' user
357 [ -n "$fstabuser" ] || fstabuser='grml'
361 # {{{ Set clock (Local time is more often used than GMT, so it is default)
363 # don't touch the files if running from harddisk:
364 if [ -z "$INSTALLED" ]; then
365 # The default hardware clock timezone is stated as representing local time.
367 grep -q "^UTC=" /etc/default/rcS || echo "UTC=no" >> /etc/default/rcS
368 checkbootparam 'utc' >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=yes|" /etc/default/rcS
369 checkbootparam 'gmt' >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=yes|" /etc/default/rcS
370 checkbootparam 'localtime' >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=no|" /etc/default/rcS
371 grep -q -i "^UTC=yes" /etc/default/rcS && UTC="-u"
372 # hwclock uses the TZ variable
373 KTZ="$(getbootparam 'tz' 2>>$DEBUG)"
374 [ -z "$KTZ" ] && [ -r /etc/timezone ] && KTZ=$(cat /etc/timezone)
375 if [ ! -f "/usr/share/zoneinfo/$KTZ" ] ; then
376 ewarn "Warning: unknown timezone $KTZ" ; eend 1
378 ewarn "Falling back to timezone $KTZ" ; eend 0
381 if ! [ -r /dev/rtc ] ; then
382 ewarn "Warning: realtime clock not available, trying to execute hwclock anyway." ; eend 0
385 ERROR=$(TZ="$KTZ" hwclock $UTC -s 2>&1 | head -1) ; RC=$?
386 if [ -n "$ERROR" ] ; then
388 ERROR=$(TZ="$KTZ" hwclock $UTC -s --directisa 2>&1 | head -1)
389 if [ -n "$ERROR" ] ; then
390 eerror "Problem running hwclock: $ERROR" ; eend 1
399 # {{{ print kernel info
401 vmware-detect &>/dev/null && VMWARE="inside ${WHITE}VMware/Qemu${NORMAL}"
402 [ -d /proc/xen ] && VMWARE='' # vmware-detect returns '0' when running with a Xen-enabled kernel
403 einfo "Running Linux Kernel $KERNEL $VMWARE" ; eend 0
404 if [ -r /proc/cpuinfo ] ; then
405 if egrep -q '^flags.*(vmx|svm)' /proc/cpuinfo ; then
407 einfo 'CPU(s) featuring virtualization technology detected' ; eend 0
411 if [ -d /proc/xen ] ; then
413 einfo 'Running kernel featuring support for Xen detected' ; eend 0
419 # {{{ vmware specific stuff
421 if checkbootparam 'novmware' ; then
422 ewarn "Skipping running vmware specific stuff as requested on boot commandline." ; eend 0
424 if [ -z "$INSTALLED" ] ; then
425 if vmware-detect || checkbootparam "BOOT_IMAGE=vmware" ; then
426 if ! checkbootparam 'qemu' ; then
427 if [ -r /etc/X11/xorg.conf.vmware ] ; then
428 einfo "VMware: Copying /etc/X11/xorg.conf.vmware to /etc/X11/xorg.conf"
429 cp /etc/X11/xorg.conf.vmware /etc/X11/xorg.conf ; eend $?
432 elif [ -r /proc/acpi/battery/BAT0/info -a -r /etc/X11/xorg.conf.virtualbox ] ; then
433 if grep -q 'OEM info: innotek' /proc/acpi/battery/BAT0/info ; then
434 einfo 'Virtual Box: Copying /etc/X11/xorg.conf.virtualbox to /etc/X11/xorg.conf'
435 cp /etc/X11/xorg.conf.virtualbox /etc/X11/xorg.conf ; eend $?
443 # {{{ qemu specific stuff
445 if checkbootparam 'qemu' ; then
446 if [ -r /etc/X11/xorg.conf.example ] ; then
447 einfo "Qemu: Copying /etc/X11/xorg.conf.example to /etc/X11/xorg.conf"
448 cp /etc/X11/xorg.conf.example /etc/X11/xorg.conf ; eend $?
454 # {{{ ld.so.cache + depmod
456 if [ -n "$INSTALLED" ]; then
457 if ! [ -r /etc/grml.first.boot ] ; then
458 einfo "Running from HD for the first time, regenerate ld.so.cache and modules.dep:"
460 # Regenerate ld.so.cache and module dependencies on HD
461 einfo "Running ldconfig" ; ldconfig ; eend $?
462 einfo "Running depmod" ; depmod -a ; eend $?
463 touch /etc/grml.first.boot
473 # don't touch the files if running from harddisk:
474 if [ -z "$INSTALLED" ]; then
475 KTZ="$(getbootparam 'tz' 2>>$DEBUG)"
476 if [ -n "$KTZ" ] ; then
477 if [ ! -f "/usr/share/zoneinfo/$KTZ" ]
479 ewarn "Warning: unknown timezone $KTZ"; eend 0
481 einfo "Setting timezone."
483 area=$(echo $KTZ | cut -d '/' -f1)
484 zone=$(echo $KTZ | cut -d '/' -f2)
485 echo "tzdata tzdata/Areas select $area" | debconf-set-selections
486 echo "tzdata tzdata/Zones/$area select $zone" | debconf-set-selections
488 echo $KTZ > /etc/timezone
490 cp "/usr/share/zoneinfo/$KTZ" /etc/localtime ; eend $?
497 # small computer / nearly no ram {{{
500 RAM=$(/usr/bin/gawk '/MemTotal/{print $2}' /proc/meminfo)
501 # MEM=$(/usr/bin/gawk 'BEGIN{m=0};/MemFree|Cached|SwapFree/{m+=$2};END{print m}' /proc/meminfo)
504 if checkbootparam 'small'; then
505 einfo "Information: ${RAM} kB of RAM available." ; eend 0
506 einfo "Bootoption small detected. Activating small system."
507 if [ -r /etc/inittab.small ] ; then
508 mv /etc/inittab /etc/inittab.normal
509 mv /etc/inittab.small /etc/inittab
511 sed -i 's/^9/#&/' /etc/inittab
512 sed -i 's/^10/#&/' /etc/inittab
513 sed -i 's/^11/#&/' /etc/inittab
514 sed -i 's/^12/#&/' /etc/inittab
516 /sbin/telinit q ; eend $?
518 if checkgrmlsmall ; then
519 if [[ $RAM -lt 25000 ]] ; then
520 ewarn "Information: ${RAM} kB of RAM available." ; eend 1
521 ewarn "At least 32MB of RAM should be available for grml-small." ; eend 1
522 ewarn "Use the bootoption small to save some more MB of memory usage." ; eend 0
523 ewarn "Dropping you into a rescue shell. To continue booting exit the shell." ; eend 0
526 einfo "Information: ${RAM} kB of RAM available." ; eend 0
529 if [[ $RAM -lt 58000 ]] ; then
530 ewarn "Information: ${RAM} kB of RAM available." ; eend 1
531 ewarn "At least 64MB of RAM should be available for grml." ; eend 1
532 ewarn "Use the bootoption small to save some more MB of memory usage." ; eend 0
533 ewarn "Dropping you into a rescue shell. To continue booting exit the shell." ; eend 0
536 einfo "Information: ${RAM} kB of RAM available." ; eend 0
544 # skip startup of w3m {{{
546 if checkbootparam 'fast'; then
547 ewarn "Bootoption fast detected. Skipping startup of grml-quickconfig."
548 sed -i 's#^1:.*#1:12345:respawn:/usr/bin/openvt -f -c 1 -w -- /bin/zsh#' /etc/inittab
549 /sbin/telinit q ; eend $?
554 # activate serial console {{{
556 if checkbootparam 'console'; then
557 einfo "Bootoption (for serial) console detected."
559 if [ -r /etc/mgetty/mgetty.config ] ; then
560 MODE=$(getbootparam 'console' | awk -F, '{print $2}')
562 [ -n "$MODE" ] || MODE=9600 # default mode
563 einfo "Setting speed in /etc/mgetty/mgetty.config to $MODE bps"
564 sed -i "s/speed [0-9]*/speed $MODE/" /etc/mgetty/mgetty.config ; eend $?
567 einfo "Activating mgetty."
568 sed -i 's/^#T0/T0/' /etc/inittab
569 sed -i 's/^#T1/T1/' /etc/inittab
570 /sbin/telinit q ; eend $?
576 # For burning on IDE-CD-Roms, k3b (and others) check for special permissions {{{
579 for DEVICE in /proc/ide/hd?; do
580 [ "$(cat $DEVICE/media 2>/dev/null)" = "cdrom" ] && CDROMS="$CDROMS /dev/${DEVICE##*/}"
582 [ -n "$CDROMS" ] && { chown root.cdrom $CDROMS; chmod 666 $CDROMS; } 2>/dev/null
586 # {{{ Bring up loopback interface now
588 if [ -z "$INSTALLED" ] ; then
589 if grep -q 'iface lo inet loopback' /etc/network/interfaces 2>/dev/null ; then
590 grep -q lo=lo /etc/network/run/ifstate 2>/dev/null || ifup lo
598 # firewire devices {{{
599 # the raw1394 driver does not yet export info into SYSFS,
600 # so let's create raw1394 device manually
601 # http://www.michael-prokop.at/blog/index.php?p=352
602 config_firewire_dev(){
603 if checkbootparam 'nofirewiredev' ; then
604 ewarn "Skipping creating some firewire devices as requested on boot commandline." ; eend 0
606 #if [ "${KERNEL%-*}" == "2.6.11" ] ; then
607 einfo "Creating some firewire devices (fix kernel 2.6-bug)."
608 # cd /dev && MAKEDEV video1394 raw1394
609 [ -r /dev/raw1394 ] || mknod /dev/raw1394 c 171 0
610 [ -r /dev/video1394 ] || mknod -m 666 /dev/video1394 c 171 16
611 # mknod -m 666 /dev/dv1394 c 171 32 # for NTSC
612 [ -r /dev/dv1394 ] || mknod -m 666 /dev/dv1394 c 171 34 # for PAL
613 chown -R root:video /dev/raw1394 /dev/video1394 /dev/dv1394
614 chmod -R 664 /dev/raw1394 /dev/video1394 /dev/dv1394 ; eend $?
620 # {{{ copy passwd-lockfile to ramdisk (fix unionfs-behaviour)
621 # otherwise we will get: passwd: Authentication token lock busy
623 if [ -z "$INSTALLED" ] ; then
631 if [ -n "$TESTCD" ]; then
632 einfo "Checking CD data integrity as requested by '${WHITE}testcd${NORMAL}' boot option."
633 einfo "Reading files and checking against GRML/md5sums, this may take a while..."
636 if [ -n "${LIVECD_PATH}"/GRML ] ; then
637 ( cd "${LIVECD_PATH}"/GRML ; rm -f /tmp/md5sum.log ; md5sum -c md5sums 2>&1 | tee /tmp/md5sum.log ; RC=$? )
639 echo "${RED} *** Error: Could not find md5sum file. ***"
642 if [ "$RC" = "0" ]; then
643 einfo "Everything looks OK" ; eend 0
645 eerror 'Checksum failed for theses files:' ; eend 1
646 egrep -v '(^md5sum:|OK$)' /tmp/md5sum.log
647 eerror 'Data on the grml medium is possibly incomplete/damaged or...'
648 eerror '... RAM of your computer is broken.' ; eend 1
649 einfon "Hit return to continue, or press the reset button to quit."
658 # {{{ hardware detection via discover
660 if checkbootparam 'nodisc' ; then
661 ewarn "Skipping hardware detection via discover as requested on boot commandline." ; eend 0
663 if [ -x /sbin/discover ] ; then
664 einfo "Discovering hardware. Trying to load the following modules in background:"
666 einfo "$(discover --data-path=linux/module/name --data-path=linux/modules/options --format="%s %s" --data-version=`uname -r` --enable-bus all | sort -u | xargs echo)"
668 /sbin/discover-modprobe -v 1>>$DEBUG 2>&1 &
671 eerror "Application discover not available. Information: udev should handle hardware recognition." ; eend 0
677 # {{{ hardware detection via hwinfo
679 if checkbootparam 'hwinfo' >>$DEBUG 2>&1; then
680 einfo "Discovering hardware via hwinfo:"
681 MODULES=$(su grml hwinfo | grep "Cmd: \"modprobe" | awk '{print $5}' | sed 's/"//')
682 echo -n " Loading modules: "
683 for i in `echo $MODULES` ; do echo -n $i && modprobe $i ; done
689 # {{{ disable hotplug agents on request
690 config_hotplug_agent(){
691 if checkbootparam 'noagent' ; then
692 AGENT="$(getbootparam 'noagent' 2>>$DEBUG)"
693 AGENTLIST=$(echo "$AGENT" | sed 's/,/\\n/g')
694 AGENTNL=$(echo "$AGENT" | sed 's/,/ /g')
695 einfo "Disabling hotplug-agent(s) $AGENTNL"
696 for agent in $(echo -e $AGENTLIST) ; do
697 mv /etc/hotplug/${agent}.rc /etc/hotplug/${agent}.norc
699 [ "$?" == "0" ] ; eend $?
704 # {{{ blacklist of hotplug-modules
705 config_hotplug_blacklist(){
706 if checkbootparam 'black' ; then
707 BLACK="$(getbootparam 'black' 2>>$DEBUG)"
708 BLACKLIST=$(echo "$BLACK" | sed 's/,/\\n/g')
709 BLACKNL=$(echo "$BLACK" | sed 's/,/ /g')
710 einfo "Blacklisting $BLACKNL via /etc/hotplug/blacklist.d/hotplug-light"
711 echo -e "$BLACKLIST" >> /etc/hotplug/blacklist.d/hotplug-light
712 echo -e "$BLACKLIST" >> /etc/hotplug/blacklist
720 if checkbootparam 'nohotplug' ; then
721 ewarn "Skipping running hotplug as requested on boot commandline." ; eend 0
723 if [ -r /etc/init.d/hotplug ] ; then
724 einfo "Starting hotplug system in background."
725 /etc/init.d/hotplug start 1>>$DEBUG 2>>$DEBUG &
727 elif [ -r /etc/init.d/hotplug-light ] ; then
728 einfo "Starting hotplug-light system in background."
729 /etc/init.d/hotplug-light start 1>>$DEBUG 2>>$DEBUG &
732 ewarn "No hotplug system found. Should be handled by udev. Skipping execution." ; eend 0
738 # {{{ blacklist specific module [ used in /etc/init.d/udev ]
740 if checkbootparam 'blacklist' ; then
741 if [ -z "$INSTALLED" ]; then
742 einfo "Bootoption blacklist found."
743 BLACK="$(getbootparam 'blacklist' 2>>$DEBUG)"
744 BLACKLIST_FILE='/etc/modprobe.d/grml.conf'
745 if [ -n "$BLACK" ] ; then
746 for module in $(echo ${BLACK//,/ }) ; do
747 einfo "Blacklisting module ${module} via ${BLACKLIST_FILE}."
748 echo "# begin entry generated by config_blacklist of grml-autoconfig" >> "$BLACKLIST_FILE"
749 echo "blacklist $module" >> "$BLACKLIST_FILE"
750 echo "alias $module off" >> "$BLACKLIST_FILE"
751 echo "# end entry generated by config_blacklist of grml-autoconfig" >> "$BLACKLIST_FILE" ; eend $?
754 eerror "No given module for blacklist found. Blacklisting will not work therefore."
757 ewarn "Backlisting via bootoption is not intended for use on harddisk installations." ; eend 1
759 einfo "Please blacklist the module(s) manually using the 'blacklist' script."
768 if [ -d /proc/acpi ]; then
769 if checkbootparam 'noacpi'; then
770 ewarn "Skipping ACPI Bios detection as requested via noacpi on boot commandline." ; eend 0
771 elif checkbootparam 'nogrmlacpi' ; then
772 ewarn "Skipping ACPI Bios detection as requested via nogrmlacpi on boot commandline." ; eend 0
774 einfo "ACPI Bios found, activating modules (disable via bootoption noacpi / nogrmlacpi): "
777 for a in /lib/modules/$KERNEL/kernel/drivers/acpi/*; do
779 basename="${basename%%.*}"
780 case "$basename" in *_acpi)
781 egrep -qi "${basename%%_acpi}" /proc/acpi/dsdt 2>>$DEBUG || continue ;;
783 modprobe $basename >>$DEBUG 2>&1 && found="yes"
784 local BASE="$BASE $basename"
786 if [ -n "$found" ] ; then
787 einfo "$BASE" ; eend 0
789 ewarn "(none)" ; eend 1
791 if ! ps x | grep -q /usr/sbin/acpid ; then
792 if ! [ -r /var/run/dbus/pid ] ; then
793 einfo "Starting acpi daemon."
794 /etc/init.d/acpid start 1>>$DEBUG 2>&1 ; eend $?
796 eerror "acpid error: it seems you are running d-bus/hal, but acpid needs to be started before d-bus."
797 eerror "Solution: please activate acpid via /etc/runlevel.conf"
801 ewarn "acpi daemon already running."
808 if checkbootparam 'noapm'; then
809 ewarn "Skipping APM Bios detection as requested on boot commandline." ; eend 0
811 modprobe apm power_off=1 >>$DEBUG 2>&1
812 if [ "$?" = "0" ] ; then
813 if [ -x /etc/init.d/apmd ] ;then
814 einfo "APM Bios found, enabling power management functions."
815 /etc/init.d/apmd start ; eend $?
818 eerror "Loading apm module failed." ; eend 1
825 # {{{ PCMCIA Check/Setup
826 # This needs to be done before other modules are being loaded (by hwsetup)
828 if checkbootparam 'nopcmcia'; then
829 ewarn "Skipping PCMCIA detection as requested on boot commandline." ; eend 0
831 if /usr/sbin/laptop-detect ; then
832 einfo "Detected Laptop - checking for PCMCIA." && eend 0
833 modprobe pcmcia_core >>$DEBUG 2>&1
834 # Try Cardbus or normal PCMCIA socket drivers
835 modprobe yenta_socket >>$DEBUG 2>&1 || modprobe i82365 >>$DEBUG 2>&1 || modprobe pd6729 >>$DEBUG 2>&1 || modprobe tcic >>$DEBUG 2>&1
836 if [ "$?" = "0" ]; then
837 modprobe ds >>$DEBUG 2>&1
838 if [ -d /proc/bus/pccard ] ; then
839 if [ -x /sbin/cardmgr ] ; then
840 einfo "PCMCIA found, starting cardmgr."
841 cardmgr >>$DEBUG 2>&1 && sleep 6 && eend 0
843 eerror "No cardmgr found. Make sure package pcmciautils is installed, it should handle it instead." ; eend 1
852 # {{{ run software synthesizer via speakup
854 if checkbootparam 'swspeak' ; then
855 einfo "Bootoption swspeak found."
857 if [ ! -d /proc/speakup/ ] && ! grep -q speakup_soft /proc/modules ; then
858 ewarn "Kernel does not support software speakup - trying to load kernel module:" ; eend 0
860 einfo "Loading speakup_soft"
861 if modprobe speakup_soft ; then
864 flitewrapper "Fatal error setting up software speakup"
871 if [ -d /proc/speakup/ ] || grep -q speakup_soft /proc/modules ; then
872 einfo "Kernel supports speakup." ; eend 0
874 einfo "Just run swspeak if you want to use software synthesizer via speakup."
875 flitewrapper "Finished activating software speakup. Just run swspeak when booting finished."
878 eerror "Kernel does not seem to support speakup. Skipping swspeak." ; eend 1
879 flitewrapper "Kernel does not seem to support speakup. Sorry."
885 # {{{ support hardware synthesizer via speakup
887 if checkbootparam 'speakup.synth' ; then
888 einfo "Bootoption speakup.synth found."
891 module="$(getbootparam 'speakup.synth' 2>>$DEBUG)"
892 if [ -z "$module" ] ; then
893 eerror "Sorry, no speakup module specified for bootoption speakup.synth."
894 flitewrapper "Sorry, no speakup module specified for bootoption speakup.synth."
896 einfo "Trying to load $module"
897 modprobe "speakup_${module}"
901 if [ -d /proc/speakup/ ] || grep -q speakup /proc/modules ; then
902 einfo "Kernel should support speakup now." ; eend 0
903 flitewrapper "Kernel should support speakup now."
905 eerror "Kernel or hardware do not seem to support speakup. Skipping hwspeak." ; eend 1
906 flitewrapper "Kernel or hardware do not seem to support speakup. Sorry."
912 elif checkbootparam 'hwspeak' ; then
913 einfo "Bootoption hwspeak found."
915 if [ ! -d /proc/speakup/ ] && ! grep -q speakup /proc/modules ; then
916 ewarn "Kernel does not support hardware speakup - trying to load kernel modules:" ; eend 0
918 if ! [ -d "/lib/modules/${KERNEL}/extra/speakup/" ] ; then
919 eerror "Kernel does not provide speakup modules, sorry." ; eend 1
921 for module in $(find "/lib/modules/${KERNEL}/extra/speakup/" -name \*.ko | \
922 sed 's#.*speakup/##g ; s#.ko$##g' | \
923 grep -ve speakup_soft -ve speakup_dummy | sort -u) ; do
924 einfo "Trying to load $module"
932 if [ -d /proc/speakup/ ] || grep -q speakup /proc/modules ; then
933 einfo "Kernel should support speakup now." ; eend 0
934 flitewrapper "Kernel should support speakup now."
936 eerror "Kernel or hardware do not seem to support speakup. Skipping hwspeak." ; eend 1
937 flitewrapper "Kernel or hardware do not seem to support speakup. Sorry."
943 # {{{ Check for blind option or brltty
946 checkbootparam 'blind' && BLIND="yes"
947 BRLTTY="$(getbootparam 'brltty' 2>>$DEBUG)"
949 if [ -n "$BLIND" -o -n "$BRLTTY" ]; then
950 if [ -x /sbin/brltty ]; then
951 # Blind option detected, start brltty now.
952 # modprobe serial_core parport_serial generic_serial && echo "done"
957 if [ -n "$BRLTTY" ]; then
959 BRLTYPE="${BRLTTY%%,*}"
961 if [ -n "$R" -a "$R" != "$BRLTTY" ]; then
963 BRLDEV="${BRLTTY%%,*}"
965 if [ -n "$R" -a "$R" != "$BRLTTY" ]; then
967 BRLTEXT="${BRLTTY%%,*}"
972 [ -n "$BRLTYPE" ] && CMD="$CMD -b $BRLTYPE"
973 [ -n "$BRLDEV" ] && CMD="$CMD -d $BRLDEV"
974 [ -n "$BRLTEXT" ] && CMD="$CMD -t $BRLTEXT"
975 einfo "Starting braille-display manager."
978 sleep 2 && BLINDSOUND="yes"
985 # {{{ Interactive configuration
986 config_interactive(){
987 ewarn "config_interactive is deprecated nowadays."
988 ewarn "Please set CONFIG_INTERACTIVE='no' in /etc/grml/autoconfig" ; eend 0
994 if checkbootparam 'forceagp' ; then
995 # Probe for AGP. Hope this can fail safely
996 grep -q "AGP" "/proc/pci" 2>>$DEBUG && { modprobe agpgart || modprobe agpgart agp_try_unsupported=1; } >>$DEBUG 2>&1 && einfo "AGP bridge detected." ; eend 0
1002 config_automounter(){
1003 if checkbootparam 'automounter' ; then
1004 RUNLEVEL="$(runlevel)"
1006 [ -x /etc/init.d/autofs ] && [ "$RUNLEVEL" != "N 1" ] && [ "$RUNLEVEL" != "N S" ] && AUTOMOUNTER="yes"
1011 if [ -n "$AUTOMOUNTER" ]; then
1012 [ -d "/mnt/$d" -a ! -L "/mnt/$d" ] && rmdir /mnt/$d
1013 [ -d "/mnt/auto/$d" ] || mkdir -p "/mnt/auto/$d"
1014 [ -L "/mnt/$d" ] || ln -s "/mnt/auto/$d" "/mnt/$d"
1015 anew="$d -fstype=auto,$2 :$i"
1016 grep -q "$anew" "/etc/auto.mnt" || echo "$anew" >> /etc/auto.mnt
1017 AUTOMOUNTS="$AUTOMOUNTS $d"
1018 new="$1 /mnt/auto/$d auto users,noauto,exec,$2 0 0"
1020 [ -d /mnt/$d ] && mkdir -p /mnt/$d
1021 new="$1 /mnt/$d auto users,noauto,exec,$2 0 0"
1023 grep -q "$new" "/etc/fstab" || echo "$new" >> /etc/fstab
1026 AUTOMOUNTS="floppy cdrom"
1027 # Add new devices to /etc/fstab and /etc/auto.mnt
1028 for i in /dev/cdrom?*; do
1030 addautomount "$i" "ro"
1035 if [ -n "$AUTOMOUNTER" ]; then
1036 # Check for floppy dir, reinstall with automounter
1037 [ -d /mnt/floppy -a ! -L /mnt/floppy ] && rmdir /mnt/floppy
1038 [ -d /mnt/auto/floppy ] || mkdir -p /mnt/auto/floppy
1039 [ -L /mnt/floppy ] || ln -s /mnt/auto/floppy /mnt/floppy
1040 [ -d /mnt/cdrom -a ! -L /mnt/cdrom ] && rmdir /mnt/cdrom
1041 [ -d /mnt/auto/cdrom ] || mkdir -p /mnt/auto/cdrom
1042 [ -L /mnt/cdrom ] || ln -s /mnt/auto/cdrom /mnt/cdrom
1043 rm -f /etc/fstab.new
1044 # Replace paths from bootfloppy
1045 sed 's|/mnt/cdrom|/mnt/auto/cdrom|g;s|/mnt/floppy|/mnt/auto/floppy|g' /etc/fstab > /etc/fstab.new
1046 mv -f /etc/fstab.new /etc/fstab
1047 # Start automounter now
1048 einfo "Starting automounter for ${AUTOMOUNTS}."
1049 /etc/init.d/autofs start >>$DEBUG ; eend $?
1054 # {{{ Collect partitions from /proc/partitions first for enabling DMA
1058 while read major minor blocks partition relax; do
1059 partition="${partition##*/}"
1060 [ -z "$partition" -o ! -e "/dev/$partition" ] && continue
1061 case "$partition" in
1062 hd?) IDEDISKS="$IDEDISKS $partition";; # IDE Harddisk, entire disk
1063 sd?) ;; # SCSI Harddisk, entire disk
1064 # [hs]d*) partitions="$partitions /dev/$partition";; # IDE or SCSI disk partition
1065 [hs]d*|ub*) partitions="$partitions /dev/$partition";; # IDE, USB or SCSI disk partition
1068 $(awk 'BEGIN{old="__start"}{if($0==old){exit}else{old=$0;if($4&&$4!="name"){print $0}}}' /proc/partitions)
1071 check_partitions 1>/dev/null 2>&1 # avoid output "check_partitions:3: read-only file system"
1074 # {{{ Enable DMA for all IDE drives now if not disabled
1075 # Notice: Already done by linuxrc, but make sure it's done also on harddisk-installed systems
1077 if checkbootparam 'nodma'; then
1078 ewarn "Skipping DMA accelleration as requested on boot commandline." ; eend 0
1080 for d in $(cd /proc/ide 2>>$DEBUG && echo hd[a-z]); do
1081 if test -d /proc/ide/$d; then
1082 if egrep -q 'using_dma[ \t]+0' /proc/ide/$d/settings 2>>$DEBUG; then
1083 MODEL="$(cat /proc/ide/$d/model 2>>$DEBUG)"
1084 test -z "$MODEL" && MODEL="[GENERIC IDE DEVICE]"
1085 einfo "Enabling DMA acceleration for: ${WHITE}$d ${YELLOW}[${MODEL}]${NORMAL}"
1086 echo "using_dma:1" >/proc/ide/$d/settings
1095 # {{{ Start creating /etc/fstab with HD partitions and USB SCSI devices now
1098 NOSWAP="yes" # we do not use swap by default!
1099 if checkbootparam 'swap' || checkbootparam 'anyswap' ; then
1101 checkbootparam 'anyswap' && export ANYSWAP='yes' || export ANYSWAP=""
1104 if checkbootparam 'nofstab' || checkbootparam 'forensic' ; then
1105 ewarn "Skipping /etc/fstab creation as requested on boot commandline." ; eend 0
1107 einfo "Scanning for harddisk partitions and creating /etc/fstab. (Disable this via boot option: nofstab)"
1108 iszsh && setopt nonomatch
1109 if [ -x /usr/sbin/rebuildfstab ] ; then
1110 config_userfstab || fstabuser=grml
1111 /usr/sbin/rebuildfstab -r -u $fstabuser -g $fstabuser ; eend $?
1113 ewarn "Command rebuildfstab not found. Install package grml-rebuildfstab." ; eend 1
1115 fi # checkbootparam nofstab/forensic
1117 # Scan for swap, config, homedir - but only in live-mode
1118 if [ -z "$INSTALLED" ] ; then
1119 [ -z "$NOSWAP" ] && einfo "Searching for swap partition(s) as requested."
1122 HOMEDIR="$(getbootparam 'home')"
1123 if [ -n "$partitions" ]; then
1124 while read p m f relax; do
1125 case "$p" in *fd0*|*proc*|*sys*|*\#*) continue;; esac
1126 partoptions="users,exec"
1128 # it's a swap partition?
1131 if [ -n "$NOSWAP" ]; then
1132 ewarn "Ignoring swap partition ${WHITE}$p${NORMAL}. (Force usage via boot option 'swap', or execute grml-swapon)"
1135 case "$(dd if=$p bs=1 count=6 skip=4086 2>/dev/null)" in
1136 S1SUSP|S2SUSP|pmdisk|[zZ]*)
1137 if [ -n "$ANYSWAP" ] ; then
1138 einfo "Using swap partition ${WHITE}${p}${NORMAL} [bootoption anyswap found]."
1139 swapon $p 2>>$DEBUG ; eend $?
1141 ewarn "Suspend signature on ${WHITE}${p}${NORMAL} found, not using as swap. (Force usage via boot option: anyswap)"
1145 if [[ "$p" == LABEL* ]] ; then
1146 p=$(blkid -t $p | awk -F: '{print $1}')
1148 if grep -q $p /proc/swaps ; then
1149 ewarn "Not using swap partition ${WHITE}${p}${NORMAL} as it is already in use." ; eend 0
1151 if [ -b "$p" ] ; then
1152 einfo "Using swap partition ${WHITE}${p}${NORMAL}."
1153 swapon $p 2>>$DEBUG ; eend $?
1155 ewarn "$p is not a valid block device - not using it therefore." ; eend 0
1164 esac # it's a swap partition?
1169 vfat|msdos|ntfs) MOUNTOPTS="$MOUNTOPTS,uid=${fstabuser},gid=${fstabuser}" ;;
1170 ext2|ext3|reiserfs|jfs|reiser4|xfs) MOUNTOPTS="$MOUNTOPTS,noatime" ;;
1172 # *) NONEFOUND='1'; continue ;;
1176 if [ -z "$NOSWAP" ] ; then
1177 mount -o "$MOUNTOPTS" -t $f $p $m 2>>$DEBUG && MOUNTED=1 || continue
1178 # Activate swapfile, if exists
1179 SWAPFILE="$(/bin/ls -1d $m/[Gg][Rr][Mm][Ll].[Ss][Ww][Pp] 2>/dev/null)"
1181 if [ -z "$NOSWAP" -a -n "$SWAPFILE" -a -f "$SWAPFILE" ]; then
1182 mount -o remount,rw $m && MOUNTED=1
1183 if swapon "$SWAPFILE" 2>>$DEBUG ; then
1185 einfo "Using GRML swapfile ${WHITE}${SWAPFILE}${NORMAL}."
1187 fnew="$SWAPFILE swap swap defaults 0 0"
1188 grep -q "$fnew" "/etc/fstab" || echo "$fnew" >> /etc/fstab
1189 GRML_SWP="$GRML_SWP $SWAPFILE"
1192 mount -o remount,ro $m 2>>$DEBUG && MOUNTED=1
1195 # use a image as home
1196 IMAGE="$(/bin/ls -1d $m/[Gg][Rr][Mm][Ll].[Ii][Mm][Gg] 2>/dev/null)"
1197 if [ -z "$GRML_IMG" -a -n "$IMAGE" -a -f "$IMAGE" ]; then
1198 if [ -n "$HOMEDIR" ]; then
1199 if [ "$HOMEDIR" != "scan" -a "$HOMEDIR" != "$IMAGE" -a "$HOMEDIR" != "${IMAGE%/*.*}" ]; then
1203 if type -a grml-image >/dev/null 2>&1 && grml-image "$IMAGE" </dev/console >/dev/console 2>&1; then
1205 mount -o remount,ro $m 2>>$DEBUG && MOUNTED=1
1210 # Umount, if not in use
1211 [ -n "$MOUNTED" ] && umount -r $m 2>/dev/null
1223 if [ -n "$MOUSE_DEVICE" ] ; then
1224 einfo "Detecting mouse: ${MOUSE_FULLNAME} at ${MOUSE_DEVICE}" ; eend $?
1229 # {{{ IPv6 configuration
1230 # Load IPv6 kernel module and print IP adresses
1232 if checkbootparam 'ipv6'; then
1233 einfo "Enabling IPv6 as requested on boot commandline (sleeping for 2 seconds)"
1235 # we probably need some time until stateless autoconfiguration has happened
1237 NETDEVICES="$(awk -F: '/eth.:|tr.:|wlan.:/{print $1}' /proc/net/dev 2>>$DEBUG)"
1238 for DEVICE in `echo "$NETDEVICES"`; do
1241 ADDRESSES="$(ifconfig $DEVICE | awk '/.*inet6 addr:.*/{print $3}')"
1242 COUNT="$(ifconfig $DEVICE | awk '/.*inet6 addr:.*/{ sum += 1};END {print sum }')"
1244 for ADDR in `echo "$ADDRESSES"` ; do
1247 if [ "$COUNT" -eq "0" ] ; then
1248 einfo "(none)" ; eend 1
1258 # {{{ Fat-Client-Version: DHCP Broadcast for IP address
1260 if checkbootparam 'nodhcp'; then
1261 ewarn "Skipping DHCP broadcast/network detection as requested on boot commandline." ; eend 0
1263 NETDEVICES="$(awk -F: '/eth.:|tr.:|wlan.:/{print $1}' /proc/net/dev 2>>$DEBUG)"
1264 rm -rf /etc/network/status ; mkdir -p /etc/network/status
1265 for DEVICE in `echo "$NETDEVICES"` ; do
1266 einfo "Network device ${WHITE}${DEVICE}${NORMAL} detected, DHCP broadcasting for IP. (Backgrounding)"
1268 ifconfig $DEVICE up >>$DEBUG 2>&1
1269 ( pump -i $DEVICE >>$DEBUG 2>&1 && echo finished_running_pump > /etc/network/status/$DEVICE ) &
1274 if [ -n "$INSTALLED" ] ; then
1275 ewarn 'If you want to disable automatic DHCP requests set CONFIG_DHCP=no in /etc/grml/autoconfig.'
1282 # {{{ helper functions
1285 # search all partitions for a file in the root directory
1286 for i in /mnt/[sh]d[a-z] /mnt/[sh]d[a-z][1-9] /mnt/[sh]d[a-z][1-9]?*; do
1287 # See if it's already mounted
1288 [ -f "$i/$1" ] && { echo "$i/$1"; return 0; }
1289 if [ -d "$i" ] && mount -r "$i" 2>>$DEBUG; then
1290 [ -f "$i/$1" ] && FOUND="$i/$1"
1291 umount -l "$i" 2>>$DEBUG
1292 [ -n "$FOUND" ] && { echo "$FOUND"; return 0; }
1299 case "$(file -s $1)" in
1300 *[Ff][Aa][Tt]*|*[Xx]86*) echo "vfat"; return 0;;
1301 *[Rr][Ee][Ii][Ss][Ee][Rr]*) echo "reiserfs"; return 0;;
1302 *[Xx][Ff][Ss]*) echo "xfs"; return 0;;
1303 *[Ee][Xx][Tt]3*) echo "ext3"; return 0;;
1304 *[Ee][Xx][Tt]2*) echo "ext2"; return 0;;
1305 *data*) echo "invalid"; return 0;;
1306 *) echo "auto"; return 0;;
1310 # Try to mount this filesystem read-only, without or with encryption
1312 # Check if already mounted
1313 case "$(cat /proc/mounts)" in *\ $2\ *) return 0;; esac
1314 # Apparently, mount-aes DOES autodetect AES loopback files.
1315 [ -b "$1" ] && { mount -t auto -o ro "$1" "$2" 2>>$DEBUG; RC="$?"; }
1316 # We need to mount crypto-loop files with initial rw support
1317 [ -f "$1" ] && { mount -t auto -o loop,rw "$1" "$2" 2>>$DEBUG; RC="$?"; }
1319 [ "$RC" = "0" ] && return 0
1321 einfo "Filesystem not autodetected, trying to mount $1 with AES256 encryption."
1323 while [ "$a" != "n" -a "$a" != "N" ]; do
1324 # We need to mount crypto-loop files with initial rw support
1325 mount -t auto -o loop,rw,encryption=AES256 "$1" "$2" && return 0
1326 echo -n "${RED}Mount failed, retry? [Y/n] ${NORMAL}"
1327 # Problem with ioctl() from getpasswd()?
1337 if checkbootparam 'nocpu'; then
1338 ewarn "Skipping CPU detection as requested on boot commandline." ; eend 0
1340 # check module dependencies
1342 if ! [ -e /lib/modules/${KERNEL}/kernel/arch/x86/kernel/cpu/cpufreq ] ; then
1343 if [ -e /lib64 ] ; then
1344 [ -e /lib/modules/${KERNEL}/kernel/arch/x86_64/kernel/cpufreq ] || return 1
1346 [ -e /lib/modules/${KERNEL}/kernel/arch/i386/kernel/cpu/cpufreq -o ! -e /lib/modules/${KERNEL}/kernel/drivers/cpufreq ] || return 1
1351 if [[ `grep -c processor /proc/cpuinfo` -gt 1 ]] ; then
1352 einfo "Detecting CPU:"
1353 CPU=$(awk -F: '/^processor/{printf " Processor"$2" is"};/^model name/{printf $2};/^vendor_id/{printf vendor};/^cpu MHz/{printf " %dMHz",int($2)};/^cache size/{printf ","$2" Cache"};/^$/{print ""}' /proc/cpuinfo 2>>$DEBUG)
1354 echo $CPU | sed 's/ \{1,\}/ /g'
1357 einfo "Detecting CPU: `awk -F: '/^processor/{printf " Processor"$2" is"};/^model name/{printf $2};/^vendor_id/{printf vendor};/^cpu MHz/{printf " %dMHz",int($2)};/^cache size/{printf ","$2" Cache"};/^$/{print ""}' /proc/cpuinfo 2>>$DEBUG` " ; eend 0
1360 # Disclaimer: sorry for the tons of if/then/else... but this makes sure we use:
1361 # * it only if we have the according kernel modules available
1362 # * cpufreq only on laptops (check via /usr/sbin/laptop-detect) and not inside Virtual Box
1363 # * current version of /etc/init.d/loadcpufreq from Debian (to stay in sync)
1364 # -> parse output of the initscript and output it according to our look'n'feel
1365 # * our own cpufreq-detect.sh if /etc/init.d/loadcpufreq isn't present
1366 if ! cpufreq_check ; then
1367 ewarn "Skipping cpufreq setup as module dependencies are not fulfilled." ; eend 1
1369 if /usr/sbin/laptop-detect 1>/dev/null 2>&1 ; then
1370 # Virtual Box supports ACPI and laptop-detect returns with '0', so check for it:
1371 if [ -r /proc/acpi/battery/BAT0/info ] ; then
1372 if grep -q 'OEM info: innotek' /proc/acpi/battery/BAT0/info ; then
1373 einfo 'Virtual Box detected, skipping cpufreq setup.' ; eend 0
1377 einfo "Detected Laptop - trying to use cpu frequency scaling:"
1379 if [ -x /etc/init.d/loadcpufreq ] ; then
1380 SKIP_CPU_GOVERNOR=''
1381 LOADCPUFREQ=$(mktemp)
1382 /etc/init.d/loadcpufreq start >"$LOADCPUFREQ" 2>&1 ; RC=$?
1383 if grep -q FATAL "$LOADCPUFREQ" ; then
1389 for line in $(grep FATAL "$LOADCPUFREQ" | sed 's/.*FATAL: //; s/ (.*)//') ; do
1390 eerror "$line" ; eend $RC
1394 elif grep -q done "$LOADCPUFREQ" ; then
1395 MODULE=$(grep done "$LOADCPUFREQ" | sed 's/.*done (\(.*\))./\1/')
1396 if [ -n "$MODULE" -a "$MODULE" != none ]; then
1397 einfo "Loading cpufreq kernel module $MODULE" ; eend 0
1399 ewarn "Could not find an appropriate kernel module for cpu frequency scaling." ; eend 1
1403 elif [ -r /usr/bin/cpufreq-detect.sh ] ; then
1404 . /usr/bin/cpufreq-detect.sh
1405 if [ -n "$MODULE" -a "$MODULE" != none ]; then
1406 einfo "Loading modules ${MODULE}"
1407 modprobe "$MODULE" 1>>$DEBUG || modprobe "$MODULE_FALLBACK" 1>>$DEBUG
1409 if [[ $RC == 0 ]]; then
1416 ewarn "Could not detect an appropriate CPU for use with cpu frequency scaling - skipping." && eend 1
1420 if [ -z "$SKIP_CPU_GOVERNOR" ] ; then
1421 einfo "Loading cpufreq_ondemand, setting ondemand governor"
1422 if modprobe cpufreq_ondemand ; RC=$? ; then
1423 for file in $(find /sys/devices/system/cpu/ -name scaling_governor 2>/dev/null) ; do
1424 echo ondemand > $file
1434 fi # checkbootparam nocpu
1438 # {{{ autostart of ssh
1440 if checkbootparam 'ssh' ; then
1442 SSH_PASSWD="$(getbootparam 'ssh' 2>>$DEBUG)"
1443 einfo "Bootoption ssh found, trying to set password for user grml."
1445 if [ -z "$SSH_PASSWD" ] ; then
1446 if [ -x /usr/bin/apg ] ; then
1447 SSH_PASSWD="$(apg -M NL -a 0 -m 8 -x 12 -n 1)"
1448 elif [ -x /usr/bin/gpw ] ; then
1449 SSH_PASSWD="$(gpw 1)"
1450 elif [ -x /usr/bin/pwgen ] ; then
1451 SSH_PASSWD="$(pwgen -1 8)"
1452 elif [ -x /usr/bin/hexdump ] ; then
1453 SSH_PASSWD="$(dd if=/dev/urandom bs=14 count=1 2>/dev/null | hexdump | awk '{print $3 $4}')"
1454 elif [ -n "$RANDOM" ] ; then
1455 SSH_PASSWD="grml${RANDOM}"
1458 eerror "Empty passphrase and neither pwgen nor hexdump nor \$RANDOM found. Skipping."
1462 if [ -n "$SSH_PASSWD" ] ; then
1463 ewarn "No given password for ssh found. Using random password: $SSH_PASSWD" ; eend 0
1468 # finally check if we have a password we can use:
1469 if [ -n "$SSH_PASSWD" ] ; then
1470 # chpasswd sucks, seriously.
1471 if chpasswd --help 2>&1 | grep -q -- '-m,' ; then
1472 echo "grml:$SSH_PASSWD" | chpasswd -m
1474 echo "grml:$SSH_PASSWD" | chpasswd
1478 einfo 'Starting secure shell server in background.'
1479 /etc/init.d/rmnologin start 1>>$DEBUG 2>>$DEBUG
1480 /etc/init.d/ssh start 1>>$DEBUG 2>>$DEBUG &
1484 ewarn 'Warning: please change the password for user grml as soon as possible!'
1490 # {{{ set password for user grml
1492 if checkbootparam 'passwd' >>$DEBUG 2>&1; then
1493 einfo "Bootoption passwd found."
1494 PASSWD="$(getbootparam 'passwd' 2>>$DEBUG)"
1495 if [ -n "$PASSWD" ] ; then
1496 echo "grml:$PASSWD" | chpasswd -m ; eend $?
1498 eerror "No given password for ssh found. Autostart of SSH will not work." ; eend 1
1501 ewarn "Warning: please change the password for user grml set via bootparameter as soon as possible!"
1507 # {{{ Check for persistent homedir option and eventually mount /home from there, or use a loopback file.
1509 if checkbootparam 'home' ; then
1510 HOMEDIR="$(getbootparam 'home')"
1514 if [ -n "$HOMEDIR" ]; then
1515 einfo "Bootoption home detected." && eend 0
1518 MYHOMEDEVICE="${HOMEDIR##/dev/}"
1519 MYHOMEDEVICE="/dev/${MYHOMEDEVICE%%/*}"
1520 MYHOMEMOUNTPOINT="/mnt/${MYHOMEDEVICE##/dev/}"
1521 MYHOMEDIR="/mnt/${HOMEDIR##/dev/}"
1524 MYHOMEDEVICE="${HOMEDIR##/mnt/}"
1525 MYHOMEDEVICE="/dev/${MYHOMEDEVICE%%/*}"
1526 MYHOMEMOUNTPOINT="/mnt/${MYHOMEDEVICE##/dev/}"
1527 MYHOMEDIR="$HOMEDIR"
1529 [Aa][Uu][Tt][Oo]|[Ss][Cc][Aa][Nn]|[Ff][Ii][Nn][Dd])
1530 MYHOMEDIR="$(findfile grml.img)"
1531 MYHOMEDEVICE="${MYHOMEDIR##/mnt/}"
1532 MYHOMEDEVICE="/dev/${MYHOMEDEVICE%%/*}"
1533 MYHOMEMOUNTPOINT="/mnt/${MYHOMEDEVICE##/dev/}"
1536 eerror "Invalid home= option '$HOMEDIR' specified (must start with /dev/ or /mnt/ or 'scan')." ; eend 1
1537 eerror "Option ignored." ; eend 1
1542 if [ -n "$MYHOMEDIR" ]; then
1543 if trymount "$MYHOMEDEVICE" "$MYHOMEMOUNTPOINT"; then
1544 [ -f "$MYHOMEMOUNTPOINT/grml.img" ] && MYHOMEDIR="$MYHOMEMOUNTPOINT/grml.img"
1545 while read device mountpoint fs relax; do
1546 case "$mountpoint" in *$MYHOMEMOUNTPOINT*)
1549 umount "$MYHOMEMOUNTPOINT"; eerror "Error: will not mount NTFS filesystem on $MYHOMEDEVICE read/write!" ; eend 1
1553 # Note: This currently won't work with encrypted partitions
1554 umount "$MYHOMEMOUNTPOINT"; mount -t vfat -o rw,uid=grml,gid=grml,umask=002 "$MYHOMEDEVICE" "$MYHOMEMOUNTPOINT"
1555 if [ ! -f "$MYHOMEDIR" ]; then
1556 ewarn "WARNING: FAT32 is not a good filesystem option for /home/grml (missing socket/symlink support)."
1557 ewarn "WARNING: Better use an ext2 loopback file on this device, and boot with home=$MYHOMEDEVICE/grml.img."
1562 if mount -o remount,rw "$MYHOMEMOUNTPOINT"; then
1563 einfo "Mounting ${WHITE}$MYHOMEDIR${NORMAL} as ${WHITE}/home/grml${NORMAL}."
1564 if [ -f "$MYHOMEDIR" ]; then
1565 # It's a loopback file, mount it over the /home/grml directory
1566 trymount "$MYHOMEDIR" /home/grml
1568 [ "$RC" = "0" ] && ERROR="$(mount -o remount,rw /home/grml 2>&1)"
1572 ERROR="$(mount --bind "$MYHOMEDIR" /home/grml 2>&1)"
1576 [ "$RC" = "0" ] && eend 0 || ( eerror "${ERROR}" ; eend 1 )
1578 fi # mount -o remount,rw,...
1581 esac # case "$mountpoint" in *$MYHOMEMOUNTPOINT*)
1585 fi # if trymount ...
1587 fi # checkbootparam home
1593 if ! [ -x /usr/bin/aumix ] ; then
1594 eerror "aumix binary not available. Can not set sound volumes therefore." ; eend 1
1597 if ! [ -r /proc/asound/cards ] ; then
1598 ewarn "No soundcard present, skipping mixer settings therefore." ; eend 0
1602 if checkbootparam 'vol' ; then
1603 VOL="$(getbootparam 'vol' 2>>$DEBUG)"
1604 if [ -z "$VOL" ] ; then
1605 eerror "Bootoption vol found but no volume level/parameter given. Using defaults." ; eend 1
1612 if checkbootparam 'nosound' ; then
1613 einfo "Muting sound devices on request."
1614 # some IBM notebooks require the following stuff:
1615 if [ -x /usr/bin/amixer ] ; then
1616 if amixer get Front 1>/dev/null 2>>$DEBUG ; then
1617 amixer set Front unmute 1>/dev/null
1618 amixer set Front 0% 1>/dev/null
1621 ERROR=$(aumix -w 0 -v 0 -p 0 -m 0 2>&1) ; RC=$?
1622 if [ -n "$ERROR" ] ; then
1624 eerror "Problem muting sound devices: $ERROR"
1628 elif [ -z "$INSTALLED" ]; then
1629 einfo "Setting mixer volumes to level ${WHITE}${VOL}${NORMAL}."
1630 # some IBM notebooks require the following stuff:
1631 if [ -x /usr/bin/amixer ] ; then
1632 if amixer get Front 1>/dev/null 2>>$DEBUG ; then
1633 amixer set Front unmute 1>/dev/null
1634 amixer set Front ${VOL}% 1>/dev/null
1637 # by default assume '0' as volume for microphone:
1638 if checkbootparam 'micvol' ; then
1639 MICVOL="$(getbootparam 'micvol' 2>>$DEBUG)"
1644 # finally set the volumes:
1645 ERROR=$(aumix -w $VOL -v $VOL -p $VOL -m $MICVOL 2>&1) ; RC=$?
1646 if [ -n "$ERROR" ] ; then
1648 eerror "Problem setting mixer volumes: $ERROR (no soundcard?)"
1658 # {{{ modem detection
1660 if checkbootparam 'nomodem'; then
1661 ewarn "Skipping check for AC97 modem controller as requested on boot commandline." ; eend 0
1663 if [ -x /etc/init.d/sl-modem-daemon ] ; then
1664 if lspci | grep Intel | grep -q "AC'97 Modem Controller" ; then
1665 einfo "AC97 modem controller detected. Start it running 'Start sl-modem-daemon'."
1673 # {{{ keyboard add-ons
1674 config_setkeycodes(){
1675 if checkbootparam 'setkeycodes' ; then
1676 einfo "Setting keycodes as requested via bootparameter 'setkeycodes'."
1677 # MS MM keyboard add-on
1679 setkeycodes e001 126 &>/dev/null
1680 setkeycodes e059 127 &>/dev/null
1682 setkeycodes e03b 59 &>/dev/null
1683 setkeycodes e008 60 &>/dev/null
1684 setkeycodes e007 61 &>/dev/null
1685 setkeycodes e03e 62 &>/dev/null
1686 setkeycodes e03f 63 &>/dev/null
1687 setkeycodes e040 64 &>/dev/null
1688 setkeycodes e041 65 &>/dev/null
1689 setkeycodes e042 66 &>/dev/null
1690 setkeycodes e043 67 &>/dev/null
1691 setkeycodes e023 68 &>/dev/null
1692 setkeycodes e057 87 &>/dev/null
1693 setkeycodes e058 88 &>/dev/null
1695 setkeycodes e00a 89 e008 90 &>/dev/null
1702 config_wondershaper(){
1703 if checkbootparam 'wondershaper' ; then
1704 WONDER="$(getbootparam 'wondershaper' 2>>$DEBUG)"
1709 if [ -n "$WONDER" ]; then
1711 DEVICE="${WONDER%%,*}"
1713 if [ -n "$R" -a "$R" != "$WONDER" ]; then
1715 DOWNSTREAM="${WONDER%%,*}"
1717 if [ -n "$R" -a "$R" != "$WONDER" ]; then
1719 UPSTREAM="${WONDER%%,*}"
1724 [ -n "$DEVICE" ] && CMD="$CMD $DEVICE"
1725 [ -n "$DOWNSTREAM" ] && CMD="$CMD $DOWNSTREAM"
1726 [ -n "$UPSTREAM" ] && CMD="$CMD $UPSTREAM"
1727 einfo "Starting wondershaper (${CMD}) in background."
1728 ( sh -c $CMD & ) && eend 0
1735 if checkbootparam 'nosyslog'; then
1736 ewarn "Not starting syslog daemon as requested on boot commandline." ; eend 0
1739 [ -x /etc/init.d/syslog-ng ] && SYSLOGD='syslog-ng'
1740 [ -x /etc/init.d/rsyslog ] && SYSLOGD='rsyslog'
1741 [ -x /etc/init.d/dsyslog ] && SYSLOGD='dsyslog'
1742 [ -x /etc/init.d/sysklogd ] && SYSLOGD='sysklogd'
1743 [ -x /etc/init.d/inetutils-syslogd ] && SYSLOGD='inetutils-syslogd'
1745 if [ -z "$SYSLOGD" ] ; then
1746 eerror "No syslog daemon found." ; eend 1
1748 einfo "Starting $SYSLOGD in background."
1749 /etc/init.d/$SYSLOGD start 1>>$DEBUG &
1758 if checkbootparam 'nogpm'; then
1759 ewarn "Not starting GPM as requested on boot commandline." ; eend 0
1761 if ! [ -r /dev/input/mice ] ; then
1762 eerror "No mouse found - not starting GPM." ; eend 1
1764 einfo "Starting gpm in background."
1765 /etc/init.d/gpm start 1>>$DEBUG &
1766 # ( while [ ! -e /dev/psaux ]; do sleep 5; done; /etc/init.d/gpm start 1>>$DEBUG ) &
1775 if checkbootparam 'services' ; then
1776 SERVICE="$(getbootparam 'services' 2>>$DEBUG)"
1777 SERVICELIST=$(echo "$SERVICE" | sed 's/,/\\n/g')
1778 SERVICENL=$(echo "$SERVICE" | sed 's/,/ /g')
1779 einfo "Starting service(s) ${SERVICENL} in background."
1780 for service in $(echo -e $SERVICELIST) ; do
1781 /etc/init.d/${service} start 1>>$DEBUG &
1783 [ "$?" == "0" ] ; eend $?
1790 if checkbootparam 'netconfig' ; then
1791 CONFIG="$(getbootparam 'netconfig' 2>>$DEBUG)"
1792 CONFIGFILE='/tmp/netconfig.grml'
1795 wget --timeout=10 --dns-timeout=10 --connect-timeout=10 \
1796 --read-timeout=10 $CONFIG -O $CONFIGFILE && return 0 || return 1
1798 einfo "Trying to get ${WHITE}${CONFIG}${NORMAL}"
1800 while ! getconfig && [[ "$counter" != 0 ]] ; do
1801 echo -n "Sleeping for 5 seconds and trying to get config again... "
1802 counter=$(( counter-1 ))
1803 echo "$counter tries left" ; sleep 1
1805 if [ -r "$CONFIGFILE" ] ; then
1806 einfo "Downloading was successfull." ; eend 0
1807 einfo "md5sum of ${WHITE}${CONFIG}${NORMAL}: "
1808 md5sum $CONFIGFILE ; eend 0
1809 cd / && einfo "Unpacking ${WHITE}${CONFIGFILE}${NORMAL}:" && /usr/bin/unp $CONFIGFILE $EXTRACTOPTIONS ; eend $?
1811 einfo "Sorry, could not fetch $CONFIG" ; eend 1
1818 config_blindsound(){
1819 if checkbootparam 'blind' ; then
1821 flitewrapper "welcome to the gremel system"
1828 if checkbootparam 'welcome' ; then
1829 flitewrapper "welcome to the gremel system"
1834 # {{{ fix/workaround for unionfs
1836 if [ -z "$INSTALLED" ]; then
1837 touch /var/cache/apt/*cache.bin
1842 # {{{ create all /mnt-directories
1844 ewarn "create_mnt_dirs is deprecated as grml-rebuildfstab does all we need."
1845 ewarn "Please set CONFIG_CREATE_MNT_DIRS='no' in /etc/grml/autoconfig" ; eend 0
1849 # {{{ start X window system via grml-x
1851 # make sure we start X only if startx is used *before* a nostartx option
1852 # so it's possible to disable automatic X startup using nostart
1853 if checkbootparam 'startx' && ! grep -q 'startx.*nostartx' "$CMDLINE" ; then
1854 if [ -x /usr/X11R6/bin/X ] ; then
1855 if [ -z "$INSTALLED" ] ; then
1856 WINDOWMANAGER="$(getbootparam 'startx' 2>>$DEBUG)"
1857 if [ -z "$WINDOWMANAGER" ] ; then
1858 einfo "No window manager specified. Taking ${WHITE}wm-ng${NORMAL} as default." && eend 0
1859 WINDOWMANAGER="wm-ng"
1861 einfo "Window manager ${WHITE}${WINDOWMANAGER}${NORMAL} found as bootoption." && eend 0
1863 einfo "Changing to runlevel 5 for starting grml-x ${WINDOWMANAGER}. Just exit X windows system to get full featured consoles."
1864 config_userfstab || fstabuser='grml'
1865 cat>|/etc/init.d/xstartup<<EOF
1867 # su - $fstabuser -c 'grml-x "$WINDOWMANAGER"'
1868 sudo -u $fstabuser -i /usr/bin/grml-x $WINDOWMANAGER 1>>$DEBUG
1870 chmod 755 /etc/init.d/xstartup
1872 # adjust inittab for xstartup
1873 if grep -q '^6:' /etc/inittab ; then
1874 sed -i 's|^6:.*|6:2345:respawn:/bin/zsh --login -c "/etc/init.d/xstartup ; /bin/zsh"|' /etc/inittab
1875 else # just append tty6 to inittab if no definition is present:
1876 echo '6:2345:respawn:/bin/zsh --login -c "/etc/init.d/xstartup ; /bin/zsh"' >> /etc/inittab
1879 /sbin/telinit q ; eend $?
1881 if grep -q '^allowed_users=' /etc/X11/Xwrapper.config ; then
1882 sed -i 's/^allowed_users=.*/allowed_users=anybody/' /etc/X11/Xwrapper.config
1884 echo 'allowed_users=anybody' >> /etc/X11/Xwrapper.config
1888 eerror "We are not running in live mode - startx will not work, skipping it."
1889 eerror " -> Please use something like xdm, gdm or kdm for starting X on a harddisk system!" ; eend 1
1892 eerror "/usr/X11R6/bin/X is not present on this grml flavour."
1893 eerror " -> Boot parameter startx does not work therefore." ; eend 1
1899 # {{{ configuration framework
1901 if checkbootparam 'extract' ; then
1902 EXTRACT="$(getbootparam 'extract' 2>>$DEBUG)"
1903 EXTRACTOPTIONS="-- -x $EXTRACT"
1907 config_finddcsdir() {
1908 # - If no GRMLCFG partition is found and noautoconfig is _not_ given
1909 # on the command line, nothing is changed and the dcs files are
1910 # searched within the .iso, $dcs-dir is set to the root directory
1912 # - If a GRMLCFG partition is found, $dcs-dir is set to the root of
1913 # the GRMLCFG partition unless noautoconfig is set. If noautoconfig is
1914 # set, $dcs-dir is set to the root directory within the .iso.
1915 # - If myconfig=foo is set on the command line, $dcs-dir is set to
1916 # foo, even if a GRMLCFG partition is present.
1918 if checkbootparam 'noautoconfig' || checkbootparam 'forensic' ; then
1919 ewarn "Skipping running automount of device(s) labeled GRMLCFG as requested." ; eend 0
1921 if [ -z "$INSTALLED" ] ; then
1922 if checkbootparam 'myconfig' ; then
1923 DCSDEVICE="$(getbootparam 'myconfig' 2>>$DEBUG)"
1924 if [ -z "$DCSDEVICE" ]; then
1925 einfo "No device for bootoption myconfig provided." ; eend 1
1926 fi # [ -z "$DCSDEVICE" ]
1927 elif checkvalue $CONFIG_MYCONFIG; then # checkbootparam myconfig
1928 einfo "Searching for device(s) labeled with GRMLCFG. (Disable this via boot option: noautoconfig)" ; eend 0
1930 # We do need the following fix so floppy disk is available to blkid in any case :-/
1931 if [ -r /dev/fd0 ] ; then
1932 einfo "Floppy device detected. Trying to access floppy disk."
1933 if timeout 4 dd if=/dev/fd0 of=/dev/null bs=512 count=1 1>>$DEBUG 2>&1 ; then
1934 blkid /dev/fd0 1>>$DEBUG 2>&1
1937 DCSDEVICE=$(blkid -t LABEL=GRMLCFG | head -1 | awk -F: '{print $1}')
1939 if [ -n "$DCSDEVICE" ]; then
1940 einfo "debs, config, scripts are read from $DCSDEVICE." ; eend 0
1941 DCSDIR="$(< /proc/mounts awk -v DCSDEV=$DCSDEVICE '{if ($1 == DCSDEV) { print $2 }}')"
1942 if [ -n "$DCSDIR" ]; then
1943 einfo "$DCSDEVICE already mounted on $DCSDIR"; eend 0
1945 [ -d /mnt/grml ] || mkdir /mnt/grml
1946 umount /mnt/grml 1>>$DEBUG 2>&1 # make sure it is not mounted
1947 mount -o ro -t auto $DCSDEVICE /mnt/grml ; RC="$?"
1948 if [[ $RC == 0 ]]; then
1949 einfo "Successfully mounted $DCSDEVICE to /mnt/grml (readonly)." ; eend 0
1958 if [ -n "$DCSDIR" ]; then
1959 einfo "Debs, config, scripts will be read from $DCSDIR." ; eend 0
1960 elif checkbootparam 'debs' || checkbootparam 'config' || checkbootparam 'scripts'; then
1961 einfo "Debs, config, scripts will be read from the live image directly." ; eend 0
1967 if checkbootparam 'partconf' ; then
1968 MOUNTDEVICE="$(getbootparam 'partconf' 2>>$DEBUG)"
1969 if [ -n "$MOUNTDEVICE" ]; then
1970 [ -d /mnt/grml ] || mkdir /mnt/grml
1971 mount -o ro -t auto $MOUNTDEVICE /mnt/grml ; RC="$?"
1972 if [[ $RC == 0 ]]; then
1973 einfo "Successfully mounted $MOUNTDEVICE to /mnt/grml (readonly)." ; eend 0
1974 einfo "Copying files from $MOUNTDEVICE over grml system."
1975 for file in `cat /etc/grml/partconf` ; do
1976 [ -d /mnt/grml/$file ] && cp -a /mnt/grml/${file}* ${file} && echo "copied: $file"
1977 [ -f /mnt/grml/$file ] && cp -a /mnt/grml/${file} ${file} && echo "copied: $file"
1980 einfo "Could not mount $MOUNTDEVICE to /mnt/grml - sorry." ; eend 1
1981 fi # mount $MOUNTDEVICE
1982 grep -q '/mnt/grml' /proc/mounts && umount /mnt/grml
1984 einfo "Sorry, no device for bootoption partconf provided. Skipping." ; eend 1
1985 fi # [ -n "$MOUNTDEVICE" ]
1990 # {{{ /cdrom/.*-options
1992 if checkbootparam 'debs' ; then
1993 DEBS="$(getbootparam 'debs' 2>>$DEBUG)"
1994 if ! echo $DEBS | grep -q '/'; then
1995 # backwards compatibility: if no path is given get debs from debs/
1998 einfo "Tring to install debian package(s) ${DEBS}"
1999 DEBS="$(eval echo ${DCSDIR}/$DEBS)"
2000 dpkg -i $DEBS ; eend $?
2005 if checkbootparam 'scripts' ; then
2006 SCRIPTS="$(getbootparam 'scripts' 2>>$DEBUG)"
2007 if [ -z "$SCRIPTS" ]; then
2008 SCRIPTS="$(cd ${DCSDIR}/scripts; /bin/ls -1d [Gg][Rr][Mm][Ll].[Ss][Hh] 2>>$DEBUG)"
2010 if ! echo $SCRIPTS | grep -q '/'; then
2011 # backwards compatibility: if no path is given get scripts from scripts/
2012 SCRIPTS="scripts/$SCRIPTS"
2014 SCRIPTS="${DCSDIR}/$SCRIPTS"
2015 if [ -d "$SCRIPTS" ]; then
2016 einfo "Bootparameter scripts found. Trying to execute from directory ${SCRIPTS}:"
2019 einfo "Bootparameter scripts found. Trying to execute ${SCRIPTS}:"
2026 if checkbootparam 'config' ; then
2027 CONFIG="$(getbootparam 'config' 2>>$DEBUG)"
2028 if [ -z "$CONFIG" ]; then
2029 CONFIG="$(cd ${DCSDIR}; ls -1d [Cc][Oo][Nn][Ff][Ii][Gg].[Tt][Bb][Zz] 2>>$DEBUG)"
2031 if [ -n "$CONFIG" ]; then
2032 if [ -d "${DCSDIR}/${CONFIG}" ] ; then
2033 einfo "Taking configuration from directory ${DCSDIR}/${CONFIG}"
2035 cp -a ${DCSDIR}/${CONFIG}/* /
2036 elif [ -f "${DCSDIR}/${CONFIG}" ]; then
2037 einfo "Extracting configuration from file ${DCSDIR}/${CONFIG}"
2040 unp ${DCSDIR}/${CONFIG} $EXTRACTOPTIONS ; eend $?
2042 ewarn "Sorry, could not find configuration file or directory ${DCSDIR}/${FILENAME}." ; eend 1
2046 # umount /mnt/grml if it was mounted by finddcsdir
2047 # this doesn't really belong here
2048 grep -q '/mnt/grml' /proc/mounts && umount /mnt/grml
2054 if checkbootparam 'mypath' ; then
2055 MY_PATH="$(getbootparam 'mypath' 2>>$DEBUG)"
2056 einfo "Bootparameter mypath found, adding ${MY_PATH} to /etc/grml/my_path"
2057 touch /etc/grml/my_path
2058 chmod 644 /etc/grml/my_path
2059 # make sure the directories exist:
2061 for i in $(echo $MY_PATH | sed 's/:/\n/g') ; do
2062 if ! [ -d "$i" ] ; then
2063 einfo "Creating directory $i"
2064 mkdir -p "$i" ; eend $?
2067 grep -q "${MY_PATH}" /etc/grml/my_path || echo "${MY_PATH}" >> /etc/grml/my_path ; eend $?
2075 if checkbootparam 'distcc' ; then
2076 OPTIONS="$(getbootparam 'distcc' 2>>$DEBUG)"
2077 if [ -n "$OPTIONS" ]; then
2080 if [ -n "$OPTIONS" ]; then
2081 NET="${OPTIONS%%,*}"
2083 if [ -n "$R" -a "$R" != "$OPTIONS" ]; then
2085 INTERFACE="${OPTIONS%%,*}"
2090 CONFIG=/etc/default/distcc
2091 sed -i "s#^STARTDISTCC=.*#STARTDISTCC=YES#" $CONFIG
2092 sed -i "s#^ALLOWEDNETS=.*#ALLOWEDNETS=$NET#" $CONFIG
2094 if [ -n "$INTERFACE" ] ; then
2095 IP=$(LANG=C ifconfig $INTERFACE | gawk -F: /"inet addr"/'{print $2}' | gawk '{print $1}')
2098 while [ -z "$IP" ] && [[ "$counter" != 0 ]] ; do
2099 counter=$(( counter-1 ))
2100 ewarn "No ip address for $INTERFACE found. Sleeping for 3 seconds. $counter tries left."
2102 IP=$(LANG=C ifconfig $INTERFACE | gawk -F: /"inet addr"/'{print $2}' | gawk '{print $1}')
2106 if [ -n "$IP" ] ; then
2107 sed -i "s#^LISTENER=.*#LISTENER=$IP#" $CONFIG
2109 einfo "Bootoption distcc found. Preparing setup for distcc daemon."
2111 id distccd >/dev/null 2>&1 || \
2113 einfo "Creating distcc user" ; \
2114 adduser --quiet --system --ingroup nogroup --home / --no-create-home distccd ; eend $?
2117 einfo "Starting distcc for network ${NET}, listening on ${IP}."
2118 /etc/init.d/distcc start 1>/dev/null ; eend $?
2121 eerror "No ip address for $INTERFACE found. distcc can not be used without it." ; eend 1
2125 if checkbootparam 'gcc'; then
2126 GCC="$(getbootparam 'gcc' 2>>$DEBUG)"
2128 einfo "Pointing /usr/bin/gcc to /usr/bin/gcc-${GCC}."
2131 ln -s /usr/bin/gcc-${GCC} /usr/bin/gcc ; eend $?
2134 if checkbootparam 'gpp'; then
2135 GPP="$(getbootparam 'gpp' 2>>$DEBUG)"
2137 einfo "Pointing /usr/bin/g++ to /usr/bin/g++-${GPP}."
2138 if [ -x /usr/bin/g++-${GPP} ] ; then
2140 ln -s /usr/bin/g++-${GPP} /usr/bin/g++ ; eend $?
2142 einfo "Pointing /usr/bin/cpp to /usr/bin/cpp-${GPP}."
2143 if [ -x /usr/bin/cpp-${GPP} ] ; then
2145 ln -s /usr/bin/cpp-${GPP} /usr/bin/cpp ; eend $?
2154 # Notice: use it only on live-cd system, if running from harddisk please
2155 # add modules to /etc/modules and activate /etc/init.d/module-init-tools
2156 # in /etc/runlevel.conf
2158 MODULES_FILE=/etc/grml/modules
2159 if checkbootparam 'nomodules' ; then
2160 ewarn "Skipping loading of modules defined in ${MODULES_FILE} as requested." ; eend 0
2161 elif [ -z "$INSTALLED" ]; then
2162 if [ -r $MODULES_FILE ] ; then
2163 einfo "Loading modules specified in ${MODULES_FILE}:"
2165 grep '^[^#]' $MODULES_FILE | \
2166 while read module args; do
2167 [ "$module" ] || continue
2169 modprobe $module $args ; eend $?
2173 ewarn "File $MODULES_FILE does not exist. Skipping loading of specific modules." ; eend 1
2180 config_915resolution(){
2181 if checkbootparam '915resolution' ; then
2182 OPTIONS="$(getbootparam '915resolution' 2>>$DEBUG)"
2183 if [ -x /usr/sbin/915resolution ]; then
2188 if [ -n "$OPTIONS" ]; then
2190 MODE="${OPTIONS%%,*}"
2192 if [ -n "$R" -a "$R" != "$OPTIONS" ]; then
2194 XRESO="${OPTIONS%%,*}"
2196 if [ -n "$R" -a "$R" != "$OPTIONS" ]; then
2198 YRESO="${OPTIONS%%,*}"
2203 einfo "Running 915resolution with options ${MODE} ${XRESO} ${YRESO}."
2204 [ -n "$MODE" ] && [ -n "$XRESO" ] && [ -n "$YRESO" ] && ( sh -c "$CMD $MODE $XRESO $YRESO" & )
2213 if [ -z "$INSTALLED" ] ; then
2214 # notice: checkbootparam "forensic" is just for users who don't know how to really use the bootoption
2215 if checkbootparam 'noraid' || checkbootparam 'noswraid' -o \
2216 checkbootparam 'forensic' || checkbootparam 'raid=noautodetect' ; then
2217 ewarn "Skipping SW-RAID code as requested on boot commandline." ; eend 0
2219 if ! [ -x /sbin/mdadm ] ; then
2220 eerror "mdadm not available, can not execute it." ; eend 1
2223 # if ! egrep -qv '^(MAILADDR.*|#.*|)$' /etc/mdadm/mdadm.conf 2>>$DEBUG ; then
2224 # find out whether we have a valid configuration file already
2225 if ! grep -q ARRAY /etc/mdadm/mdadm.conf 2>>$DEBUG ; then
2226 einfo "Creating /etc/mdadm/mdadm.conf for use with mdadm."
2227 [ -r /etc/mdadm/mdadm.conf ] && mv /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf.old
2228 MDADM_MAILADDR__='root' /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf ; eend $?
2230 ewarn "/etc/mdadm/mdadm.conf looks like a configured mdadm setup, will not touch it." ; eend 0
2233 if ! checkbootparam 'swraid' ; then
2235 einfo "Just run 'Start mdadm-raid' to assemble md arrays or boot using 'swraid' as bootoption for autostart."
2238 einfo "Bootoption swraid found. Searching for software RAID arrays:"
2243 for line in $(mdadm --assemble --scan --auto=yes --symlink=no 2>&1) ; do
2245 *'No arrays found'*)
2246 ewarn "$line" ; eend 0
2249 einfo "$line" ; eend 0
2256 if [ -r /proc/mdstat ] ; then
2258 MDSTAT=$(grep '^md[0-9]' /proc/mdstat)
2259 if [ -z "$MDSTAT" ] ; then
2260 ewarn "No active arrays found" ; eend 0
2265 for line in $(grep '^md[0-9]' /proc/mdstat) ; do
2266 einfo "active arrays: $line" ; eend 0
2272 fi # bootoption swraid
2274 fi # is /sbin/mdadm executable?
2275 fi # check for bootoptions
2276 fi # run only in live-cd mode
2280 # {{{ LVM (Logical Volumes)
2282 if [ -z "$INSTALLED" ] ; then
2283 # notice: checkbootparam "forensic" is just for users who don't know how to really use the bootoption
2284 if checkbootparam 'nolvm' ; then
2285 ewarn "Skipping LVM code as requested on boot commandline." ; eend 0
2287 # Debian etch provides /etc/init.d/lvm only, newer suites provide /etc/init.d/lvm2
2288 if ! [ -x /sbin/lvm -a -x /sbin/lvdisplay ] || ! [ -x /etc/init.d/lvm2 -o -x /etc/init.d/lvm ] ; then
2289 eerror "LVM not available, can not execute it." ; eend 1
2291 if lvdisplay 2>&1 | grep -v 'No volume groups found' 1>/dev/null 2>&1 ; then
2292 einfo "You seem to have logical volumes (LVM) on your system."
2294 einfo "Just run 'Start lvm2' to activate them or boot using 'lvm' as bootoption for autostart."
2296 if checkbootparam 'lvm' ; then
2297 einfo "Bootoption LVM found. Searching for logical volumes:"
2298 /etc/init.d/lvm2 start ; eend $?
2302 fi # check for lvm binary
2303 fi # check for bootoption nolvm
2304 fi # run only in live-cd mode
2308 # {{{ debnet: setup network based on an existing one found on a partition
2310 if checkbootparam 'debnet' ; then
2311 iszsh && setopt shwordsplit
2312 DEVICES="$(< /proc/partitions tail -n +3 | awk '{print "/dev/"$4}' | tr "\n" " ")"
2313 DEVICES="$DEVICES $(ls /dev/mapper/*)"
2316 einfo "Bootoption 'debnet' found. Searching for Debian network configuration: "
2318 if ! mount | grep '/mnt ' 1>/dev/null 2>&1 ; then
2319 for i in $DEVICES; do
2320 if mount -o ro -t auto "$i" /mnt >/dev/null 2>&1; then
2321 einfo "Scanning on $i"
2322 if [ -f /mnt/etc/network/interfaces ]; then
2323 einfo "/etc/network/interfaces found on ${i}" ; eend 0
2331 if [ -n "$FOUND_DEBNET" ]; then
2332 einfo "Stopping network."
2333 pump -k 1>/dev/null 2>&1
2334 /etc/init.d/networking stop 1>/dev/null 2>&1 ; eend $?
2335 einfo "Copying Debian network configuration from $FOUND_DEBNET to running system."
2336 rm -rf /etc/network/run
2337 cp -a /mnt/etc/network /etc
2338 rm -rf /etc/network/run
2339 mkdir /etc/network/run
2340 umount /mnt ; eend $?
2341 einfo "Starting network."
2342 invoke-rc.d networking start ; eend $?
2344 eerror "/etc/network/interfaces not found." ; eend 1
2348 eerror "Error: /mnt already mounted." ; eend 1
2354 # {{{ check for broken ipw3945 driver which causes problems (especially on hd install)
2356 if grep -q ipw3945 /proc/modules ; then
2357 if ! iwconfig 2>/dev/null| grep -qe 'IEEE 802' -qe 'unassociated' ; then
2358 ewarn "Broken ipw3945 network interface found, reloading module."
2367 # {{{ disable console blanking
2369 if checkbootparam 'noblank' ; then
2370 einfo "Bootoption noblank found. Disabling monitor blanking."
2371 setterm -blank 0 ; eend $?
2376 # {{{ tohd= bootoption
2379 if checkbootparam 'tohd' ; then
2380 local TARGET="$(getbootparam 'tohd' 2>>$DEBUG)"
2381 if [ -z "$TARGET" ] ; then
2382 eerror "Error: tohd specified without any partition, can not continue." ; eend 1
2383 eerror "Please use something like tohd=/dev/sda9." ; eend 1
2387 if ! [ -b "$TARGET" ] ; then
2388 eerror "Error: $TARGET is not a valid block device, sorry." ; eend 1
2392 if grep -q $TARGET /proc/mounts ; then
2393 eerror "$TARGET already mounted, skipping execution of tohd therefore."
2398 local MOUNTDIR=$(mktemp -d)
2400 if mount -o rw "$TARGET" "$MOUNTDIR" ; then
2401 einfo "Copyring live system to $TARGET - this might take a while"
2402 rsync -a --progress /live/image/live $MOUNTDIR
2406 einfo "Booting with \"grml bootfrom=$TARGET\" should work now." ; eend 0
2408 eerror "Error when trying to mount $TARGET, sorry."; eend 1
2417 # {{{ grml2hd: automatic installation
2420 if checkbootparam "BOOT_IMAGE=grml2hd" ; then
2422 if checkbootparam 'user' ; then
2424 NEWUSER="$(getbootparam 'user' 2>>$DEBUG)"
2425 sed -i "s/^NEWUSER=.*/NEWUSER=$NEWUSER/" /etc/grml2hd/config || export GRML2HD_FAIL=1
2428 if checkbootparam 'filesystem' ; then
2430 FILESYSTEM="$(getbootparam 'filesystem' 2>>$DEBUG)"
2431 sed -i "s/^FILESYSTEM=.*/FILESYSTEM=$FILESYSTEM/" /etc/grml2hd/config || export GRML2HD_FAIL=1
2434 if checkbootparam 'partition' ; then
2436 PARTITION="$(getbootparam 'partition' 2>>$DEBUG)"
2437 # notice: the following checks whether the given partition is available, if not the skip
2438 # execution of grml2hd as it might result in data loss...
2439 if [ -r $PARTITION ] ; then
2440 sed -i "s#^PARTITION=.*#PARTITION=$PARTITION#" /etc/grml2hd/config || export GRML2HD_FAIL=1
2442 ewarn "Partition $PARTITION does not exist. Skipping execution of grml2hd therefore." ; eend 1
2446 if checkbootparam 'mbr' ; then
2448 BOOT_PARTITION="$(getbootparam 'mbr' 2>>$DEBUG)"
2449 sed -i "s#^BOOT_PARTITION=.*#BOOT_PARTITION=$BOOT_PARTITION#" /etc/grml2hd/config || export GRML2HD_FAIL=1
2452 cat>|/usr/bin/grml2hd_noninteractive<<EOF
2454 GRML2HD_NONINTERACTIVE='yes' grml2hd
2457 chmod 755 /usr/bin/grml2hd_noninteractive
2458 einfo "Bootoption grml2hd found. Running automatic installation via grml2hd using /etc/grml2hd/config." && eend 0
2459 if [ -z "$GRML2HD_FAIL" ] ; then
2460 screen /usr/bin/grml2hd_noninteractive ; einfo "Invoking a shell, just exit to continue booting..." ; /bin/zsh
2462 ewarn "There was an error adjusting /etc/grml2hd/config. Skipping execution of grml2hd for security reasons." ; eend 1
2465 fi # if checkbootparam "BOOT_IMAGE=grml2hd ...
2469 # {{{ debootstrap: automatic installation
2470 config_debootstrap(){
2472 if checkbootparam "BOOT_IMAGE=debian2hd" ; then
2474 einfo "Bootoption debian2hd found. Setting up environment for automatic installation via grml-debootstrap." ; eend 0
2476 if ! [ -x /usr/sbin/grml-debootstrap ] ; then
2478 eerror "Bootoption debian2hd found, but grml-debootstrap is not available." ; eend 1
2483 if checkbootparam 'target' ; then
2485 TARGET="$(getbootparam 'target' 2>>$DEBUG)"
2486 # notice: the following checks whether the given partition is available, if not the skip
2487 # execution of grml-debootstrap as it might result in data loss...
2488 if ! [ -r "$TARGET" ] ; then
2489 eerror "Target $TARGET does not exist. Skipping execution of grml-debootstrap therefore." ; eend 1
2493 eerror "No bootoption named target found, can not continue execution of grml-debootstrap." ; eend 1
2498 if checkbootparam 'grub' ; then
2500 GRUB="$(getbootparam 'grub' 2>>$DEBUG)"
2503 if checkbootparam 'groot' ; then
2505 GROOT="$(getbootparam 'groot' 2>>$DEBUG)"
2508 if checkbootparam 'release' ; then
2510 RELEASE="$(getbootparam 'release' 2>>$DEBUG)"
2513 if checkbootparam 'mirror' ; then
2515 MIRROR="$(getbootparam 'mirror' 2>>$DEBUG)"
2518 if checkbootparam 'boot_append' ; then
2520 BOOT_APPEND="$(getbootparam 'boot_append' 2>>$DEBUG)"
2523 if checkbootparam 'password' ; then
2525 PASSWORD="$(getbootparam 'password' 2>>$DEBUG)"
2528 # now check which options are available
2529 if [ -n "TARGET" ] ; then
2530 TARGETCMD="--target $TARGET"
2534 eerror "Target not set via bootoption. Skipping execution of grml-debootstrap therefore."; eend 1
2538 [ -n "$GRUB" ] && GRUBCMD="--grub $GRUB" || GRUBCMD=''
2539 [ -n "$GROOT" ] && GROOTCMD="--groot $GROOT" || GROOTCMD=''
2540 [ -n "$RELEASE" ] && RELEASECMD="--release $RELEASE" || RELEASECMD=''
2541 [ -n "$MIRROR" ] && MIRRORCMD="--mirror $MIRROR" || MIRRORCMD=''
2542 [ -n "$PASSWORD" ] && PASSWORDCMD="--password $PASSWORD" || PASSWORDCMD=''
2543 [ -n "$BOOT_APPEND" ] && BOOT_APPEND="--boot_append $BOOT_APPEND" || BOOT_APPEND=''
2545 # and finally write script and execute it
2546 cat>|/usr/bin/grml-debootstrap_noninteractive<<EOF
2548 AUTOINSTALL='yes' grml-debootstrap $TARGETCMD $GRUBCMD $GROOTCMD $RELEASECMD $MIRRORCMD $PASSWORDCMD $BOOT_APPEND
2551 chmod 750 /usr/bin/grml-debootstrap_noninteractive
2553 screen /usr/bin/grml-debootstrap_noninteractive
2554 einfo "Invoking a shell, just exit to continue booting..."
2557 fi # checkbootparam "BOOT_IMAGE=debian2hd
2561 # {{{ Support customization
2563 if checkbootparam 'distri'; then
2564 DISTRI="$(getbootparam 'distri' 2>>$DEBUG)"
2565 if [ -r "${LIVECD_PATH}"/desktop/"$DISTRI".jpg ] ; then
2566 [ -n "$BOOTDEBUG" ] && einfo "Debug: bootoption distri found and file ${LIVECD_PATH}/desktop/${DISTRI} present" && eend 0
2567 # make sure the desktop.jpg file is not a symlink, so copying does not file then
2568 [ -L /usr/share/grml/desktop.jpg ] && rm /usr/share/grml/desktop.jpg
2569 cp "${LIVECD_PATH}"/desktop/"$DISTRI".jpg /usr/share/grml/desktop.jpg
2575 ### {{{ backwards compatible stuff
2576 config_environment(){
2577 ewarn "config_environment is deprecated. Please set CONFIG_ENVIRONMENT in /etc/grml/autoconfig to 'no'." ; eend 0
2580 ewarn "config_keyboard is deprecated. Please set CONFIG_KEYBOARD in /etc/grml/autoconfig to 'no'." ; eend 0
2584 ## END OF FILE #################################################################
2585 # vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=3