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 [ "$(cat /proc/1/comm 2>/dev/null)" = "systemd" ] ; then
33 if [ "$#" -lt 2 ] ; then
34 echo "Usage: service_wrapper <service> <action>" >&2
42 systemctl "$action" "$service"
44 /etc/init.d/"$service" "$action"
50 if [ -n "$ZSH_VERSION" ] ; then
56 # avoid 'no matches found: ...'
57 iszsh && setopt no_nomatch # || echo "Warning: not running under zsh!"
60 # {{{ Read in boot parameters
61 if [ -z "$CMDLINE" ]; then
62 # if CMDLINE was set from the outside, we're debugging.
63 # otherwise, take CMDLINE from Kernel and config files.
64 CMDLINE="$(cat /proc/cmdline)"
65 [ -d ${LIVECD_PATH}/bootparams/ ] && CMDLINE="$CMDLINE $(cat ${LIVECD_PATH}/bootparams/* | tr '\n' ' ')"
66 modprobe 9p 2>/dev/null || true
67 if grep -q 9p /proc/filesystems ; then
69 if grep -q "$TAG" /sys/bus/virtio/devices/*/mount_tag 2>/dev/null ; then
70 MOUNTDIR="$(mktemp -d)"
71 mount -t 9p -o trans=virtio,ro "$TAG" "$MOUNTDIR"
72 CMDLINE="$CMDLINE $(cat "$MOUNTDIR"/* 2>/dev/null | tr '\n' ' ')"
80 ### {{{ Utility Functions
82 # Get a bootoption's parameter: read boot command line and either
83 # echo last parameter's argument or return false.
91 result="${line##*[$ws]$1=}"
92 result="${result%%[$ws]*}"
100 # Check boot commandline for specified option
102 [ -n "$1" ] || ( echo "Error: missing argument to checkbootparam()" ; return 1 )
108 *[${ws}]"$1"=*|*[${ws}]"$1"[${ws}]*)
115 # Check if currently using a framebuffer
117 [ -e /dev/fb0 ] && return 0 || return 1
120 # Check wheter a configuration variable (like $CONFIG_TOHD) is
124 [yY][eE][sS]) return 0 ;; # it's set to 'yes'
125 [tT][rR][uU][eE]) return 0 ;; # it's set to 'true'
126 *) return 1 ;; # default
130 # Are we using grml-small?
132 grep -q small /etc/grml_version 2>>$DEBUG && return 0 || return 1
135 # if no password is set return a random password
137 [ -n "$PASSWD" ] && return 0
139 if [ -x /usr/bin/apg ] ; then
140 PASSWD="$(apg -M NL -a 0 -m 8 -x 12 -n 1)"
141 elif [ -x /usr/bin/gpw ] ; then
143 elif [ -x /usr/bin/pwgen ] ; then
144 PASSWD="$(pwgen -1 8)"
145 elif [ -x /usr/bin/hexdump ] ; then
146 PASSWD="$(dd if=/dev/urandom bs=14 count=1 2>/dev/null | hexdump | awk '{print $3 $4}')"
147 elif [ -n "$RANDOM" ] ; then
148 PASSWD="grml${RANDOM}"
151 eerror "Empty passphrase and neither apg, gpw, pwgen, hexdump nor \$RANDOM available. Skipping."
159 # {{{ filesystems (proc, pts, sys) and fixes
161 [ -f /proc/version ] || mount -t proc /proc /proc 2>/dev/null
165 grep -q "/dev/pts" /proc/mounts || mount -t devpts /dev/pts /dev/pts 2>/dev/null
169 [ -d /sys/devices ] || mount -t sysfs /sys /sys 2>/dev/null
173 # {{{ Check if we are running in live mode or from HD
175 [ -e /etc/grml_cd ] || INSTALLED="yes"
178 # {{{ provide information about virtual environments
179 VIRTUAL=false # assume physical system by default
184 if vmware-detect &>/dev/null; then
185 VIRTUAL=true; VMWARE=true; VIRTUAL_ENV='VMware'
186 elif [ "$(virt-what 2>/dev/null)" = "kvm" ] || \
187 [ "$(imvirt 2>/dev/null)" = "KVM" ] ; then
188 VIRTUAL=true; KVM=true; VIRTUAL_ENV='KVM'
189 elif [ "$(virt-what 2>/dev/null)" = "virtualbox" ] || \
190 [ "$(imvirt 2>/dev/null)" = "VirtualBox" ] ; then
191 VIRTUAL=true; VIRTUALBOX=true; VIRTUAL_ENV='VirtualBox'
195 # {{{ source lsb-functions , color handling
196 if checkbootparam 'nocolor'; then
197 . /etc/grml/lsb-functions
198 einfo "Disabling colors in bootsequence as requested on commandline." ; eend 0
200 . /etc/grml/lsb-functions
206 if checkbootparam 'log' || checkbootparam 'debug' ; then
207 export DEBUG="/tmp/grml.log.`date +%Y%m%d`"
209 einfo "Bootparameter log found. Log files: ${DEBUG} and /var/log/boot"
211 einfo "Starting bootlogd." # known to be *very* unreliable :(
212 bootlogd -r -c >>$DEBUG 2>&1 ; eend $?
220 ### {{{ language configuration / localization
223 einfo "Activating language settings:"
226 # people can specify $LANGUAGE and $CONSOLEFONT in a config file
227 [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig
229 # check for bootoption which overrides config from /etc/grml/autoconfig
230 BOOT_LANGUAGE="$(getbootparam 'lang' 2>>$DEBUG)"
231 [ -n "$BOOT_LANGUAGE" ] && LANGUAGE="$BOOT_LANGUAGE"
233 # set default to 'en' in live-cd mode iff $LANGUAGE is not set yet
234 if [ -z "$INSTALLED" ] ; then
235 [ -n "$LANGUAGE" ] || LANGUAGE='en'
238 if [ -x /usr/sbin/grml-setlang ] ; then
239 # if bootoption lang is used update /etc/default/locale accordingly
240 if [ -n "$BOOT_LANGUAGE" ] ; then
241 /usr/sbin/grml-setlang "$LANGUAGE"
242 # otherwise default to lang=en
244 /usr/sbin/grml-setlang "en"
249 if [ -z "$CONSOLEFONT" ] ; then
250 if ! checkbootparam 'nodefaultfont' >>$DEBUG 2>&1 ; then
251 if [ -r /usr/share/consolefonts/Uni3-Terminus16.psf.gz ] ; then
252 CONSOLEFONT='Uni3-Terminus16'
254 ewarn "/usr/share/consolefonts/Uni3-Terminus16.psf.gz not available. Please upgrade package console-terminus." ; eend 1
257 CONSOLEFONT='Lat15-Terminus16'
262 # export it now, so error messages get translated, too
263 [ -r /etc/default/locale ] && . /etc/default/locale
266 # configure keyboard layout, read in already set values first:
267 [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
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 # modify /etc/sysconfig/keyboard only in live-cd mode:
277 if [ -z "$INSTALLED" ] ; then
279 local LANGUAGE="$BOOT_LANGUAGE"
280 . /etc/grml/language-functions
281 # allow setting xkeyboard explicitly different than console keyboard
282 KXKEYBOARD="$(getbootparam 'xkeyboard' 2>>$DEBUG)"
283 if [ -n "$KXKEYBOARD" ]; then
284 XKEYBOARD="$KXKEYBOARD"
285 KDEKEYBOARD="$KXKEYBOARD"
286 elif [ -n "$KKEYBOARD" ]; then
287 XKEYBOARD="$KKEYBOARD"
288 KDEKEYBOARD="$KKEYBOARD"
291 # duplicate of previous code to make sure /etc/grml/language-functions
292 # does not overwrite our values....
293 # now allow keyboard override by boot commandline for later use:
294 KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
295 [ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD"
296 # notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead:
297 [[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys
298 [[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys
300 # write keyboard related variables to file for later use
301 [ -d /etc/sysconfig ] || mkdir /etc/sysconfig
302 if ! [ -e /etc/sysconfig/keyboard ] ; then
303 echo "KEYTABLE=\"$KEYTABLE\"" > /etc/sysconfig/keyboard
304 echo "XKEYBOARD=\"$XKEYBOARD\"" >> /etc/sysconfig/keyboard
305 echo "KDEKEYBOARD=\"$KDEKEYBOARD\"" >> /etc/sysconfig/keyboard
306 echo "KDEKEYBOARDS=\"$KDEKEYBOARDS\"" >> /etc/sysconfig/keyboard
310 [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
312 # activate unicode console if running within utf8 environment
313 if [ -r /etc/default/locale ] ; then
314 if grep -q "LANG=.*UTF" /etc/default/locale ; then
315 einfo "Setting up unicode environment."
316 unicode_start >>$DEBUG 2>&1 ; eend $?
320 # Set default keyboard before interactive setup
321 if [ -n "$KEYTABLE" ] ; then
322 einfo "Running loadkeys for ${WHITE}${KEYTABLE}${NORMAL} in background"
323 loadkeys -q $KEYTABLE &
327 # we have to set up all consoles, therefore loop it over all ttys:
328 NUM_CONSOLES=$(fgconsole --next-available 2>/dev/null)
329 if [ -n "$NUM_CONSOLES" ] ; then
330 NUM_CONSOLES=$(expr ${NUM_CONSOLES} - 1)
331 [ ${NUM_CONSOLES} -eq 1 ] && NUM_CONSOLES=6
333 CUR_CONSOLE=$(fgconsole 2>/dev/null)
335 if [ -x "$(which setfont)" ] ; then
337 elif [ -x "$(which consolechars)" ] ; then
338 use_consolechars=true
340 eerror "Neither setfont nor consolechars tool present, can not set font."
345 if [ -n "$CHARMAP" ] ; then
346 einfo "Setting font to ${CHARMAP}"
348 for vc in $(seq 0 ${NUM_CONSOLES}) ; do
349 if $use_setfont ; then
350 setfont -C /dev/tty${vc} $CHARMAP ; RC=$?
351 elif $use_consolechars ; then
352 consolechars --tty=/dev/tty${vc} -m ${CHARMAP} ; RC=$?
355 if [ -n "$CUR_CONSOLE" ] ; then
356 [ "$CUR_CONSOLE" != "serial" ] && chvt $CUR_CONSOLE
361 if checkbootparam 'noconsolefont' ; then
362 ewarn "Skipping setting console font as requested on boot commandline." ; eend 0
364 if [ -n "$CONSOLEFONT" ] ; then
365 einfo "Setting font to ${CONSOLEFONT}"
367 for vc in $(seq 0 ${NUM_CONSOLES}) ; do
368 if $use_setfont ; then
369 setfont -C /dev/tty${vc} ${CONSOLEFONT} ; RC=$?
370 elif $use_consolechars ; then
371 consolechars --tty=/dev/tty${vc} -f ${CONSOLEFONT} ; RC=$?
374 if [ -n "$CUR_CONSOLE" ] ; then
375 [ "$CUR_CONSOLE" != "serial" ] && chvt $CUR_CONSOLE
387 if ! checkbootparam 'hostname' ; then
391 HOSTNAME="$(getbootparam 'hostname' 2>>$DEBUG)"
392 if [ -z "$HOSTNAME" ] && [ -x /usr/bin/random-hostname ] ; then
393 einfo "Generating random hostname as no hostname was specified."
394 HOSTNAME="$(/usr/bin/random-hostname)"
398 einfo "Setting hostname to $HOSTNAME as requested."
399 grml-hostname $HOSTNAME >>$DEBUG
404 # fstabuser (needed when running from harddisk with username != grml {{{
406 # force load of build-in and local config
407 [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig
408 [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig.local
410 # 1st. try configured fstab user
411 if [ -n "$CONFIG_FSTAB_USER" ] ; then
412 fstabuser=$(getent passwd $CONFIG_FSTAB_USER | cut -d: -f1)
415 # 2nd. use standard user id
416 [ -n "$fstabuser" ] || fstabuser=$(getent passwd 1000 | cut -d: -f1)
418 # 3rd. use standard user name
419 [ -n "$fstabuser" ] || fstabuser=$(getent passwd grml | cut -d: -f1)
421 # if not yet set fall back to 'root' user, avoid bad /etc/fstab
422 [ -n "$fstabuser" ] || fstabuser='root'
426 # local_user (needed when running with username != grml {{{
429 # force load of build-in and local config
430 [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig
431 [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig.local
433 # 1st. try id of primary user
434 localuser=$(getent passwd 1000 | cut -d: -f1)
436 # 2nd. use name standard user
437 [ -n "$localuser" ] || localuser=$(getent passwd grml | cut -d: -f1)
441 # {{{ Set clock (Local time is more often used than GMT, so it is default)
443 # don't touch the files if running from harddisk:
444 if [ -z "$INSTALLED" ]; then
445 # The default hardware clock timezone is stated as representing local time.
448 if [ -f /etc/default/rcS ] ; then
449 grep -q "^UTC=" /etc/default/rcS || echo "UTC=no" >> /etc/default/rcS
450 checkbootparam 'utc' >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=yes|" /etc/default/rcS
451 checkbootparam 'gmt' >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=yes|" /etc/default/rcS
452 checkbootparam 'localtime' >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=no|" /etc/default/rcS
453 grep -q -i "^UTC=yes" /etc/default/rcS && UTC="-u"
454 # recent initscripts package versions don't ship /etc/default/rcS anymore, instead rely on /etc/adjtime
455 elif [ -f /etc/adjtime ] ; then
456 checkbootparam 'utc' >>$DEBUG 2>&1 && sed -i "s/^LOCAL/UTC/" /etc/adjtime
457 checkbootparam 'gmt' >>$DEBUG 2>&1 && sed -i "s/^LOCAL/UTC/" /etc/adjtime
458 checkbootparam 'localtime' >>$DEBUG 2>&1 && sed -i "s/^UTC$/LOCAL/" /etc/adjtime
459 grep -q "^UTC$" /etc/adjtime && UTC="-u"
462 # hwclock uses the TZ variable
463 KTZ="$(getbootparam 'tz' 2>>$DEBUG)"
464 [ -z "$KTZ" ] && [ -r /etc/timezone ] && KTZ=$(cat /etc/timezone)
465 if [ ! -f "/usr/share/zoneinfo/$KTZ" ] ; then
466 ewarn "Warning: unknown timezone $KTZ" ; eend 1
468 ewarn "Falling back to timezone $KTZ" ; eend 0
471 if ! [ -r /dev/rtc ] ; then
472 ewarn "Warning: realtime clock not available, trying to execute hwclock anyway." ; eend 0
475 ERROR=$(TZ="$KTZ" hwclock $UTC -s 2>&1 | head -1) ; RC=$?
476 if [ -n "$ERROR" ] ; then
478 ERROR=$(TZ="$KTZ" hwclock $UTC -s --directisa 2>&1 | head -1)
479 if [ -n "$ERROR" ] ; then
480 eerror "Problem running hwclock: $ERROR" ; eend 1
489 # {{{ print kernel info
491 if $VIRTUAL && [ -n "$VIRTUAL_ENV" ] ; then
492 einfo "Running Linux Kernel $KERNEL inside $VIRTUAL_ENV" ; eend 0
494 einfo "Running Linux Kernel $KERNEL" ; eend 0
497 if [ -r /proc/cpuinfo ] ; then
498 if egrep -q '^flags.*(vmx|svm)' /proc/cpuinfo ; then
500 einfo 'CPU(s) featuring virtualization technology detected' ; eend 0
505 if [ -d /proc/xen ] ; then
507 einfo 'Running kernel featuring support for Xen detected' ; eend 0
515 # systemd does this for us, but if we are not running under systemd then mokutil
516 # doesn't work as needed as it relies on /sys/firmware/efi/efivars (while
517 # /sys/firmware/efi/vars would exist)
520 mount -t efivarfs efivarfs /sys/firmware/efi/efivars
523 if [ -x /usr/bin/mokutil ] ; then
524 local secstate=$(mokutil --sb-state 2>/dev/null) # "SecureBoot enabled"
525 if [ -n "$secstate" ] ; then
526 einfo "SecureBoot is enabled" ; eend 0
528 einfo "SecureBoot not detected" ; eend 0
531 if modprobe efivars &>/dev/null ; then
532 if od -An -t u1 /sys/firmware/efi/vars/SecureBoot-*/data 2>/dev/null | grep -q 1 ; then
533 einfo "SecureBoot is enabled" ; eend 0
535 einfo "SecureBoot not detected" ; eend 0
544 # don't touch the files if running from harddisk:
545 if [ -z "$INSTALLED" ]; then
546 KTZ="$(getbootparam 'tz' 2>>$DEBUG)"
547 if [ -n "$KTZ" ] ; then
548 if [ ! -f "/usr/share/zoneinfo/$KTZ" ]
550 ewarn "Warning: unknown timezone $KTZ"; eend 0
552 einfo "Setting timezone."
554 area=$(echo $KTZ | cut -d '/' -f1)
555 zone=$(echo $KTZ | cut -d '/' -f2)
556 echo "tzdata tzdata/Areas select $area" | debconf-set-selections
557 echo "tzdata tzdata/Zones/$area select $zone" | debconf-set-selections
559 echo $KTZ > /etc/timezone
561 cp "/usr/share/zoneinfo/$KTZ" /etc/localtime ; eend $?
568 # activate serial console {{{
570 if checkbootparam 'console'; then
571 # this hack is no longer necessary with systemd
580 einfo "Bootoption for serial console detected:"
584 line="${line#*[$ws]}"
586 while [ -n "$line" ]; do
590 local device="${this%%,*}"
591 local device="${device##*=}"
592 if echo $serial | grep -q ttyS ; then
593 local option="${serial##*,}"
594 # default (works for kvm & CO):
595 local speed="115200,57600,38400,19200,9600,4800,2400,1200";
596 # ... unless overriden by command line:
598 115200*) speed=115200 ;;
599 57600*) speed=57600 ;;
600 38400*) speed=38400 ;;
601 19200*) speed=19200 ;;
608 einfo "Activating console login on device ${device} with speed ${speed}."
609 local number="${device#ttyS}"
610 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
617 this="${line%%[$ws]*}"
618 line="${line#*[$ws]}"
621 if [ -n "$telinitq" ]; then
631 if checkbootparam 'testcd' ; then
632 einfo "Checking CD data integrity as requested by '${WHITE}testcd${NORMAL}' boot option."
636 local FOUND_FILE=false
637 local logfile='/tmp/md5sum.log'
641 for md5 in $(find "${LIVECD_PATH}" -name md5sums) ; do
642 einfo "Checking files against $md5, this may take a while..."
647 md5sum -c $(basename "$md5") |& tee -a "${logfile}"
648 if [ $pipestatus[1] -eq 0 ] ; then
654 if ! $FOUND_FILE ; then
655 eerror 'Error: Could not find md5sum file' ; eend 1
660 einfo "Everything looks OK" ; eend 0
662 eerror 'Checksum failed for theses files:' ; eend 1
663 egrep -v '(^md5sum:|OK$)' "${logfile}"
664 eerror 'Data on the medium is possibly incomplete/damaged or RAM of your system is broken.' ; eend 1
665 einfon "Hit return to continue, or press the power button to shut down system."
674 # {{{ blacklist specific module [ used in /etc/init.d/udev ]
676 if checkbootparam 'blacklist' ; then
677 if [ -z "$INSTALLED" ]; then
678 einfo "Bootoption blacklist found."
679 BLACK="$(getbootparam 'blacklist' 2>>$DEBUG)"
680 BLACKLIST_FILE='/etc/modprobe.d/grml.conf'
681 if [ -n "$BLACK" ] ; then
682 for module in $(echo ${BLACK//,/ }) ; do
683 einfo "Blacklisting module ${module} via ${BLACKLIST_FILE}."
684 echo "# begin entry generated by config_blacklist of grml-autoconfig" >> "$BLACKLIST_FILE"
685 echo "blacklist $module" >> "$BLACKLIST_FILE"
686 echo "alias $module off" >> "$BLACKLIST_FILE"
687 echo "# end entry generated by config_blacklist of grml-autoconfig" >> "$BLACKLIST_FILE" ; eend $?
690 eerror "No given module for blacklist found. Blacklisting will not work therefore."
693 ewarn "Backlisting via bootoption is not intended for use on harddisk installations." ; eend 1
695 einfo "Please blacklist the module(s) manually using the 'blacklist' script."
705 echo "systemd detected, no acpi(d) stuff needed." >>"$DEBUG"
709 if checkbootparam 'noacpi'; then
710 ewarn "ACPI: Not loading modules as requested by boot option \"noacpi\"." ; eend 0
711 elif checkbootparam 'nogrmlacpi' ; then
712 ewarn "ACPI: Not loading modules as requested by boot option \"nogrmlacpi\"." ; eend 0
713 elif [ ! -d /proc/acpi ] ; then
714 ewarn "ACPI: Kernel support not present." ; eend 0
716 einfo "ACPI: Loading modules (disable with boot option noacpi / nogrmlacpi): "
719 for a in /lib/modules/$KERNEL/kernel/drivers/acpi/*; do
721 basename="${basename%%.*}"
722 case "$basename" in *_acpi)
723 egrep -qi "${basename%%_acpi}" /proc/acpi/dsdt 2>>$DEBUG || continue ;;
725 modprobe $basename >>$DEBUG 2>&1 && found="yes"
726 local BASE="$BASE $basename"
728 if [ -n "$found" ] ; then
729 einfo "$BASE" ; eend 0
731 ewarn "(none)" ; eend 1
733 if ! pgrep acpid >/dev/null ; then
734 einfo "Starting acpi daemon."
735 service_wrapper acpid.socket start >>$DEBUG 2>&1 ; eend $?
736 service_wrapper acpid start >>$DEBUG 2>&1 ; eend $?
738 ewarn "acpi daemon already running."
748 if checkbootparam 'brltty' ; then
749 [ -x /lib/brltty/brltty.sh ] && /lib/brltty/brltty.sh
754 # {{{ Start creating /etc/fstab with HD partitions and USB SCSI devices now
757 NOSWAP="yes" # we do not use swap by default!
758 if checkbootparam 'swap' || checkbootparam 'anyswap' ; then
760 checkbootparam 'anyswap' && export ANYSWAP='yes' || export ANYSWAP=""
763 # Scan for swap, config, homedir - but only in live-mode
764 if [ -z "$INSTALLED" ] ; then
765 [ -z "$NOSWAP" ] && einfo "Searching for swap partition(s) as requested."
768 HOMEDIR="$(getbootparam 'home')"
769 if [ -n "$partitions" ]; then
770 while read p m f relax; do
771 case "$p" in *fd0*|*proc*|*sys*|*\#*) continue;; esac
772 partoptions="users,exec"
774 # it's a swap partition?
777 if [ -n "$NOSWAP" ]; then
778 ewarn "Ignoring swap partition ${WHITE}$p${NORMAL}. (Force usage via boot option 'swap', or execute grml-swapon)"
781 case "$(dd if=$p bs=1 count=6 skip=4086 2>/dev/null)" in
782 S1SUSP|S2SUSP|pmdisk|[zZ]*)
783 if [ -n "$ANYSWAP" ] ; then
784 einfo "Using swap partition ${WHITE}${p}${NORMAL} [bootoption anyswap found]."
785 swapon $p 2>>$DEBUG ; eend $?
787 ewarn "Suspend signature on ${WHITE}${p}${NORMAL} found, not using as swap. (Force usage via boot option: anyswap)"
791 if [[ "$p" == LABEL* ]] ; then
792 p=$(blkid -t $p | awk -F: '{print $1}')
794 if grep -q $p /proc/swaps ; then
795 ewarn "Not using swap partition ${WHITE}${p}${NORMAL} as it is already in use." ; eend 0
797 if [ -b "$p" ] ; then
798 einfo "Using swap partition ${WHITE}${p}${NORMAL}."
799 swapon $p 2>>$DEBUG ; eend $?
801 ewarn "$p is not a valid block device - not using it therefore." ; eend 0
810 esac # it's a swap partition?
815 vfat|msdos|ntfs) MOUNTOPTS="$MOUNTOPTS,uid=${fstabuser},gid=${fstabuser}" ;;
816 ext2|ext3|reiserfs|jfs|reiser4|xfs) MOUNTOPTS="$MOUNTOPTS,noatime" ;;
818 # *) NONEFOUND='1'; continue ;;
822 if [ -z "$NOSWAP" ] ; then
823 mount -o "$MOUNTOPTS" -t $f $p $m 2>>$DEBUG && MOUNTED=1 || continue
824 # Activate swapfile, if exists
825 SWAPFILE="$(/bin/ls -1d $m/[Gg][Rr][Mm][Ll].[Ss][Ww][Pp] 2>/dev/null)"
827 if [ -z "$NOSWAP" -a -n "$SWAPFILE" -a -f "$SWAPFILE" ]; then
828 mount -o remount,rw $m && MOUNTED=1
829 if swapon "$SWAPFILE" 2>>$DEBUG ; then
831 einfo "Using GRML swapfile ${WHITE}${SWAPFILE}${NORMAL}."
833 fnew="$SWAPFILE swap swap defaults 0 0"
834 grep -q "$fnew" "/etc/fstab" || echo "$fnew" >> /etc/fstab
835 GRML_SWP="$GRML_SWP $SWAPFILE"
838 mount -o remount,ro $m 2>>$DEBUG && MOUNTED=1
841 # use a image as home
842 IMAGE="$(/bin/ls -1d $m/[Gg][Rr][Mm][Ll].[Ii][Mm][Gg] 2>/dev/null)"
843 if [ -z "$GRML_IMG" -a -n "$IMAGE" -a -f "$IMAGE" ]; then
844 if [ -n "$HOMEDIR" ]; then
845 if [ "$HOMEDIR" != "scan" -a "$HOMEDIR" != "$IMAGE" -a "$HOMEDIR" != "${IMAGE%/*.*}" ]; then
849 if type -a grml-image >/dev/null 2>&1 && grml-image "$IMAGE" </dev/console >/dev/console 2>&1; then
851 mount -o remount,ro $m 2>>$DEBUG && MOUNTED=1
856 # Umount, if not in use
857 [ -n "$MOUNTED" ] && umount -r $m 2>/dev/null
869 if checkbootparam 'nocpu'; then
870 ewarn "Skipping CPU detection as requested on boot commandline." ; eend 0
874 if [[ $(grep -c processor /proc/cpuinfo) -gt 1 ]] ; then
876 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)
877 echo $CPU | sed 's/ \{1,\}/ /g'
880 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
883 # no cpufreq setup inside VirtualBox
884 if $VIRTUALBOX ; then
885 einfo 'Virtual Box detected, skipping cpufreq setup.' ; eend 0
889 if ! [ -x /etc/init.d/loadcpufreq ] ; then
890 ewarn "loadcpufreq init script not available, ignoring cpu frequency scaling."
894 einfo "Trying to set up cpu frequency scaling:"
897 LOADCPUFREQ=$(mktemp)
898 /etc/init.d/loadcpufreq start >"$LOADCPUFREQ" 2>&1 ; RC=$?
899 if grep -q FATAL "$LOADCPUFREQ" ; then
904 for line in $(grep FATAL "$LOADCPUFREQ" | sed 's/.*FATAL: //; s/ (.*)//') ; do
905 eerror "$line" ; eend $RC
909 elif grep -q done "$LOADCPUFREQ" ; then
910 MODULE=$(grep done "$LOADCPUFREQ" | sed 's/.*done (\(.*\))./\1/')
911 if [ -n "$MODULE" -a "$MODULE" != none ]; then
912 einfo "Loading cpufreq kernel module $MODULE" ; eend 0
915 ewarn "Could not find an appropriate kernel module for cpu frequency scaling." ; eend 1
921 if [ -z "$SKIP_CPU_GOVERNOR" ] ; then
922 if [ -r /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors ] ; then
923 if ! grep -q ondemand /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors ; then
924 einfo "Ondemand governor not available for CPU(s), not modifying governor configuration"
926 einfo "Setting ondemand governor"
928 for file in $(find /sys/devices/system/cpu/ -name scaling_governor 2>/dev/null) ; do
929 echo ondemand > $file || RC=1
941 # {{{ autostart of ssh
943 if checkbootparam 'ssh' ; then
945 PASSWD="$(getbootparam 'ssh' 2>>$DEBUG)"
948 einfo "Bootoption ssh found, trying to set password for root and user $localuser"
949 [ -z "$localuser" ] && eend 1
952 if [ -z "$PASSWD" ] ; then
953 set_passwd && ewarn "No given password for found. Using random password: $PASSWD" && eend 0
957 if [ -n "$PASSWD" ] ; then
959 if chpasswd --help 2>&1 | grep -q -- '-m,' ; then
963 echo "$localuser:$PASSWD" | chpasswd $chpass_options
964 echo "root:$PASSWD" | chpasswd $chpass_options
967 ewarn "Warning: please change the password for root and user $localuser as soon as possible!"
971 einfo "Starting secure shell server in background for root and user $localuser"
972 service_wrapper rmnologin start >>$DEBUG 2>>$DEBUG
973 service_wrapper ssh start >>$DEBUG 2>>$DEBUG &
981 # {{{ display hostkeys of SSH server
982 config_display_ssh_fingerprints() {
983 if ! ls /etc/ssh/ssh_host_\*_key >/dev/null 2>&1 ; then
984 return 0 # no SSH host keys present
987 einfo "SSH key fingerprints:"
988 for file in /etc/ssh/ssh_host_*_key ; do
990 ssh-keygen -l -f $file
996 # {{{ autostart of x11vnc
998 if checkbootparam 'vnc' ; then
1001 VNC_PASSWD="$(getbootparam 'vnc' 2>>$DEBUG)"
1002 einfo "Bootoption vnc found, trying to set password for user $localuser."
1004 if [ -z "$VNC_PASSWD" ] ; then
1005 if [ -x /usr/bin/apg ] ; then
1006 VNC_PASSWD="$(apg -M NL -a 0 -m 8 -x 12 -n 1)"
1007 elif [ -x /usr/bin/gpw ] ; then
1008 VNC_PASSWD="$(gpw 1)"
1009 elif [ -x /usr/bin/pwgen ] ; then
1010 VNC_PASSWD="$(pwgen -1 8)"
1011 elif [ -x /usr/bin/hexdump ] ; then
1012 VNC_PASSWD="$(dd if=/dev/urandom bs=14 count=1 2>/dev/null | hexdump | awk '{print $3 $4}')"
1013 elif [ -n "$RANDOM" ] ; then
1014 VNC_PASSWD="${localuser}${RANDOM}"
1017 eerror "Empty passphrase and neither pwgen nor hexdump nor \$RANDOM found. Skipping."
1021 if [ -n "$VNC_PASSWD" ] ; then
1022 ewarn "No given password for vnc found. Using random password: $VNC_PASSWD" ; eend 0
1027 # finally check if we have a password we can use:
1028 if [ -n "$VNC_PASSWD" ] ; then
1030 VNCDIR="/home/${localuser}/.vnc"
1031 [ -d "$VNCDIR" ] || mkdir "$VNCDIR"
1033 if [ ! -x /usr/bin/x11vnc ] ; then
1034 eerror "Error: x11vnc not found - can not set up vnc. Please make sure to install the x11vnc package."
1037 /usr/bin/x11vnc -storepasswd "$VNC_PASSWD" "$VNCDIR"/passwd ; eend $?
1038 /bin/chown -R "$localuser": "$VNCDIR"
1041 if checkbootparam 'vnc_connect' ; then
1043 VNC_CONNECT="$(getbootparam 'vnc_connect' 2>>$DEBUG)"
1044 einfo "Bootoption vnc_connect found, will start vnc with connect to $VNC_CONNECT."
1045 #store the options in a file
1046 VNCDIR="/home/${localuser}/.vnc"
1047 [ -d "$VNCDIR" ] || mkdir "$VNCDIR"
1048 echo " --connect $VNC_CONNECT " >> $VNCDIR/options
1054 # {{{ set password for root and default user
1056 if checkbootparam 'passwd' >>$DEBUG 2>&1; then
1058 PASSWD="$(getbootparam 'passwd' 2>>$DEBUG)"
1061 einfo "Bootoption passwd found, trying to set password for root and user $localuser"
1062 [ -z "$localuser" ] && eend 1
1065 if [ -z "$PASSWD" ] ; then
1066 set_passwd && ewarn "No given password for found. Using random password: $PASSWD" && eend 0
1070 if [ -n "$PASSWD" ] ; then
1072 if chpasswd --help 2>&1 | grep -q -- '-m,' ; then
1076 echo "$localuser:$PASSWD" | chpasswd $chpass_options
1077 echo "root:$PASSWD" | chpasswd $chpass_options
1080 ewarn "Warning: please change the password for root and user $localuser as soon as possible!"
1086 if checkbootparam 'encpasswd' >>$DEBUG 2>&1; then
1088 PASSWD="$(getbootparam 'encpasswd' 2>>$DEBUG)"
1090 if [ -z "$PASSWD" ] ; then
1091 eerror "No hashed password found, can not set password."
1097 einfo "Bootoption encpasswd found, trying to set hashed password for root and user $localuser"
1098 [ -z "$localuser" ] && eend 1
1100 if [ -n "$PASSWD" ] ; then
1103 echo "$localuser:$PASSWD" | chpasswd $chpass_options
1104 echo "root:$PASSWD" | chpasswd $chpass_options
1107 ewarn "Warning: please change the password for root and user $localuser as soon as possible!"
1117 if ! [ -x /usr/bin/amixer ] ; then
1118 logger -t grml-autoconfig "amixer binary not available"
1122 if ! [ -r /proc/asound/cards ] ; then
1123 ewarn "No soundcard present, skipping mixer settings therefore."
1128 for card in $(cat /proc/asound/cards| grep -e '^\s*[0-9]' | awk '{print $1}') ; do
1129 einfo "Configuring soundcard \"$(awk -F\[ '/^ *'$card' \[/{ FS=" "; $0=$2; print $1}' < /proc/asound/cards)\""
1132 if checkbootparam 'vol' ; then
1133 VOL="$(getbootparam 'vol' 2>>$DEBUG)"
1134 if [ -z "$VOL" ] ; then
1135 eerror "Bootoption vol found but no volume level/parameter given. Using defaults (75%)."
1143 if checkbootparam 'nosound' ; then
1144 einfo "Muting sound devices on request."
1145 ERROR=$(amixer -q set Master mute)
1147 if [ -n "$ERROR" ] ; then
1149 eerror "Problem muting sound devices: $ERROR"
1153 elif [ -z "$INSTALLED" ] ; then
1154 einfo "Setting mixer volumes to level ${WHITE}${VOL}${NORMAL}."
1156 if checkbootparam 'micvol' ; then
1157 MICVOL="$(getbootparam 'micvol' 2>>$DEBUG)"
1158 einfo "Setting microphone to ${WHITE}${MICVOL}${NORMAL}."
1163 CONTROLS=$(amixer -c $card scontrols | awk -F"Simple mixer control " '{print $2}')
1166 for CONTROL in ${=CONTROLS} ; do
1167 # such devices can not be controlled with amixer ... unmute
1168 [[ "$CONTROL" == *Console* ]] && continue
1170 if ! echo "${CONTROL}" | grep -q -i "mic" ; then
1171 if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*pswitch' ; then
1172 amixer -c $card -q set "${CONTROL}" unmute
1174 if amixer -c $card sget "${CONTROL}" | grep -q -P 'Capabilities:.*(pvolume| volume)' ; then
1175 amixer -c $card -q set "${CONTROL}" "${VOL}"%
1179 if [ ${MICVOL} -ne 0 ] ; then
1180 if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*cswitch' ; then
1181 amixer -c $card -q set "${CONTROL}" unmute
1183 if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*cvolume' ; then
1184 amixer -c $card -q set "${CONTROL}" $MICVOL%
1190 fi # checkbootparam 'nosound'
1196 # {{{ syslog service
1198 if checkbootparam 'nosyslog'; then
1199 ewarn "Not starting syslog daemon as requested on boot commandline." ; eend 0
1201 einfo "Starting rsyslog in background."
1202 service_wrapper rsyslog start >>$DEBUG &
1210 if checkbootparam 'nogpm'; then
1211 ewarn "Not starting GPM as requested on boot commandline." ; eend 0
1213 if ! [ -r /dev/input/mice ] ; then
1214 eerror "No mouse found - not starting GPM." ; eend 1
1216 einfo "Starting gpm in background."
1217 service_wrapper gpm start >>$DEBUG &
1218 # ( while [ ! -e /dev/psaux ]; do sleep 5; done; /etc/init.d/gpm start >>$DEBUG ) &
1227 if checkbootparam 'services' ; then
1228 SERVICE="$(getbootparam 'services' 2>>$DEBUG)"
1229 SERVICELIST=$(echo "$SERVICE" | sed 's/,/\\n/g')
1230 SERVICENL=$(echo "$SERVICE" | sed 's/,/ /g')
1231 for service in $(echo -e $SERVICELIST) ; do
1232 # support running (custom) init scripts in non-blocking mode
1233 # if they contain the keyword "DO_NO_RUN_IN_BACKGROUND".
1234 if grep -q 'DO_NO_RUN_IN_BACKGROUND' "/etc/init.d/${service}" 2>>$DEBUG ; then
1235 einfo "Starting service ${service}."
1236 service_wrapper "${service}" start >>$DEBUG
1238 einfo "Starting service ${service} in background."
1239 service_wrapper "${service}" start >>$DEBUG &
1249 [ "$#" -eq 2 ] || ( echo "Error: wrong parameter for get_remote_file()" ; return 1 )
1250 SOURCE=$(eval echo "$1")
1253 wget --timeout=10 --dns-timeout=10 --connect-timeout=10 --tries=1 \
1254 --read-timeout=10 ${SOURCE} -O ${TARGET} && return 0 || return 1
1256 einfo "Trying to get ${WHITE}${TARGET}${NORMAL}"
1258 if checkbootparam 'getfile.retries' ; then
1259 local counter="$(getbootparam 'getfile.retries' 2>>$DEBUG)"
1264 while ! getconfig && [[ "$counter" != 0 ]] ; do
1265 echo -n "Sleeping for 1 second and trying to get config again... "
1266 counter=$(( counter-1 ))
1267 echo "$counter tries left" ; sleep 1
1269 if [ -s "$TARGET" ] ; then
1270 einfo "Downloading was successfull." ; eend 0
1271 einfo "md5sum of ${WHITE}${TARGET}${NORMAL}: "
1272 md5sum ${TARGET} ; eend 0
1275 einfo "Sorry, could not fetch ${SOURCE}" ; eend 1
1283 if checkbootparam 'netconfig' ; then
1284 CONFIG="$(getbootparam 'netconfig' 2>>$DEBUG)"
1285 CONFIGFILE='/tmp/netconfig.grml'
1287 if get_remote_file ${CONFIG} ${CONFIGFILE} ; then
1288 cd / && einfo "Unpacking ${WHITE}${CONFIGFILE}${NORMAL}:" && /usr/bin/unp $CONFIGFILE $EXTRACTOPTIONS ; eend $?
1295 # {{{ remote scripts
1296 config_netscript() {
1297 if checkbootparam 'netscript' ; then
1298 CONFIG="$(getbootparam 'netscript' 2>>$DEBUG)"
1299 SCRIPTFILE='/tmp/netscript.grml'
1301 if get_remote_file ${CONFIG} ${SCRIPTFILE} ; then
1302 chmod +x ${SCRIPTFILE}
1303 einfo "Running ${WHITE}${SCRIPTFILE}${NORMAL}:" && NETSCRIPT=${CONFIG} ${SCRIPTFILE} ; eend $?
1310 # {{{ start X window system via grml-x
1314 # make sure we start X only if startx is used *before* a nostartx option
1315 # so it's possible to disable automatic X startup using nostart
1316 if checkbootparam 'startx' && ! echo "$CMDLINE" | grep -q 'startx.*nostartx' ; then
1317 if [ -x "$(which X)" ] ; then
1318 if [ -z "$INSTALLED" ] ; then
1319 WINDOWMANAGER="$(getbootparam 'startx' 2>>$DEBUG)"
1320 if [ -z "$WINDOWMANAGER" ] ; then
1321 einfo "No window manager specified. Using default one." && eend 0
1323 einfo "Window manager ${WHITE}${WINDOWMANAGER}${NORMAL} found as bootoption." && eend 0
1325 einfo "Setting up and invoking grml-x ${WINDOWMANAGER}. Just exit X windows system to get full featured consoles."
1328 if [ -n "$WINDOWMANAGER" ] ; then
1329 mkdir -p /var/run/grml-x/
1330 echo "$WINDOWMANAGER" > /var/run/grml-x/window-manager
1335 cat>|/etc/init.d/startx<<EOF
1337 su "${localuser}" -c "/usr/bin/grml-x ${WINDOWMANAGER}"
1339 chmod 755 /etc/init.d/startx
1341 # adjust inittab for startx
1342 if grep -q '^6:' /etc/inittab ; then
1343 sed -i 's|^6:.*|6:2345:respawn:/bin/zsh --login -c "/etc/init.d/startx ; /usr/share/grml-scripts/run-welcome" >/dev/tty6 2>\&1 </dev/tty6|' /etc/inittab
1344 else # just append tty6 to inittab if no definition is present:
1345 echo '6:2345:respawn:/bin/zsh --login -c "/etc/init.d/startx ; /usr/share/grml-scripts/run-welcome" >/dev/tty6 2>&1 < /dev/tty6' >> /etc/inittab
1348 /sbin/telinit q ; eend $?
1350 if grep -q '^allowed_users=' /etc/X11/Xwrapper.config ; then
1351 sed -i 's/^allowed_users=.*/allowed_users=anybody/' /etc/X11/Xwrapper.config
1353 echo 'allowed_users=anybody' >> /etc/X11/Xwrapper.config
1357 eerror "We are not running in live mode - startx will not work, skipping it."
1358 eerror " -> Please use something like xdm, gdm or kdm for starting X on a harddisk system!" ; eend 1
1361 eerror "/usr/bin/X is not present on this grml flavour."
1362 eerror " -> Boot parameter startx does not work therefore." ; eend 1
1368 # {{{ configuration framework
1370 if checkbootparam 'extract' ; then
1371 EXTRACT="$(getbootparam 'extract' 2>>$DEBUG)"
1372 EXTRACTOPTIONS="-- -x $EXTRACT"
1376 config_finddcsdir() {
1377 # - If no GRMLCFG partition is found and noautoconfig is _not_ given
1378 # on the command line, nothing is changed and the dcs files are
1379 # searched within the .iso, $dcs-dir is set to the root directory
1381 # - If a GRMLCFG partition is found, $dcs-dir is set to the root of
1382 # the GRMLCFG partition unless noautoconfig is set. If noautoconfig is
1383 # set, $dcs-dir is set to the root directory within the .iso.
1384 # - If myconfig=foo is set on the command line, $dcs-dir is set to
1385 # foo, even if a GRMLCFG partition is present.
1388 # autoconfig, see issue673
1389 GRMLCFG="$(getbootparam 'autoconfig' 2>>$DEBUG)"
1390 [ -n "$GRMLCFG" ] || GRMLCFG="GRMLCFG"
1391 if checkbootparam 'noautoconfig' ; then
1392 DCSDIR="${LIVECD_PATH}" # set default so it works for "scripts" boot option as expected
1393 ewarn "Skipping running automount of device(s) labeled $GRMLCFG as requested." ; eend 0
1395 if [ -z "$INSTALLED" ] ; then
1396 if checkbootparam 'myconfig' ; then
1397 DCSDEVICE="$(getbootparam 'myconfig' 2>>$DEBUG)"
1398 if [ -z "$DCSDEVICE" ]; then
1399 eerror "Error: No device for bootoption myconfig provided." ; eend 1
1400 fi # [ -z "$DCSDEVICE" ]
1401 elif checkvalue $CONFIG_MYCONFIG; then # checkbootparam myconfig
1402 einfo "Searching for device(s) labeled with $GRMLCFG. (Disable this via boot option: noautoconfig)" ; eend 0
1404 DCSDEVICE=$(blkid -t LABEL=$GRMLCFG | head -1 | awk -F: '{print $1}')
1406 modprobe 9p 2>/dev/null || true
1407 if [ -z "$DCSDEVICE" ] && grep -q 9p /proc/filesystems ; then
1408 if grep -q "$GRMLCFG" /sys/bus/virtio/devices/*/mount_tag 2>/dev/null ; then
1409 einfo "Found 9p-virtio fs with mount_tag $GRMLCFG"
1410 DCSDEVICE="$GRMLCFG"
1411 MOUNTOPTIONS="ro,trans=virtio"
1416 if [ -n "$DCSDEVICE" ]; then
1417 DCSMP="/mnt/grmlcfg"
1422 # if not specified/present then assume default:
1423 if [ -z "$DCSDEVICE" ]; then
1424 DCSDIR="${LIVECD_PATH}"
1427 einfo "debs, config, scripts are read from $DCSDEVICE." ; eend 0
1428 DCSDIR="$(< /proc/mounts awk -v DCSDEV=$DCSDEVICE '{if ($1 == DCSDEV) { print $2 }}')"
1429 if [ -n "$DCSDIR" ]; then
1430 ewarn "$DCSDEVICE already mounted on $DCSDIR"; eend 0
1432 [ -d $DCSMP ] || mkdir $DCSMP
1433 umount $DCSMP >>$DEBUG 2>&1 # make sure it is not mounted
1434 mount -o ${MOUNTOPTIONS:-ro} -t ${DCSFS:-auto} $DCSDEVICE $DCSMP ; RC="$?"
1435 if [[ $RC == 0 ]]; then
1436 einfo "Successfully mounted $DCSDEVICE to $DCSMP (readonly)." ; eend 0
1438 eerror "Error: mounting $DCSDEVICE to $DCSMP (readonly) failed." ; eend 1
1447 if [ -n "$DCSDIR" -a "$DCSDIR" != "${LIVECD_PATH}" ] ; then
1448 einfo "Debs, config, scripts (if present) will be read from $DCSDIR." ; eend 0
1449 elif checkbootparam 'debs' || checkbootparam 'config' || checkbootparam 'scripts'; then
1450 einfo "Debs, config, scripts will be read from the live image directly." ; eend 0
1456 if checkbootparam 'partconf' ; then
1457 MOUNTDEVICE="$(getbootparam 'partconf' 2>>$DEBUG)"
1458 if [ -n "$MOUNTDEVICE" ]; then
1459 [ -d /mnt/grml ] || mkdir /mnt/grml
1460 mount -o ro -t auto $MOUNTDEVICE /mnt/grml ; RC="$?"
1461 if [[ $RC == 0 ]]; then
1462 einfo "Successfully mounted $MOUNTDEVICE to /mnt/grml (readonly)." ; eend 0
1463 einfo "Copying files from $MOUNTDEVICE over grml system."
1464 for file in `cat /etc/grml/partconf` ; do
1465 [ -d /mnt/grml/$file ] && cp -a /mnt/grml/${file}* ${file} && echo "copied: $file"
1466 [ -f /mnt/grml/$file ] && cp -a /mnt/grml/${file} ${file} && echo "copied: $file"
1469 einfo "Could not mount $MOUNTDEVICE to /mnt/grml - sorry." ; eend 1
1470 fi # mount $MOUNTDEVICE
1471 grep -q '/mnt/grml' /proc/mounts && umount /mnt/grml
1473 einfo "Sorry, no device for bootoption partconf provided. Skipping." ; eend 1
1474 fi # [ -n "$MOUNTDEVICE" ]
1479 # {{{ /cdrom/.*-options
1481 if checkbootparam 'debs' ; then
1482 iszsh && setopt localoptions shwordsplit
1483 DEBS="$(getbootparam 'debs' 2>>$DEBUG)"
1484 if [ -z "$DEBS" ] ; then
1487 if ! echo $DEBS | grep -q '/'; then
1488 # backwards compatibility: if no path is given get debs from debs/
1491 einfo "Trying to install Debian package(s) ${DEBS}"
1492 DEBS="$(eval echo ${DCSDIR}/$DEBS)"
1493 dpkg -i $DEBS ; eend $?
1498 if checkbootparam 'scripts' || [ "$DCSMP" = "/mnt/grmlcfg" ]; then
1499 SCRIPTS="$(getbootparam 'scripts' 2>>$DEBUG)"
1500 if [ -d ${DCSDIR}/scripts ] && [ -z "$SCRIPTS" ]; then
1501 SCRIPTS="$(cd ${DCSDIR}/scripts; /bin/ls -1d [Gg][Rr][Mm][Ll].[Ss][Hh] 2>>$DEBUG)"
1503 if ! echo $SCRIPTS | grep -q '/'; then
1504 # backwards compatibility: if no path is given get scripts from scripts/
1505 SCRIPTS="scripts/$SCRIPTS"
1507 if [ -n "$SCRIPTS" ]; then
1508 SCRIPTS="${DCSDIR}/$SCRIPTS"
1509 if [ "$DCSMP" = "/mnt/grmlcfg" ]; then
1510 einfo "Trying to execute ${SCRIPTS}"
1513 elif [ -d "$SCRIPTS" ]; then
1514 einfo "Bootparameter scripts found. Trying to execute from directory ${SCRIPTS}:"
1515 run-parts --regex '.*' $SCRIPTS
1518 einfo "Bootparameter scripts found. Trying to execute ${SCRIPTS}:"
1527 if checkbootparam 'config' || [ "$DCSMP" = "/mnt/grmlcfg" ]; then
1528 CONFIG="$(getbootparam 'config' 2>>$DEBUG)"
1529 if [ -z "$CONFIG" ]; then
1530 CONFIG="$(cd ${DCSDIR}; ls -1d [Cc][Oo][Nn][Ff][Ii][Gg].[Tt][Bb][Zz] 2>>$DEBUG)"
1532 if [ -n "$CONFIG" ]; then
1533 if [ -d "${DCSDIR}/${CONFIG}" ] ; then
1534 einfo "Taking configuration from directory ${DCSDIR}/${CONFIG}"
1536 cp -a ${DCSDIR}/${CONFIG}/* /
1537 elif [ -f "${DCSDIR}/${CONFIG}" ]; then
1538 einfo "Extracting configuration from file ${DCSDIR}/${CONFIG}"
1541 unp ${DCSDIR}/${CONFIG} $EXTRACTOPTIONS ; eend $?
1543 ewarn "Sorry, could not find configuration file or directory ${DCSDIR}/${FILENAME}." ; eend 1
1550 # {{{ confing_umount_dcsdir
1551 config_umount_dcsdir(){
1552 # umount $DCSMP if it was mounted by finddcsdir
1553 grep -q "$DCSMP" /proc/mounts && umount "$DCSMP"
1559 if checkbootparam 'mypath' ; then
1560 MY_PATH="$(getbootparam 'mypath' 2>>$DEBUG)"
1561 einfo "Bootparameter mypath found, adding ${MY_PATH} to /etc/grml/my_path"
1562 touch /etc/grml/my_path
1563 chmod 644 /etc/grml/my_path
1564 # make sure the directories exist:
1566 for i in $(echo $MY_PATH | sed 's/:/\n/g') ; do
1567 if ! [ -d "$i" ] ; then
1568 einfo "Creating directory $i"
1569 mkdir -p "$i" ; eend $?
1572 grep -q "${MY_PATH}" /etc/grml/my_path || echo "${MY_PATH}" >> /etc/grml/my_path ; eend $?
1580 [ -n "$INSTALLED" ] && return 0
1582 if checkbootparam 'noraid' || checkbootparam 'noswraid' || \
1583 checkbootparam 'raid=noautodetect' ; then
1584 ewarn "Skipping SW-RAID code as requested on boot commandline." ; eend 0
1586 [ -e /proc/mdstat ] || modprobe md_mod
1587 if ! [ -x /sbin/mdadm ] ; then
1588 eerror "mdadm not available, can not execute it." ; eend 1
1591 # if ! egrep -qv '^(MAILADDR.*|#.*|)$' /etc/mdadm/mdadm.conf 2>>$DEBUG ; then
1592 # find out whether we have a valid configuration file already
1593 if ! grep -q ARRAY /etc/mdadm/mdadm.conf 2>>$DEBUG ; then
1594 einfo "Creating /etc/mdadm/mdadm.conf for use with mdadm."
1595 [ -r /etc/mdadm/mdadm.conf ] && mv /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf.old
1596 MDADM_MAILADDR__='root' /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf ; eend $?
1598 ewarn "/etc/mdadm/mdadm.conf looks like a configured mdadm setup, will not touch it." ; eend 0
1601 if ! checkbootparam 'swraid' ; then
1604 einfo "Just run 'mdadm --assemble --scan' to assemble md arrays or boot using 'swraid' as bootoption for autostart."
1606 einfo "Just run 'Start mdadm-raid' to assemble md arrays or boot using 'swraid' as bootoption for autostart."
1610 einfo "Bootoption swraid found. Searching for software RAID arrays:"
1614 for line in $(mdadm --assemble --scan 2>&1) ; do
1616 *'No arrays found'*)
1617 ewarn "$line" ; eend 0
1620 einfo "$line" ; eend 0
1627 if [ -r /proc/mdstat ] ; then
1629 MDSTAT=$(grep '^md[0-9]' /proc/mdstat)
1630 if [ -z "$MDSTAT" ] ; then
1631 ewarn "No active arrays found" ; eend 0
1635 for line in $(grep '^md[0-9]' /proc/mdstat) ; do
1636 einfo "active arrays: $line" ; eend 0
1642 fi # bootoption swraid
1644 fi # is /sbin/mdadm executable?
1645 fi # check for bootoptions
1651 [ -n "$INSTALLED" ] && return 0
1653 if checkbootparam 'nodmraid' ; then
1654 ewarn "Skipping dmraid code as requested on boot commandline." ; eend 0
1658 if ! [ -x /sbin/dmraid ] ; then
1659 eerror "dmraid not available, can not execute it." ; eend 1
1664 # usage: dmraid_wrapper <dmraid_option>
1665 [ -n "$1" ] || return 1
1671 for line in $(dmraid $1 ; echo errcode:$?); do
1673 *'no block devices found'*)
1674 einfo "No block devices found" ; eend 0
1678 einfo "No active dmraid devices found" ; eend 0
1697 if checkbootparam 'dmraid' ; then
1698 local ACTION="$(getbootparam 'dmraid' 2>>$DEBUG)"
1699 if [ "$ACTION" = "off" ] ; then
1700 # Deactivates all active software RAID sets:
1701 einfo "Deactivating present dmraid sets (as requested via dmraid=off):"
1704 # Activate all software RAID sets discovered:
1705 einfo "Activating present dmraid sets (as requested via dmraid):"
1712 # by default (no special bootoptions) discover all software RAID devices:
1713 einfo "Searching for any present dmraid sets:"
1718 # {{{ LVM (Logical Volumes)
1720 [ -n "$INSTALLED" ] && return 0
1722 if checkbootparam 'nolvm' ; then
1723 ewarn "Skipping LVM code as requested on boot commandline." ; eend 0
1725 if ! [ -x /sbin/lvm ] ; then
1726 eerror "LVM not available, can not execute it." ; eend 1
1728 if lvdisplay 2>&1 | grep -v 'No volume groups found' >/dev/null 2>&1 ; then
1729 einfo "You seem to have logical volumes (LVM) on your system."
1732 einfo "Just run 'Start lvm2-pvscan@name' to activate LV or VG 'name' or boot using 'lvm' as bootoption for autostart."
1734 einfo "Just run 'Start lvm2' to activate them or boot using 'lvm' as bootoption for autostart."
1737 if checkbootparam 'lvm' ; then
1738 einfo "Bootoption LVM found. Searching for logical volumes and enabling them:"
1740 service_wrapper lvm2-lvmetad start
1744 service_wrapper lvm2 start ; eend $?
1749 fi # check for lvm binary
1750 fi # check for bootoption nolvm
1754 # {{{ debnet: setup network based on an existing one found on a partition
1756 if checkbootparam 'debnet' ; then
1757 einfo "Bootoption 'debnet' found. Searching for Debian network configuration: "
1763 # {{{ disable console blanking
1765 if checkbootparam 'noblank' ; then
1766 einfo "Bootoption noblank found. Disabling monitor blanking."
1767 setterm -blank 0 ; eend $?
1772 # {{{ debootstrap: automatic installation
1773 config_debootstrap(){
1775 if checkbootparam "BOOT_IMAGE=debian2hd" || checkbootparam "debian2hd" ; then
1777 einfo "Bootoption debian2hd found. Setting up environment for automatic installation via grml-debootstrap." ; eend 0
1779 if ! [ -x /usr/sbin/grml-debootstrap ] ; then
1781 eerror "Bootoption debian2hd found, but grml-debootstrap is not available." ; eend 1
1786 if checkbootparam 'target' ; then
1788 TARGET="$(getbootparam 'target' 2>>$DEBUG)"
1789 # notice: the following checks whether the given partition is available, if not the skip
1790 # execution of grml-debootstrap as it might result in data loss...
1791 if ! [ -r "$TARGET" ] ; then
1792 eerror "Target $TARGET does not exist. Skipping execution of grml-debootstrap therefore." ; eend 1
1796 eerror "No bootoption named target found, can not continue execution of grml-debootstrap." ; eend 1
1801 if checkbootparam 'grub' ; then
1803 GRUB="$(getbootparam 'grub' 2>>$DEBUG)"
1806 if checkbootparam 'groot' ; then
1808 GROOT="$(getbootparam 'groot' 2>>$DEBUG)"
1811 if checkbootparam 'release' ; then
1813 RELEASE="$(getbootparam 'release' 2>>$DEBUG)"
1816 if checkbootparam 'mirror' ; then
1818 MIRROR="$(getbootparam 'mirror' 2>>$DEBUG)"
1821 if checkbootparam 'boot_append' ; then
1823 BOOT_APPEND="$(getbootparam 'boot_append' 2>>$DEBUG)"
1826 if checkbootparam 'password' ; then
1828 PASSWORD="$(getbootparam 'password' 2>>$DEBUG)"
1831 # now check which options are available
1832 if [ -n "TARGET" ] ; then
1833 TARGETCMD="--target $TARGET"
1837 eerror "Target not set via bootoption. Skipping execution of grml-debootstrap therefore."; eend 1
1841 [ -n "$GRUB" ] && GRUBCMD="--grub $GRUB" || GRUBCMD=''
1842 [ -n "$GROOT" ] && GROOTCMD="--groot $GROOT" || GROOTCMD=''
1843 [ -n "$RELEASE" ] && RELEASECMD="--release $RELEASE" || RELEASECMD=''
1844 [ -n "$MIRROR" ] && MIRRORCMD="--mirror $MIRROR" || MIRRORCMD=''
1845 [ -n "$PASSWORD" ] && PASSWORDCMD="--password $PASSWORD" || PASSWORDCMD=''
1846 [ -n "$BOOT_APPEND" ] && BOOT_APPEND="--boot_append $BOOT_APPEND" || BOOT_APPEND=''
1848 # and finally write script and execute it
1849 cat>|/usr/bin/grml-debootstrap_noninteractive<<EOF
1851 AUTOINSTALL='yes' grml-debootstrap $TARGETCMD $GRUBCMD $GROOTCMD $RELEASECMD $MIRRORCMD $PASSWORDCMD $BOOT_APPEND
1854 chmod 750 /usr/bin/grml-debootstrap_noninteractive
1856 screen /usr/bin/grml-debootstrap_noninteractive
1857 einfo "Invoking a shell, just exit to continue booting..."
1860 fi # checkbootparam "BOOT_IMAGE=debian2hd
1864 # {{{ virtualbox shared folders
1865 config_virtualbox_shared_folders() {
1866 if $VIRTUALBOX ; then
1867 einfo "VirtualBox detected, trying to set up Shared Folders."
1868 if ! modinfo vboxsf &>/dev/null ; then
1869 ewarn "vboxsf driver not present, not setting up VirtualBox Shared Folders."
1871 elif ! [ -x /usr/sbin/VBoxService ] ; then
1872 ewarn "virtualbox-guest-utils not installed, not setting up VirtualBox Shared Folders."
1877 einfo "Loading vboxsf driver."
1878 lsmod | grep -q vboxsf || modprobe vboxsf
1881 einfo "Adjusting /dev/vboxguest."
1882 chown root:vboxsf /dev/vboxguest
1883 chmod 660 /dev/vboxguest
1888 einfo "Adding $fstabuser to group vboxsf."
1889 adduser grml vboxsf &>/dev/null
1892 einfo "Starting VBoxService."
1893 VBoxService >/dev/null
1896 local vbautomation='automation'
1897 if checkbootparam 'vbautomation'; then
1898 vbautomation="$(getbootparam 'vbautomation' 2>>$DEBUG)"
1901 if ! VBoxControl sharedfolder list | egrep -q "^[0-9]+ - ${vbautomation}$" ; then
1902 ewarn "No automount shared folder '$vbautomation' available"
1905 einfo "Found automount shared folder '$vbautomation'"
1908 local distri="$(getbootparam 'distri' 2>>$DEBUG)"
1909 [ -n "$distri" ] || distri='grml'
1911 local vbox_auto_sf="/media/sf_${vbautomation}"
1913 sleep 1 # ugly but necessary
1917 while ! [ -d "${vbox_auto_sf}" ] && [[ "$counter" != 0 ]]; do
1918 einfo "Waiting another second to retry access to ${vbox_auto_sf}"
1920 counter=$(( counter-1 ))
1925 if ! [ -d "${vbox_auto_sf}" ] ; then
1926 eerror "Giving up trying to access folder ${vbox_auto_sf} which doesn't seem to exist"
1929 einfo "Found shared folders automation directory $vbox_auto_sf"
1933 if checkbootparam 'novbautomation' ; then
1934 einfo "Bootoption novbautomation found. Disabling automation script execution."
1937 if ! [ -x "${vbox_auto_sf}/${distri}" ] ; then
1938 ewarn "Couldn't find an automation script named ${vbox_auto_sf}/${distri}"
1941 einfo "Executing '${vbox_auto_sf}/${distri}' now:"
1942 "${vbox_auto_sf}/${distri}"
1956 # {{{ Support customization
1958 if checkbootparam 'distri'; then
1959 DISTRI="$(getbootparam 'distri' 2>>$DEBUG)"
1960 if [ -r "${LIVECD_PATH}"/desktop/"$DISTRI".jpg ] ; then
1961 # make sure the desktop.jpg file is not a symlink, so copying does not file then
1962 [ -L /usr/share/grml/desktop.jpg ] && rm /usr/share/grml/desktop.jpg
1963 cp "${LIVECD_PATH}"/desktop/"$DISTRI".jpg /usr/share/grml/desktop.jpg
1969 ## END OF FILE #################################################################
1970 # vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=2