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"
16 # old linuxrc version:
17 [ -d /cdrom ] && export LIVECD_PATH=/cdrom
18 # initramfs layout until around December 2012:
19 [ -d /live/image ] && export LIVECD_PATH=/live/image
20 # initramfs layout since around December 2012:
21 [ -d /lib/live/mount/medium ] && export LIVECD_PATH=/lib/live/mount/medium
23 # Ignore these signals in non-interactive mode: INT, TERM, SEGV
24 [ -z "$PS1" ] && trap "" 2 3 11
26 if [[ "$(realpath "$(cat /proc/1/cmdline)")" == "/lib/systemd/systemd" ]] ; then
34 if [ -n "$ZSH_VERSION" ] ; then
40 # avoid 'no matches found: ...'
41 iszsh && setopt no_nomatch # || echo "Warning: not running under zsh!"
44 # {{{ Read in boot parameters
45 if [ -z "$CMDLINE" ]; then
46 # if CMDLINE was set from the outside, we're debugging.
47 # otherwise, take CMDLINE from Kernel and config files.
48 CMDLINE="$(cat /proc/cmdline)"
49 [ -d ${LIVECD_PATH}/bootparams/ ] && CMDLINE="$CMDLINE $(cat ${LIVECD_PATH}/bootparams/* | tr '\n' ' ')"
50 modprobe 9p 2>/dev/null || true
51 if grep -q 9p /proc/filesystems ; then
53 if grep -q "$TAG" /sys/bus/virtio/devices/*/mount_tag 2>/dev/null ; then
54 MOUNTDIR="$(mktemp -d)"
55 mount -t 9p -o trans=virtio,ro "$TAG" "$MOUNTDIR"
56 CMDLINE="$CMDLINE $(cat "$MOUNTDIR"/* 2>/dev/null | tr '\n' ' ')"
64 ### {{{ Utility Functions
66 # Get a bootoption's parameter: read boot command line and either
67 # echo last parameter's argument or return false.
75 result="${line##*[$ws]$1=}"
76 result="${result%%[$ws]*}"
84 # Check boot commandline for specified option
86 [ -n "$1" ] || ( echo "Error: missing argument to checkbootparam()" ; return 1 )
92 *[${ws}]"$1"=*|*[${ws}]"$1"[${ws}]*)
99 # Check if currently using a framebuffer
101 [ -e /dev/fb0 ] && return 0 || return 1
104 # Check wheter a configuration variable (like $CONFIG_TOHD) is
108 [yY][eE][sS]) return 0 ;; # it's set to 'yes'
109 [tT][rR][uU][eE]) return 0 ;; # it's set to 'true'
110 *) return 1 ;; # default
114 # Are we using grml-small?
116 grep -q small /etc/grml_version 2>>$DEBUG && return 0 || return 1
119 # if no password is set return a random password
121 [ -n "$PASSWD" ] && return 0
123 if [ -x /usr/bin/apg ] ; then
124 PASSWD="$(apg -M NL -a 0 -m 8 -x 12 -n 1)"
125 elif [ -x /usr/bin/gpw ] ; then
127 elif [ -x /usr/bin/pwgen ] ; then
128 PASSWD="$(pwgen -1 8)"
129 elif [ -x /usr/bin/hexdump ] ; then
130 PASSWD="$(dd if=/dev/urandom bs=14 count=1 2>/dev/null | hexdump | awk '{print $3 $4}')"
131 elif [ -n "$RANDOM" ] ; then
132 PASSWD="grml${RANDOM}"
135 eerror "Empty passphrase and neither apg, gpw, pwgen, hexdump nor \$RANDOM available. Skipping."
143 # {{{ filesystems (proc, pts, sys) and fixes
145 [ -f /proc/version ] || mount -t proc /proc /proc 2>/dev/null
149 grep -q "/dev/pts" /proc/mounts || mount -t devpts /dev/pts /dev/pts 2>/dev/null
153 [ -d /sys/devices ] || mount -t sysfs /sys /sys 2>/dev/null
157 # {{{ Check if we are running in live mode or from HD
159 [ -e /etc/grml_cd ] || INSTALLED="yes"
162 # {{{ provide information about virtual environments
163 VIRTUAL=false # assume physical system by default
168 if vmware-detect &>/dev/null; then
169 VIRTUAL=true; VMWARE=true; VIRTUAL_ENV='VMware'
170 elif [ "$(virt-what 2>/dev/null)" = "kvm" ] || \
171 [ "$(imvirt 2>/dev/null)" = "KVM" ] ; then
172 VIRTUAL=true; KVM=true; VIRTUAL_ENV='KVM'
173 elif [ "$(virt-what 2>/dev/null)" = "virtualbox" ] || \
174 [ "$(imvirt 2>/dev/null)" = "VirtualBox" ] ; then
175 VIRTUAL=true; VIRTUALBOX=true; VIRTUAL_ENV='VirtualBox'
179 # {{{ source lsb-functions , color handling
180 if checkbootparam 'nocolor'; then
182 . /etc/grml/lsb-functions
183 einfo "Disabling colors in bootsequence as requested on commandline." ; eend 0
185 . /etc/grml/lsb-functions
192 checkbootparam 'debug' && BOOTDEBUG="yes"
193 checkbootparam "BOOT_IMAGE=debug" && BOOTDEBUG="yes"
196 if [ -n "$BOOTDEBUG" ]; then
197 einfo "Starting intermediate shell stage $stage as requested by \"debug\" option."
198 if [ grep -q "debug=noscreen" "$CMDLINE" ] ; then
199 einfo "Notice that the shell does not provide job handling: ctrl-z, bg and fg won't work!"
200 einfo "Just exit the shell to continue boot process..."
204 if [ -r /etc/grml/screenrc ] ; then
205 einfo "Starting GNU screen to be able to use a full featured shell environment."
206 einfo "Just exit the shells (and therefore screen) to continue boot process..."
207 /bin/zsh -c "screen -c /etc/grml/screenrc"
209 einfo "Notice that the shell does not provide job handling: ctrl-z, bg and fg won't work!"
210 einfo "Just exit the shell to continue boot process..."
222 if checkbootparam 'log' || checkbootparam 'debug' ; then
223 export DEBUG="/tmp/grml.log.`date +%Y%m%d`"
225 einfo "Bootparameter log found. Log files: ${DEBUG} and /var/log/boot"
227 einfo "Starting bootlogd." # known to be *very* unreliable :(
228 bootlogd -r -c >>$DEBUG 2>&1 ; eend $?
236 ### {{{ language configuration / localization
239 einfo "Activating language settings:"
242 # people can specify $LANGUAGE and $CONSOLEFONT in a config file
243 [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig
245 # check for bootoption which overrides config from /etc/grml/autoconfig
246 BOOT_LANGUAGE="$(getbootparam 'lang' 2>>$DEBUG)"
247 [ -n "$BOOT_LANGUAGE" ] && LANGUAGE="$BOOT_LANGUAGE"
249 # set default to 'en' in live-cd mode iff $LANGUAGE is not set yet
250 if [ -z "$INSTALLED" ] ; then
251 [ -n "$LANGUAGE" ] || LANGUAGE='en'
254 if [ -x /usr/sbin/grml-setlang ] ; then
255 # if bootoption lang is used update /etc/default/locale accordingly
256 if [ -n "$BOOT_LANGUAGE" ] ; then
257 /usr/sbin/grml-setlang "$LANGUAGE"
258 # otherwise default to lang=en
260 /usr/sbin/grml-setlang "en"
265 if [ -z "$CONSOLEFONT" ] ; then
266 if ! checkbootparam 'nodefaultfont' >>$DEBUG 2>&1 ; then
267 if [ -r /usr/share/consolefonts/Uni3-Terminus16.psf.gz ] ; then
268 CONSOLEFONT='Uni3-Terminus16'
270 ewarn "/usr/share/consolefonts/Uni3-Terminus16.psf.gz not available. Please upgrade package console-terminus." ; eend 1
273 CONSOLEFONT='Lat15-Terminus16'
278 # export it now, so error messages get translated, too
279 [ -r /etc/default/locale ] && . /etc/default/locale
282 # configure keyboard layout, read in already set values first:
283 [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
285 # now allow keyboard override by boot commandline for later use:
286 KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
287 [ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD"
288 # notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead:
289 [[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys
290 [[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys
292 # modify /etc/sysconfig/keyboard only in live-cd mode:
293 if [ -z "$INSTALLED" ] ; then
295 local LANGUAGE="$BOOT_LANGUAGE"
296 . /etc/grml/language-functions
297 # allow setting xkeyboard explicitly different than console keyboard
298 KXKEYBOARD="$(getbootparam 'xkeyboard' 2>>$DEBUG)"
299 if [ -n "$KXKEYBOARD" ]; then
300 XKEYBOARD="$KXKEYBOARD"
301 KDEKEYBOARD="$KXKEYBOARD"
302 elif [ -n "$KKEYBOARD" ]; then
303 XKEYBOARD="$KKEYBOARD"
304 KDEKEYBOARD="$KKEYBOARD"
307 # duplicate of previous code to make sure /etc/grml/language-functions
308 # does not overwrite our values....
309 # now allow keyboard override by boot commandline for later use:
310 KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
311 [ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD"
312 # notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead:
313 [[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys
314 [[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys
316 # write keyboard related variables to file for later use
317 [ -d /etc/sysconfig ] || mkdir /etc/sysconfig
318 if ! [ -e /etc/sysconfig/keyboard ] ; then
319 echo "KEYTABLE=\"$KEYTABLE\"" > /etc/sysconfig/keyboard
320 echo "XKEYBOARD=\"$XKEYBOARD\"" >> /etc/sysconfig/keyboard
321 echo "KDEKEYBOARD=\"$KDEKEYBOARD\"" >> /etc/sysconfig/keyboard
322 echo "KDEKEYBOARDS=\"$KDEKEYBOARDS\"" >> /etc/sysconfig/keyboard
326 [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
328 # activate unicode console if running within utf8 environment
329 if [ -r /etc/default/locale ] ; then
330 if grep -q "LANG=.*UTF" /etc/default/locale ; then
331 einfo "Setting up unicode environment."
332 unicode_start >>$DEBUG 2>&1 ; eend $?
336 # Set default keyboard before interactive setup
337 if [ -n "$KEYTABLE" ] ; then
338 einfo "Running loadkeys for ${WHITE}${KEYTABLE}${NORMAL} in background"
339 loadkeys -q $KEYTABLE &
343 # we have to set up all consoles, therefore loop it over all ttys:
344 NUM_CONSOLES=$(fgconsole --next-available 2>/dev/null)
345 if [ -n "$NUM_CONSOLES" ] ; then
346 NUM_CONSOLES=$(expr ${NUM_CONSOLES} - 1)
347 [ ${NUM_CONSOLES} -eq 1 ] && NUM_CONSOLES=6
349 CUR_CONSOLE=$(fgconsole 2>/dev/null)
351 if [ -x "$(which setfont)" ] ; then
353 elif [ -x "$(which consolechars)" ] ; then
354 use_consolechars=true
356 eerror "Neither setfont nor consolechars tool present, can not set font."
361 if [ -n "$CHARMAP" ] ; then
362 einfo "Setting font to ${CHARMAP}"
364 for vc in $(seq 0 ${NUM_CONSOLES}) ; do
365 if $use_setfont ; then
366 setfont -C /dev/tty${vc} $CHARMAP ; RC=$?
367 elif $use_consolechars ; then
368 consolechars --tty=/dev/tty${vc} -m ${CHARMAP} ; RC=$?
371 if [ -n "$CUR_CONSOLE" ] ; then
372 [ "$CUR_CONSOLE" != "serial" ] && chvt $CUR_CONSOLE
377 if checkbootparam 'noconsolefont' ; then
378 ewarn "Skipping setting console font as requested on boot commandline." ; eend 0
380 if [ -n "$CONSOLEFONT" ] ; then
381 einfo "Setting font to ${CONSOLEFONT}"
383 for vc in $(seq 0 ${NUM_CONSOLES}) ; do
384 if $use_setfont ; then
385 setfont -C /dev/tty${vc} ${CONSOLEFONT} ; RC=$?
386 elif $use_consolechars ; then
387 consolechars --tty=/dev/tty${vc} -f ${CONSOLEFONT} ; RC=$?
390 if [ -n "$CUR_CONSOLE" ] ; then
391 [ "$CUR_CONSOLE" != "serial" ] && chvt $CUR_CONSOLE
403 if ! checkbootparam 'hostname' ; then
407 HOSTNAME="$(getbootparam 'hostname' 2>>$DEBUG)"
408 if [ -z "$HOSTNAME" ] && [ -x /usr/bin/random-hostname ] ; then
409 einfo "Generating random hostname as no hostname was specified."
410 HOSTNAME="$(/usr/bin/random-hostname)"
414 einfo "Setting hostname to $HOSTNAME as requested."
415 grml-hostname $HOSTNAME >>$DEBUG
420 # fstabuser (needed when running from harddisk with username != grml {{{
422 # force load of build-in and local config
423 [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig
424 [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig.local
426 # 1st. try configured fstab user
427 if [ -n "$CONFIG_FSTAB_USER" ] ; then
428 fstabuser=$(getent passwd $CONFIG_FSTAB_USER | cut -d: -f1)
431 # 2nd. use standard user id
432 [ -n "$fstabuser" ] || fstabuser=$(getent passwd 1000 | cut -d: -f1)
434 # 3rd. use standard user name
435 [ -n "$fstabuser" ] || fstabuser=$(getent passwd grml | cut -d: -f1)
437 # if not yet set fall back to 'root' user, avoid bad /etc/fstab
438 [ -n "$fstabuser" ] || fstabuser='root'
442 # local_user (needed when running with username != grml {{{
445 # force load of build-in and local config
446 [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig
447 [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig.local
449 # 1st. try id of primary user
450 localuser=$(getent passwd 1000 | cut -d: -f1)
452 # 2nd. use name standard user
453 [ -n "$localuser" ] || localuser=$(getent passwd grml | cut -d: -f1)
457 # {{{ Set clock (Local time is more often used than GMT, so it is default)
459 # don't touch the files if running from harddisk:
460 if [ -z "$INSTALLED" ]; then
461 # The default hardware clock timezone is stated as representing local time.
464 if [ -f /etc/default/rcS ] ; then
465 grep -q "^UTC=" /etc/default/rcS || echo "UTC=no" >> /etc/default/rcS
466 checkbootparam 'utc' >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=yes|" /etc/default/rcS
467 checkbootparam 'gmt' >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=yes|" /etc/default/rcS
468 checkbootparam 'localtime' >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=no|" /etc/default/rcS
469 grep -q -i "^UTC=yes" /etc/default/rcS && UTC="-u"
470 # recent initscripts package versions don't ship /etc/default/rcS anymore, instead rely on /etc/adjtime
471 elif [ -f /etc/adjtime ] ; then
472 checkbootparam 'utc' >>$DEBUG 2>&1 && sed -i "s/^LOCAL/UTC/" /etc/adjtime
473 checkbootparam 'gmt' >>$DEBUG 2>&1 && sed -i "s/^LOCAL/UTC/" /etc/adjtime
474 checkbootparam 'localtime' >>$DEBUG 2>&1 && sed -i "s/^UTC$/LOCAL/" /etc/adjtime
475 grep -q "^UTC$" /etc/adjtime && UTC="-u"
478 # hwclock uses the TZ variable
479 KTZ="$(getbootparam 'tz' 2>>$DEBUG)"
480 [ -z "$KTZ" ] && [ -r /etc/timezone ] && KTZ=$(cat /etc/timezone)
481 if [ ! -f "/usr/share/zoneinfo/$KTZ" ] ; then
482 ewarn "Warning: unknown timezone $KTZ" ; eend 1
484 ewarn "Falling back to timezone $KTZ" ; eend 0
487 if ! [ -r /dev/rtc ] ; then
488 ewarn "Warning: realtime clock not available, trying to execute hwclock anyway." ; eend 0
491 ERROR=$(TZ="$KTZ" hwclock $UTC -s 2>&1 | head -1) ; RC=$?
492 if [ -n "$ERROR" ] ; then
494 ERROR=$(TZ="$KTZ" hwclock $UTC -s --directisa 2>&1 | head -1)
495 if [ -n "$ERROR" ] ; then
496 eerror "Problem running hwclock: $ERROR" ; eend 1
505 # {{{ print kernel info
507 if $VIRTUAL && [ -n "$VIRTUAL_ENV" ] ; then
508 einfo "Running Linux Kernel $KERNEL inside $VIRTUAL_ENV" ; eend 0
510 einfo "Running Linux Kernel $KERNEL" ; eend 0
513 if [ -r /proc/cpuinfo ] ; then
514 if egrep -q '^flags.*(vmx|svm)' /proc/cpuinfo ; then
516 einfo 'CPU(s) featuring virtualization technology detected' ; eend 0
521 if [ -d /proc/xen ] ; then
523 einfo 'Running kernel featuring support for Xen detected' ; eend 0
531 # don't touch the files if running from harddisk:
532 if [ -z "$INSTALLED" ]; then
533 KTZ="$(getbootparam 'tz' 2>>$DEBUG)"
534 if [ -n "$KTZ" ] ; then
535 if [ ! -f "/usr/share/zoneinfo/$KTZ" ]
537 ewarn "Warning: unknown timezone $KTZ"; eend 0
539 einfo "Setting timezone."
541 area=$(echo $KTZ | cut -d '/' -f1)
542 zone=$(echo $KTZ | cut -d '/' -f2)
543 echo "tzdata tzdata/Areas select $area" | debconf-set-selections
544 echo "tzdata tzdata/Zones/$area select $zone" | debconf-set-selections
546 echo $KTZ > /etc/timezone
548 cp "/usr/share/zoneinfo/$KTZ" /etc/localtime ; eend $?
555 # activate serial console {{{
557 if checkbootparam 'console'; then
562 einfo "Bootoption for serial console detected:"
566 line="${line#*[$ws]}"
568 while [ -n "$line" ]; do
572 local device="${this%%,*}"
573 local device="${device##*=}"
574 if echo $serial | grep -q ttyS ; then
575 local option="${serial##*,}"
576 # default (works for kvm & CO):
577 local speed="115200,57600,38400,19200,9600,4800,2400,1200";
578 # ... unless overriden by command line:
580 115200*) speed=115200 ;;
581 57600*) speed=57600 ;;
582 38400*) speed=38400 ;;
583 19200*) speed=19200 ;;
590 einfo "Activating console login on device ${device} with speed ${speed}."
591 local number="${device#ttyS}"
592 sed -i "/^T$number:/d;/^#grmlserial#/iT$number:23:respawn:/bin/bash -c \"/sbin/getty -L $device -l /usr/share/grml-scripts/run-welcome $speed vt100 || sleep 30\"" /etc/inittab
599 this="${line%%[$ws]*}"
600 line="${line#*[$ws]}"
603 if [ -n "$telinitq" ]; then
613 if checkbootparam 'testcd' ; then
614 einfo "Checking CD data integrity as requested by '${WHITE}testcd${NORMAL}' boot option."
618 local FOUND_FILE=false
619 local logfile='/tmp/md5sum.log'
623 for md5 in $(find "${LIVECD_PATH}" -name md5sums) ; do
624 einfo "Checking files against $md5, this may take a while..."
629 md5sum -c $(basename "$md5") |& tee -a "${logfile}"
630 if [ $pipestatus[1] -eq 0 ] ; then
636 if ! $FOUND_FILE ; then
637 eerror 'Error: Could not find md5sum file' ; eend 1
642 einfo "Everything looks OK" ; eend 0
644 eerror 'Checksum failed for theses files:' ; eend 1
645 egrep -v '(^md5sum:|OK$)' "${logfile}"
646 eerror 'Data on the medium is possibly incomplete/damaged or RAM of your system is broken.' ; eend 1
647 einfon "Hit return to continue, or press the power button to shut down system."
656 # {{{ blacklist specific module [ used in /etc/init.d/udev ]
658 if checkbootparam 'blacklist' ; then
659 if [ -z "$INSTALLED" ]; then
660 einfo "Bootoption blacklist found."
661 BLACK="$(getbootparam 'blacklist' 2>>$DEBUG)"
662 BLACKLIST_FILE='/etc/modprobe.d/grml.conf'
663 if [ -n "$BLACK" ] ; then
664 for module in $(echo ${BLACK//,/ }) ; do
665 einfo "Blacklisting module ${module} via ${BLACKLIST_FILE}."
666 echo "# begin entry generated by config_blacklist of grml-autoconfig" >> "$BLACKLIST_FILE"
667 echo "blacklist $module" >> "$BLACKLIST_FILE"
668 echo "alias $module off" >> "$BLACKLIST_FILE"
669 echo "# end entry generated by config_blacklist of grml-autoconfig" >> "$BLACKLIST_FILE" ; eend $?
672 eerror "No given module for blacklist found. Blacklisting will not work therefore."
675 ewarn "Backlisting via bootoption is not intended for use on harddisk installations." ; eend 1
677 einfo "Please blacklist the module(s) manually using the 'blacklist' script."
686 if checkbootparam 'noacpi'; then
687 ewarn "ACPI: Not loading modules as requested by boot option \"noacpi\"." ; eend 0
688 elif checkbootparam 'nogrmlacpi' ; then
689 ewarn "ACPI: Not loading modules as requested by boot option \"nogrmlacpi\"." ; eend 0
690 elif [ ! -d /proc/acpi ] ; then
691 ewarn "ACPI: Kernel support not present." ; eend 0
693 einfo "ACPI: Loading modules (disable with boot option noacpi / nogrmlacpi): "
696 for a in /lib/modules/$KERNEL/kernel/drivers/acpi/*; do
698 basename="${basename%%.*}"
699 case "$basename" in *_acpi)
700 egrep -qi "${basename%%_acpi}" /proc/acpi/dsdt 2>>$DEBUG || continue ;;
702 modprobe $basename >>$DEBUG 2>&1 && found="yes"
703 local BASE="$BASE $basename"
705 if [ -n "$found" ] ; then
706 einfo "$BASE" ; eend 0
708 ewarn "(none)" ; eend 1
710 if ! pgrep acpid >/dev/null ; then
711 einfo "Starting acpi daemon."
712 $SYSTEMD && systemctl start acpid.socket
713 /etc/init.d/acpid start >>$DEBUG 2>&1 ; eend $?
715 ewarn "acpi daemon already running."
725 if checkbootparam 'brltty' ; then
726 [ -x /lib/brltty/brltty.sh ] && /lib/brltty/brltty.sh
731 # {{{ Start creating /etc/fstab with HD partitions and USB SCSI devices now
734 NOSWAP="yes" # we do not use swap by default!
735 if checkbootparam 'swap' || checkbootparam 'anyswap' ; then
737 checkbootparam 'anyswap' && export ANYSWAP='yes' || export ANYSWAP=""
740 # Scan for swap, config, homedir - but only in live-mode
741 if [ -z "$INSTALLED" ] ; then
742 [ -z "$NOSWAP" ] && einfo "Searching for swap partition(s) as requested."
745 HOMEDIR="$(getbootparam 'home')"
746 if [ -n "$partitions" ]; then
747 while read p m f relax; do
748 case "$p" in *fd0*|*proc*|*sys*|*\#*) continue;; esac
749 partoptions="users,exec"
751 # it's a swap partition?
754 if [ -n "$NOSWAP" ]; then
755 ewarn "Ignoring swap partition ${WHITE}$p${NORMAL}. (Force usage via boot option 'swap', or execute grml-swapon)"
758 case "$(dd if=$p bs=1 count=6 skip=4086 2>/dev/null)" in
759 S1SUSP|S2SUSP|pmdisk|[zZ]*)
760 if [ -n "$ANYSWAP" ] ; then
761 einfo "Using swap partition ${WHITE}${p}${NORMAL} [bootoption anyswap found]."
762 swapon $p 2>>$DEBUG ; eend $?
764 ewarn "Suspend signature on ${WHITE}${p}${NORMAL} found, not using as swap. (Force usage via boot option: anyswap)"
768 if [[ "$p" == LABEL* ]] ; then
769 p=$(blkid -t $p | awk -F: '{print $1}')
771 if grep -q $p /proc/swaps ; then
772 ewarn "Not using swap partition ${WHITE}${p}${NORMAL} as it is already in use." ; eend 0
774 if [ -b "$p" ] ; then
775 einfo "Using swap partition ${WHITE}${p}${NORMAL}."
776 swapon $p 2>>$DEBUG ; eend $?
778 ewarn "$p is not a valid block device - not using it therefore." ; eend 0
787 esac # it's a swap partition?
792 vfat|msdos|ntfs) MOUNTOPTS="$MOUNTOPTS,uid=${fstabuser},gid=${fstabuser}" ;;
793 ext2|ext3|reiserfs|jfs|reiser4|xfs) MOUNTOPTS="$MOUNTOPTS,noatime" ;;
795 # *) NONEFOUND='1'; continue ;;
799 if [ -z "$NOSWAP" ] ; then
800 mount -o "$MOUNTOPTS" -t $f $p $m 2>>$DEBUG && MOUNTED=1 || continue
801 # Activate swapfile, if exists
802 SWAPFILE="$(/bin/ls -1d $m/[Gg][Rr][Mm][Ll].[Ss][Ww][Pp] 2>/dev/null)"
804 if [ -z "$NOSWAP" -a -n "$SWAPFILE" -a -f "$SWAPFILE" ]; then
805 mount -o remount,rw $m && MOUNTED=1
806 if swapon "$SWAPFILE" 2>>$DEBUG ; then
808 einfo "Using GRML swapfile ${WHITE}${SWAPFILE}${NORMAL}."
810 fnew="$SWAPFILE swap swap defaults 0 0"
811 grep -q "$fnew" "/etc/fstab" || echo "$fnew" >> /etc/fstab
812 GRML_SWP="$GRML_SWP $SWAPFILE"
815 mount -o remount,ro $m 2>>$DEBUG && MOUNTED=1
818 # use a image as home
819 IMAGE="$(/bin/ls -1d $m/[Gg][Rr][Mm][Ll].[Ii][Mm][Gg] 2>/dev/null)"
820 if [ -z "$GRML_IMG" -a -n "$IMAGE" -a -f "$IMAGE" ]; then
821 if [ -n "$HOMEDIR" ]; then
822 if [ "$HOMEDIR" != "scan" -a "$HOMEDIR" != "$IMAGE" -a "$HOMEDIR" != "${IMAGE%/*.*}" ]; then
826 if type -a grml-image >/dev/null 2>&1 && grml-image "$IMAGE" </dev/console >/dev/console 2>&1; then
828 mount -o remount,ro $m 2>>$DEBUG && MOUNTED=1
833 # Umount, if not in use
834 [ -n "$MOUNTED" ] && umount -r $m 2>/dev/null
846 if checkbootparam 'nocpu'; then
847 ewarn "Skipping CPU detection as requested on boot commandline." ; eend 0
851 if [[ $(grep -c processor /proc/cpuinfo) -gt 1 ]] ; then
853 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)
854 echo $CPU | sed 's/ \{1,\}/ /g'
857 einfo "Found 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
860 # no cpufreq setup inside VirtualBox
861 if $VIRTUALBOX ; then
862 einfo 'Virtual Box detected, skipping cpufreq setup.' ; eend 0
866 if [ -x /etc/init.d/loadcpufreq ] ; then
867 einfo "Trying to set up cpu frequency scaling:"
870 LOADCPUFREQ=$(mktemp)
871 /etc/init.d/loadcpufreq start >"$LOADCPUFREQ" 2>&1 ; RC=$?
872 if grep -q FATAL "$LOADCPUFREQ" ; then
878 for line in $(grep FATAL "$LOADCPUFREQ" | sed 's/.*FATAL: //; s/ (.*)//') ; do
879 eerror "$line" ; eend $RC
883 elif grep -q done "$LOADCPUFREQ" ; then
884 MODULE=$(grep done "$LOADCPUFREQ" | sed 's/.*done (\(.*\))./\1/')
885 if [ -n "$MODULE" -a "$MODULE" != none ]; then
886 einfo "Loading cpufreq kernel module $MODULE" ; eend 0
889 ewarn "Could not find an appropriate kernel module for cpu frequency scaling." ; eend 1
895 if [ -z "$SKIP_CPU_GOVERNOR" ] ; then
896 if [ -r /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors ] ; then
897 if ! grep -q ondemand /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors ; then
898 einfo "Ondemand governor not available for CPU(s), not modifying governor configuration"
900 einfo "Setting ondemand governor"
902 for file in $(find /sys/devices/system/cpu/ -name scaling_governor 2>/dev/null) ; do
903 echo ondemand > $file || RC=1
915 # {{{ autostart of ssh
917 if checkbootparam 'ssh' ; then
919 PASSWD="$(getbootparam 'ssh' 2>>$DEBUG)"
922 einfo "Bootoption ssh found, trying to set password for root and user $localuser"
923 [ -z "$localuser" ] && eend 1
926 if [ -z "$PASSWD" ] ; then
927 set_passwd && ewarn "No given password for found. Using random password: $PASSWD" && eend 0
931 if [ -n "$PASSWD" ] ; then
933 if chpasswd --help 2>&1 | grep -q -- '-m,' ; then
937 echo "$localuser:$PASSWD" | chpasswd $chpass_options
938 echo "root:$PASSWD" | chpasswd $chpass_options
941 ewarn "Warning: please change the password for root and user $localuser as soon as possible!"
945 einfo "Starting secure shell server in background for root and user $localuser"
946 /etc/init.d/rmnologin start >>$DEBUG 2>>$DEBUG
947 /etc/init.d/ssh start >>$DEBUG 2>>$DEBUG &
955 # {{{ display hostkeys of SSH server
956 config_display_ssh_fingerprints() {
957 if ! ls /etc/ssh/ssh_host_\*_key >/dev/null 2>&1 ; then
958 return 0 # no SSH host keys present
961 einfo "SSH key fingerprints:"
962 for file in /etc/ssh/ssh_host_*_key ; do
964 ssh-keygen -l -f $file
970 # {{{ autostart of x11vnc
972 if checkbootparam 'vnc' ; then
975 VNC_PASSWD="$(getbootparam 'vnc' 2>>$DEBUG)"
976 einfo "Bootoption vnc found, trying to set password for user $localuser."
978 if [ -z "$VNC_PASSWD" ] ; then
979 if [ -x /usr/bin/apg ] ; then
980 VNC_PASSWD="$(apg -M NL -a 0 -m 8 -x 12 -n 1)"
981 elif [ -x /usr/bin/gpw ] ; then
982 VNC_PASSWD="$(gpw 1)"
983 elif [ -x /usr/bin/pwgen ] ; then
984 VNC_PASSWD="$(pwgen -1 8)"
985 elif [ -x /usr/bin/hexdump ] ; then
986 VNC_PASSWD="$(dd if=/dev/urandom bs=14 count=1 2>/dev/null | hexdump | awk '{print $3 $4}')"
987 elif [ -n "$RANDOM" ] ; then
988 VNC_PASSWD="${localuser}${RANDOM}"
991 eerror "Empty passphrase and neither pwgen nor hexdump nor \$RANDOM found. Skipping."
995 if [ -n "$VNC_PASSWD" ] ; then
996 ewarn "No given password for vnc found. Using random password: $VNC_PASSWD" ; eend 0
1001 # finally check if we have a password we can use:
1002 if [ -n "$VNC_PASSWD" ] ; then
1004 VNCDIR="/home/${localuser}/.vnc"
1005 [ -d "$VNCDIR" ] || mkdir "$VNCDIR"
1007 if [ ! -x /usr/bin/x11vnc ] ; then
1008 eerror "Error: x11vnc not found - can not set up vnc. Please make sure to install the x11vnc package."
1011 /usr/bin/x11vnc -storepasswd "$VNC_PASSWD" "$VNCDIR"/passwd ; eend $?
1012 /bin/chown -R "$localuser": "$VNCDIR"
1015 if checkbootparam 'vnc_connect' ; then
1017 VNC_CONNECT="$(getbootparam 'vnc_connect' 2>>$DEBUG)"
1018 einfo "Bootoption vnc_connect found, will start vnc with connect to $VNC_CONNECT."
1019 #store the options in a file
1020 VNCDIR="/home/${localuser}/.vnc"
1021 [ -d "$VNCDIR" ] || mkdir "$VNCDIR"
1022 echo " --connect $VNC_CONNECT " >> $VNCDIR/options
1028 # {{{ set password for root and default user
1030 if checkbootparam 'passwd' >>$DEBUG 2>&1; then
1032 PASSWD="$(getbootparam 'passwd' 2>>$DEBUG)"
1035 einfo "Bootoption passwd found, trying to set password for root and user $localuser"
1036 [ -z "$localuser" ] && eend 1
1039 if [ -z "$PASSWD" ] ; then
1040 set_passwd && ewarn "No given password for found. Using random password: $PASSWD" && eend 0
1044 if [ -n "$PASSWD" ] ; then
1046 if chpasswd --help 2>&1 | grep -q -- '-m,' ; then
1050 echo "$localuser:$PASSWD" | chpasswd $chpass_options
1051 echo "root:$PASSWD" | chpasswd $chpass_options
1054 ewarn "Warning: please change the password for root and user $localuser as soon as possible!"
1060 if checkbootparam 'encpasswd' >>$DEBUG 2>&1; then
1062 PASSWD="$(getbootparam 'encpasswd' 2>>$DEBUG)"
1064 if [ -z "$PASSWD" ] ; then
1065 eerror "No hashed password found, can not set password."
1071 einfo "Bootoption encpasswd found, trying to set hashed password for root and user $localuser"
1072 [ -z "$localuser" ] && eend 1
1074 if [ -n "$PASSWD" ] ; then
1077 echo "$localuser:$PASSWD" | chpasswd $chpass_options
1078 echo "root:$PASSWD" | chpasswd $chpass_options
1081 ewarn "Warning: please change the password for root and user $localuser as soon as possible!"
1091 if ! [ -x /usr/bin/amixer ] ; then
1092 eerror "amixer binary not available. Can not set sound volumes therefore."
1095 if ! [ -r /proc/asound/cards ] ; then
1096 ewarn "No soundcard present, skipping mixer settings therefore."
1101 for card in $(cat /proc/asound/cards| grep -e '^\s*[0-9]' | awk '{print $1}') ; do
1102 einfo "Configuring soundcard \"$(awk -F\[ '/^ *'$card' \[/{ FS=" "; $0=$2; print $1}' < /proc/asound/cards)\""
1105 if checkbootparam 'vol' ; then
1106 VOL="$(getbootparam 'vol' 2>>$DEBUG)"
1107 if [ -z "$VOL" ] ; then
1108 eerror "Bootoption vol found but no volume level/parameter given. Using defaults (75%)."
1116 if checkbootparam 'nosound' ; then
1117 einfo "Muting sound devices on request."
1118 ERROR=$(amixer -q set Master mute)
1120 if [ -n "$ERROR" ] ; then
1122 eerror "Problem muting sound devices: $ERROR"
1126 elif [ -z "$INSTALLED" ] ; then
1127 einfo "Setting mixer volumes to level ${WHITE}${VOL}${NORMAL}."
1129 if checkbootparam 'micvol' ; then
1130 MICVOL="$(getbootparam 'micvol' 2>>$DEBUG)"
1131 einfo "Setting microphone to ${WHITE}${MICVOL}${NORMAL}."
1136 CONTROLS=$(amixer -c $card scontrols | awk -F"Simple mixer control " '{print $2}')
1140 for CONTROL in ${=CONTROLS} ; do
1141 # such devices can not be controlled with amixer ... unmute
1142 [[ "$CONTROL" == *Console* ]] && continue
1144 if ! echo "${CONTROL}" | grep -q -i "mic" ; then
1145 if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*pswitch' ; then
1146 amixer -c $card -q set "${CONTROL}" unmute
1148 if amixer -c $card sget "${CONTROL}" | grep -q -P 'Capabilities:.*(pvolume| volume)' ; then
1149 amixer -c $card -q set "${CONTROL}" "${VOL}"%
1153 if [ ${MICVOL} -ne 0 ] ; then
1154 if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*cswitch' ; then
1155 amixer -c $card -q set "${CONTROL}" unmute
1157 if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*cvolume' ; then
1158 amixer -c $card -q set "${CONTROL}" $MICVOL%
1164 fi # checkbootparam 'nosound'
1171 # {{{ syslog service
1173 if checkbootparam 'nosyslog'; then
1174 ewarn "Not starting syslog daemon as requested on boot commandline." ; eend 0
1177 [ -x /etc/init.d/syslog-ng ] && SYSLOGD='syslog-ng'
1178 [ -x /etc/init.d/rsyslog ] && SYSLOGD='rsyslog'
1179 [ -x /etc/init.d/dsyslog ] && SYSLOGD='dsyslog'
1180 [ -x /etc/init.d/sysklogd ] && SYSLOGD='sysklogd'
1181 [ -x /etc/init.d/inetutils-syslogd ] && SYSLOGD='inetutils-syslogd'
1183 if [ -z "$SYSLOGD" ] ; then
1184 eerror "No syslog daemon found." ; eend 1
1186 einfo "Starting $SYSLOGD in background."
1187 /etc/init.d/$SYSLOGD start >>$DEBUG &
1196 if checkbootparam 'nogpm'; then
1197 ewarn "Not starting GPM as requested on boot commandline." ; eend 0
1199 if ! [ -r /dev/input/mice ] ; then
1200 eerror "No mouse found - not starting GPM." ; eend 1
1202 einfo "Starting gpm in background."
1203 /etc/init.d/gpm start >>$DEBUG &
1204 # ( while [ ! -e /dev/psaux ]; do sleep 5; done; /etc/init.d/gpm start >>$DEBUG ) &
1213 if checkbootparam 'services' ; then
1214 SERVICE="$(getbootparam 'services' 2>>$DEBUG)"
1215 SERVICELIST=$(echo "$SERVICE" | sed 's/,/\\n/g')
1216 SERVICENL=$(echo "$SERVICE" | sed 's/,/ /g')
1217 for service in $(echo -e $SERVICELIST) ; do
1218 # support running (custom) init scripts in non-blocking mode
1219 # if they contain the keyword "DO_NO_RUN_IN_BACKGROUND".
1220 if grep -q 'DO_NO_RUN_IN_BACKGROUND' "/etc/init.d/${service}" 2>>$DEBUG ; then
1221 einfo "Starting service ${service}."
1222 /etc/init.d/${service} start >>$DEBUG
1224 einfo "Starting service ${service} in background."
1225 /etc/init.d/${service} start >>$DEBUG &
1235 [ "$#" -eq 2 ] || ( echo "Error: wrong parameter for get_remote_file()" ; return 1 )
1236 SOURCE=$(eval echo "$1")
1239 wget --timeout=10 --dns-timeout=10 --connect-timeout=10 --tries=1 \
1240 --read-timeout=10 ${SOURCE} -O ${TARGET} && return 0 || return 1
1242 einfo "Trying to get ${WHITE}${TARGET}${NORMAL}"
1244 if checkbootparam 'getfile.retries' ; then
1245 local counter="$(getbootparam 'getfile.retries' 2>>$DEBUG)"
1250 while ! getconfig && [[ "$counter" != 0 ]] ; do
1251 echo -n "Sleeping for 1 second and trying to get config again... "
1252 counter=$(( counter-1 ))
1253 echo "$counter tries left" ; sleep 1
1255 if [ -s "$TARGET" ] ; then
1256 einfo "Downloading was successfull." ; eend 0
1257 einfo "md5sum of ${WHITE}${TARGET}${NORMAL}: "
1258 md5sum ${TARGET} ; eend 0
1261 einfo "Sorry, could not fetch ${SOURCE}" ; eend 1
1269 if checkbootparam 'netconfig' ; then
1270 CONFIG="$(getbootparam 'netconfig' 2>>$DEBUG)"
1271 CONFIGFILE='/tmp/netconfig.grml'
1273 if get_remote_file ${CONFIG} ${CONFIGFILE} ; then
1274 cd / && einfo "Unpacking ${WHITE}${CONFIGFILE}${NORMAL}:" && /usr/bin/unp $CONFIGFILE $EXTRACTOPTIONS ; eend $?
1281 # {{{ remote scripts
1282 config_netscript() {
1283 if checkbootparam 'netscript' ; then
1284 CONFIG="$(getbootparam 'netscript' 2>>$DEBUG)"
1285 SCRIPTFILE='/tmp/netscript.grml'
1287 if get_remote_file ${CONFIG} ${SCRIPTFILE} ; then
1288 chmod +x ${SCRIPTFILE}
1289 einfo "Running ${WHITE}${SCRIPTFILE}${NORMAL}:" && NETSCRIPT=${CONFIG} ${SCRIPTFILE} ; eend $?
1298 if ! checkbootparam 'nostats' ; then
1299 BASE_URL="http://stats.grml.org/report/"
1302 HOST_ID=$(cat /proc/sys/kernel/random/boot_id)
1304 grep -q " lm " /proc/cpuinfo && HAS_64BIT="1" || HAS_64BIT="0"
1305 DATE_STRING=$(date +'h=%H&m=%M&s=%S')
1306 [ -e /etc/grml_version ] && VERSION=$(cat /etc/grml_version) || \
1307 VERSION=$(lsb_release -d | awk -F: '{gsub(/^[ \t]+/, "", $2); print $2}')
1309 PARAMS="$( echo "$CMDLINE" | sed -e 's/=[^ ]*/=x/g' | tr " " "\n"|sort|tr "\n" " " )"
1311 echo "$CMDLINE" | grep -q -e "fetch" -e "nfsroot" && BOOT="remote"
1312 [ -z "$BOOT" ] && BOOT="local"
1314 ADDITIONAL_PARAMS=""
1315 ( [ -n "$COLUMNS" ] && [ -n "$LINES" ] ) && \
1316 ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS&res=$((COLUMNS * 8))x$((LINES * 16))"
1318 URI='$BASE_URL?action=${ACTION_NAME}\&$DATE_STRING\&unique_id=${HOST_ID}\&support_64bit=$HAS_64BIT\&version=$VERSION\&bootup=$BOOT\¶ms=$PARAMS$ADDITIONAL_PARAMS'
1320 get_remote_file "$URI" "/dev/null" >/dev/null 2>&1 &!
1325 # {{{ start X window system via grml-x
1327 # make sure we start X only if startx is used *before* a nostartx option
1328 # so it's possible to disable automatic X startup using nostart
1329 if checkbootparam 'startx' && ! echo "$CMDLINE" | grep -q 'startx.*nostartx' ; then
1330 if [ -x "$(which X)" ] ; then
1331 if [ -z "$INSTALLED" ] ; then
1332 WINDOWMANAGER="$(getbootparam 'startx' 2>>$DEBUG)"
1333 if [ -z "$WINDOWMANAGER" ] ; then
1334 einfo "No window manager specified. Using default one." && eend 0
1336 einfo "Window manager ${WHITE}${WINDOWMANAGER}${NORMAL} found as bootoption." && eend 0
1338 einfo "Setting up and invoking grml-x ${WINDOWMANAGER}. Just exit X windows system to get full featured consoles."
1340 cat>|/etc/init.d/xstartup<<EOF
1342 su $localuser -c "/usr/bin/grml-x ${WINDOWMANAGER}"
1344 chmod 755 /etc/init.d/xstartup
1346 # adjust inittab for xstartup
1347 if grep -q '^6:' /etc/inittab ; then
1348 sed -i 's|^6:.*|6:2345:respawn:/bin/zsh --login -c "/etc/init.d/xstartup ; /usr/share/grml-scripts/run-welcome" >/dev/tty6 2>\&1 </dev/tty6|' /etc/inittab
1349 else # just append tty6 to inittab if no definition is present:
1350 echo '6:2345:respawn:/bin/zsh --login -c "/etc/init.d/xstartup ; /usr/share/grml-scripts/run-welcome" >/dev/tty6 2>&1 < /dev/tty6' >> /etc/inittab
1353 /sbin/telinit q ; eend $?
1355 if grep -q '^allowed_users=' /etc/X11/Xwrapper.config ; then
1356 sed -i 's/^allowed_users=.*/allowed_users=anybody/' /etc/X11/Xwrapper.config
1358 echo 'allowed_users=anybody' >> /etc/X11/Xwrapper.config
1362 eerror "We are not running in live mode - startx will not work, skipping it."
1363 eerror " -> Please use something like xdm, gdm or kdm for starting X on a harddisk system!" ; eend 1
1366 eerror "/usr/bin/X is not present on this grml flavour."
1367 eerror " -> Boot parameter startx does not work therefore." ; eend 1
1373 # {{{ configuration framework
1375 if checkbootparam 'extract' ; then
1376 EXTRACT="$(getbootparam 'extract' 2>>$DEBUG)"
1377 EXTRACTOPTIONS="-- -x $EXTRACT"
1381 config_finddcsdir() {
1382 # - If no GRMLCFG partition is found and noautoconfig is _not_ given
1383 # on the command line, nothing is changed and the dcs files are
1384 # searched within the .iso, $dcs-dir is set to the root directory
1386 # - If a GRMLCFG partition is found, $dcs-dir is set to the root of
1387 # the GRMLCFG partition unless noautoconfig is set. If noautoconfig is
1388 # set, $dcs-dir is set to the root directory within the .iso.
1389 # - If myconfig=foo is set on the command line, $dcs-dir is set to
1390 # foo, even if a GRMLCFG partition is present.
1393 # autoconfig, see issue673
1394 GRMLCFG="$(getbootparam 'autoconfig' 2>>$DEBUG)"
1395 [ -n "$GRMLCFG" ] || GRMLCFG="GRMLCFG"
1396 if checkbootparam 'noautoconfig' ; then
1397 DCSDIR="${LIVECD_PATH}" # set default so it works for "scripts" boot option as expected
1398 ewarn "Skipping running automount of device(s) labeled $GRMLCFG as requested." ; eend 0
1400 if [ -z "$INSTALLED" ] ; then
1401 if checkbootparam 'myconfig' ; then
1402 DCSDEVICE="$(getbootparam 'myconfig' 2>>$DEBUG)"
1403 if [ -z "$DCSDEVICE" ]; then
1404 eerror "Error: No device for bootoption myconfig provided." ; eend 1
1405 fi # [ -z "$DCSDEVICE" ]
1406 elif checkvalue $CONFIG_MYCONFIG; then # checkbootparam myconfig
1407 einfo "Searching for device(s) labeled with $GRMLCFG. (Disable this via boot option: noautoconfig)" ; eend 0
1409 DCSDEVICE=$(blkid -t LABEL=$GRMLCFG | head -1 | awk -F: '{print $1}')
1411 modprobe 9p 2>/dev/null || true
1412 if [ -z "$DCSDEVICE" ] && grep -q 9p /proc/filesystems ; then
1413 if grep -q "$GRMLCFG" /sys/bus/virtio/devices/*/mount_tag 2>/dev/null ; then
1414 einfo "Found 9p-virtio fs with mount_tag $GRMLCFG"
1415 DCSDEVICE="$GRMLCFG"
1416 MOUNTOPTIONS="ro,trans=virtio"
1421 if [ -n "$DCSDEVICE" ]; then
1422 DCSMP="/mnt/grmlcfg"
1427 # if not specified/present then assume default:
1428 if [ -z "$DCSDEVICE" ]; then
1429 DCSDIR="${LIVECD_PATH}"
1432 einfo "debs, config, scripts are read from $DCSDEVICE." ; eend 0
1433 DCSDIR="$(< /proc/mounts awk -v DCSDEV=$DCSDEVICE '{if ($1 == DCSDEV) { print $2 }}')"
1434 if [ -n "$DCSDIR" ]; then
1435 ewarn "$DCSDEVICE already mounted on $DCSDIR"; eend 0
1437 [ -d $DCSMP ] || mkdir $DCSMP
1438 umount $DCSMP >>$DEBUG 2>&1 # make sure it is not mounted
1439 mount -o ${MOUNTOPTIONS:-ro} -t ${DCSFS:-auto} $DCSDEVICE $DCSMP ; RC="$?"
1440 if [[ $RC == 0 ]]; then
1441 einfo "Successfully mounted $DCSDEVICE to $DCSMP (readonly)." ; eend 0
1443 eerror "Error: mounting $DCSDEVICE to $DCSMP (readonly) failed." ; eend 1
1452 if [ -n "$DCSDIR" -a "$DCSDIR" != "${LIVECD_PATH}" ] ; then
1453 einfo "Debs, config, scripts (if present) will be read from $DCSDIR." ; eend 0
1454 elif checkbootparam 'debs' || checkbootparam 'config' || checkbootparam 'scripts'; then
1455 einfo "Debs, config, scripts will be read from the live image directly." ; eend 0
1461 if checkbootparam 'partconf' ; then
1462 MOUNTDEVICE="$(getbootparam 'partconf' 2>>$DEBUG)"
1463 if [ -n "$MOUNTDEVICE" ]; then
1464 [ -d /mnt/grml ] || mkdir /mnt/grml
1465 mount -o ro -t auto $MOUNTDEVICE /mnt/grml ; RC="$?"
1466 if [[ $RC == 0 ]]; then
1467 einfo "Successfully mounted $MOUNTDEVICE to /mnt/grml (readonly)." ; eend 0
1468 einfo "Copying files from $MOUNTDEVICE over grml system."
1469 for file in `cat /etc/grml/partconf` ; do
1470 [ -d /mnt/grml/$file ] && cp -a /mnt/grml/${file}* ${file} && echo "copied: $file"
1471 [ -f /mnt/grml/$file ] && cp -a /mnt/grml/${file} ${file} && echo "copied: $file"
1474 einfo "Could not mount $MOUNTDEVICE to /mnt/grml - sorry." ; eend 1
1475 fi # mount $MOUNTDEVICE
1476 grep -q '/mnt/grml' /proc/mounts && umount /mnt/grml
1478 einfo "Sorry, no device for bootoption partconf provided. Skipping." ; eend 1
1479 fi # [ -n "$MOUNTDEVICE" ]
1484 # {{{ /cdrom/.*-options
1486 if checkbootparam 'debs' ; then
1487 iszsh && setopt localoptions shwordsplit
1488 DEBS="$(getbootparam 'debs' 2>>$DEBUG)"
1489 if [ -z "$DEBS" ] ; then
1492 if ! echo $DEBS | grep -q '/'; then
1493 # backwards compatibility: if no path is given get debs from debs/
1496 einfo "Trying to install Debian package(s) ${DEBS}"
1497 DEBS="$(eval echo ${DCSDIR}/$DEBS)"
1498 dpkg -i $DEBS ; eend $?
1503 if checkbootparam 'scripts' || [ "$DCSMP" = "/mnt/grmlcfg" ]; then
1504 SCRIPTS="$(getbootparam 'scripts' 2>>$DEBUG)"
1505 if [ -d ${DCSDIR}/scripts ] && [ -z "$SCRIPTS" ]; then
1506 SCRIPTS="$(cd ${DCSDIR}/scripts; /bin/ls -1d [Gg][Rr][Mm][Ll].[Ss][Hh] 2>>$DEBUG)"
1508 if ! echo $SCRIPTS | grep -q '/'; then
1509 # backwards compatibility: if no path is given get scripts from scripts/
1510 SCRIPTS="scripts/$SCRIPTS"
1512 if [ -n "$SCRIPTS" ]; then
1513 SCRIPTS="${DCSDIR}/$SCRIPTS"
1514 if [ "$DCSMP" = "/mnt/grmlcfg" ]; then
1515 einfo "Trying to execute ${SCRIPTS}"
1518 elif [ -d "$SCRIPTS" ]; then
1519 einfo "Bootparameter scripts found. Trying to execute from directory ${SCRIPTS}:"
1520 run-parts --regex '.*' $SCRIPTS
1523 einfo "Bootparameter scripts found. Trying to execute ${SCRIPTS}:"
1532 if checkbootparam 'config' || [ "$DCSMP" = "/mnt/grmlcfg" ]; then
1533 CONFIG="$(getbootparam 'config' 2>>$DEBUG)"
1534 if [ -z "$CONFIG" ]; then
1535 CONFIG="$(cd ${DCSDIR}; ls -1d [Cc][Oo][Nn][Ff][Ii][Gg].[Tt][Bb][Zz] 2>>$DEBUG)"
1537 if [ -n "$CONFIG" ]; then
1538 if [ -d "${DCSDIR}/${CONFIG}" ] ; then
1539 einfo "Taking configuration from directory ${DCSDIR}/${CONFIG}"
1541 cp -a ${DCSDIR}/${CONFIG}/* /
1542 elif [ -f "${DCSDIR}/${CONFIG}" ]; then
1543 einfo "Extracting configuration from file ${DCSDIR}/${CONFIG}"
1546 unp ${DCSDIR}/${CONFIG} $EXTRACTOPTIONS ; eend $?
1548 ewarn "Sorry, could not find configuration file or directory ${DCSDIR}/${FILENAME}." ; eend 1
1555 # {{{ confing_umount_dcsdir
1556 config_umount_dcsdir(){
1557 # umount $DCSMP if it was mounted by finddcsdir
1558 grep -q "$DCSMP" /proc/mounts && umount "$DCSMP"
1564 if checkbootparam 'mypath' ; then
1565 MY_PATH="$(getbootparam 'mypath' 2>>$DEBUG)"
1566 einfo "Bootparameter mypath found, adding ${MY_PATH} to /etc/grml/my_path"
1567 touch /etc/grml/my_path
1568 chmod 644 /etc/grml/my_path
1569 # make sure the directories exist:
1571 for i in $(echo $MY_PATH | sed 's/:/\n/g') ; do
1572 if ! [ -d "$i" ] ; then
1573 einfo "Creating directory $i"
1574 mkdir -p "$i" ; eend $?
1577 grep -q "${MY_PATH}" /etc/grml/my_path || echo "${MY_PATH}" >> /etc/grml/my_path ; eend $?
1585 [ -n "$INSTALLED" ] && return 0
1587 if checkbootparam 'noraid' || checkbootparam 'noswraid' || \
1588 checkbootparam 'raid=noautodetect' ; then
1589 ewarn "Skipping SW-RAID code as requested on boot commandline." ; eend 0
1591 [ -e /proc/mdstat ] || modprobe md_mod
1592 if ! [ -x /sbin/mdadm ] ; then
1593 eerror "mdadm not available, can not execute it." ; eend 1
1596 # if ! egrep -qv '^(MAILADDR.*|#.*|)$' /etc/mdadm/mdadm.conf 2>>$DEBUG ; then
1597 # find out whether we have a valid configuration file already
1598 if ! grep -q ARRAY /etc/mdadm/mdadm.conf 2>>$DEBUG ; then
1599 einfo "Creating /etc/mdadm/mdadm.conf for use with mdadm."
1600 [ -r /etc/mdadm/mdadm.conf ] && mv /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf.old
1601 MDADM_MAILADDR__='root' /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf ; eend $?
1603 ewarn "/etc/mdadm/mdadm.conf looks like a configured mdadm setup, will not touch it." ; eend 0
1606 if ! checkbootparam 'swraid' ; then
1608 einfo "Just run 'Start mdadm-raid' to assemble md arrays or boot using 'swraid' as bootoption for autostart."
1611 einfo "Bootoption swraid found. Searching for software RAID arrays:"
1616 for line in $(mdadm --assemble --scan --auto=yes --symlink=no 2>&1) ; do
1618 *'No arrays found'*)
1619 ewarn "$line" ; eend 0
1622 einfo "$line" ; eend 0
1629 if [ -r /proc/mdstat ] ; then
1631 MDSTAT=$(grep '^md[0-9]' /proc/mdstat)
1632 if [ -z "$MDSTAT" ] ; then
1633 ewarn "No active arrays found" ; eend 0
1638 for line in $(grep '^md[0-9]' /proc/mdstat) ; do
1639 einfo "active arrays: $line" ; eend 0
1645 fi # bootoption swraid
1647 fi # is /sbin/mdadm executable?
1648 fi # check for bootoptions
1654 [ -n "$INSTALLED" ] && return 0
1656 if checkbootparam 'nodmraid' ; then
1657 ewarn "Skipping dmraid code as requested on boot commandline." ; eend 0
1661 if ! [ -x /sbin/dmraid ] ; then
1662 eerror "dmraid not available, can not execute it." ; eend 1
1667 # usage: dmraid_wrapper <dmraid_option>
1668 [ -n "$1" ] || return 1
1675 for line in $(dmraid $1 ; echo errcode:$?); do
1677 *'no block devices found'*)
1678 einfo "No block devices found" ; eend 0
1682 einfo "No active dmraid devices found" ; eend 0
1701 if checkbootparam 'dmraid' ; then
1702 local ACTION="$(getbootparam 'dmraid' 2>>$DEBUG)"
1703 if [ "$ACTION" = "off" ] ; then
1704 # Deactivates all active software RAID sets:
1705 einfo "Deactivating present dmraid sets (as requested via dmraid=off):"
1708 # Activate all software RAID sets discovered:
1709 einfo "Activating present dmraid sets (as requested via dmraid):"
1716 # by default (no special bootoptions) discover all software RAID devices:
1717 einfo "Searching for any present dmraid sets:"
1722 # {{{ LVM (Logical Volumes)
1724 [ -n "$INSTALLED" ] && return 0
1726 if checkbootparam 'nolvm' ; then
1727 ewarn "Skipping LVM code as requested on boot commandline." ; eend 0
1729 # Debian etch provides /etc/init.d/lvm only, newer suites provide /etc/init.d/lvm2
1730 if ! [ -x /sbin/lvm -a -x /sbin/lvdisplay ] || ! [ -x /etc/init.d/lvm2 -o -x /etc/init.d/lvm ] ; then
1731 eerror "LVM not available, can not execute it." ; eend 1
1733 if lvdisplay 2>&1 | grep -v 'No volume groups found' >/dev/null 2>&1 ; then
1734 einfo "You seem to have logical volumes (LVM) on your system."
1736 einfo "Just run 'Start lvm2' to activate them or boot using 'lvm' as bootoption for autostart."
1738 if checkbootparam 'lvm' ; then
1739 einfo "Bootoption LVM found. Searching for logical volumes:"
1740 /etc/init.d/lvm2 start ; eend $?
1744 fi # check for lvm binary
1745 fi # check for bootoption nolvm
1749 # {{{ debnet: setup network based on an existing one found on a partition
1751 if checkbootparam 'debnet' ; then
1752 einfo "Bootoption 'debnet' found. Searching for Debian network configuration: "
1758 # {{{ disable console blanking
1760 if checkbootparam 'noblank' ; then
1761 einfo "Bootoption noblank found. Disabling monitor blanking."
1762 setterm -blank 0 ; eend $?
1767 # {{{ debootstrap: automatic installation
1768 config_debootstrap(){
1770 if checkbootparam "BOOT_IMAGE=debian2hd" || checkbootparam "debian2hd" ; then
1772 einfo "Bootoption debian2hd found. Setting up environment for automatic installation via grml-debootstrap." ; eend 0
1774 if ! [ -x /usr/sbin/grml-debootstrap ] ; then
1776 eerror "Bootoption debian2hd found, but grml-debootstrap is not available." ; eend 1
1781 if checkbootparam 'target' ; then
1783 TARGET="$(getbootparam 'target' 2>>$DEBUG)"
1784 # notice: the following checks whether the given partition is available, if not the skip
1785 # execution of grml-debootstrap as it might result in data loss...
1786 if ! [ -r "$TARGET" ] ; then
1787 eerror "Target $TARGET does not exist. Skipping execution of grml-debootstrap therefore." ; eend 1
1791 eerror "No bootoption named target found, can not continue execution of grml-debootstrap." ; eend 1
1796 if checkbootparam 'grub' ; then
1798 GRUB="$(getbootparam 'grub' 2>>$DEBUG)"
1801 if checkbootparam 'groot' ; then
1803 GROOT="$(getbootparam 'groot' 2>>$DEBUG)"
1806 if checkbootparam 'release' ; then
1808 RELEASE="$(getbootparam 'release' 2>>$DEBUG)"
1811 if checkbootparam 'mirror' ; then
1813 MIRROR="$(getbootparam 'mirror' 2>>$DEBUG)"
1816 if checkbootparam 'boot_append' ; then
1818 BOOT_APPEND="$(getbootparam 'boot_append' 2>>$DEBUG)"
1821 if checkbootparam 'password' ; then
1823 PASSWORD="$(getbootparam 'password' 2>>$DEBUG)"
1826 # now check which options are available
1827 if [ -n "TARGET" ] ; then
1828 TARGETCMD="--target $TARGET"
1832 eerror "Target not set via bootoption. Skipping execution of grml-debootstrap therefore."; eend 1
1836 [ -n "$GRUB" ] && GRUBCMD="--grub $GRUB" || GRUBCMD=''
1837 [ -n "$GROOT" ] && GROOTCMD="--groot $GROOT" || GROOTCMD=''
1838 [ -n "$RELEASE" ] && RELEASECMD="--release $RELEASE" || RELEASECMD=''
1839 [ -n "$MIRROR" ] && MIRRORCMD="--mirror $MIRROR" || MIRRORCMD=''
1840 [ -n "$PASSWORD" ] && PASSWORDCMD="--password $PASSWORD" || PASSWORDCMD=''
1841 [ -n "$BOOT_APPEND" ] && BOOT_APPEND="--boot_append $BOOT_APPEND" || BOOT_APPEND=''
1843 # and finally write script and execute it
1844 cat>|/usr/bin/grml-debootstrap_noninteractive<<EOF
1846 AUTOINSTALL='yes' grml-debootstrap $TARGETCMD $GRUBCMD $GROOTCMD $RELEASECMD $MIRRORCMD $PASSWORDCMD $BOOT_APPEND
1849 chmod 750 /usr/bin/grml-debootstrap_noninteractive
1851 screen /usr/bin/grml-debootstrap_noninteractive
1852 einfo "Invoking a shell, just exit to continue booting..."
1855 fi # checkbootparam "BOOT_IMAGE=debian2hd
1859 # {{{ virtualbox shared folders
1860 config_virtualbox_shared_folders() {
1861 if $VIRTUALBOX ; then
1862 einfo "VirtualBox detected, trying to set up Shared Folders."
1863 if ! modinfo vboxsf &>/dev/null ; then
1864 ewarn "vboxsf driver not present, not setting up VirtualBox Shared Folders."
1866 elif ! [ -x /usr/sbin/VBoxService ] ; then
1867 ewarn "virtualbox-guest-utils not installed, not setting up VirtualBox Shared Folders."
1872 einfo "Loading vboxsf driver."
1873 lsmod | grep -q vboxsf || modprobe vboxsf
1876 einfo "Adjusting /dev/vboxguest."
1877 chown root:vboxsf /dev/vboxguest
1878 chmod 660 /dev/vboxguest
1883 einfo "Adding $fstabuser to group vboxsf."
1884 adduser grml vboxsf &>/dev/null
1887 einfo "Starting VBoxService."
1888 VBoxService >/dev/null
1891 local vbautomation='automation'
1892 if checkbootparam 'vbautomation'; then
1893 vbautomation="$(getbootparam 'vbautomation' 2>>$DEBUG)"
1896 if ! VBoxControl sharedfolder list | egrep -q "^[0-9]+ - ${vbautomation}$" ; then
1897 ewarn "No automount shared folder '$vbautomation' available"
1900 einfo "Found automount shared folder '$vbautomation'"
1903 local distri="$(getbootparam 'distri' 2>>$DEBUG)"
1904 [ -n "$distri" ] || distri='grml'
1906 local vbox_auto_sf="/media/sf_${vbautomation}"
1908 sleep 1 # ugly but necessary
1912 while ! [ -d "${vbox_auto_sf}" ] && [[ "$counter" != 0 ]]; do
1913 einfo "Waiting another second to retry access to ${vbox_auto_sf}"
1915 counter=$(( counter-1 ))
1920 if ! [ -d "${vbox_auto_sf}" ] ; then
1921 eerror "Giving up trying to access folder ${vbox_auto_sf} which doesn't seem to exist"
1924 einfo "Found shared folders automation directory $vbox_auto_sf"
1928 if checkbootparam 'novbautomation' ; then
1929 einfo "Bootoption novbautomation found. Disabling automation script execution."
1932 if ! [ -x "${vbox_auto_sf}/${distri}" ] ; then
1933 ewarn "Couldn't find an automation script named ${vbox_auto_sf}/${distri}"
1936 einfo "Executing '${vbox_auto_sf}/${distri}' now:"
1937 "${vbox_auto_sf}/${distri}"
1951 # {{{ Support customization
1953 if checkbootparam 'distri'; then
1954 DISTRI="$(getbootparam 'distri' 2>>$DEBUG)"
1955 if [ -r "${LIVECD_PATH}"/desktop/"$DISTRI".jpg ] ; then
1956 [ -n "$BOOTDEBUG" ] && einfo "Debug: bootoption distri found and file ${LIVECD_PATH}/desktop/${DISTRI} present" && eend 0
1957 # make sure the desktop.jpg file is not a symlink, so copying does not file then
1958 [ -L /usr/share/grml/desktop.jpg ] && rm /usr/share/grml/desktop.jpg
1959 cp "${LIVECD_PATH}"/desktop/"$DISTRI".jpg /usr/share/grml/desktop.jpg
1965 ## END OF FILE #################################################################
1966 # vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=2