VirtualBox shared folders: expect exact match for automation folder name
[grml-autoconfig.git] / autoconfig.functions
index 6f774db..3aa9787 100755 (executable)
@@ -13,12 +13,10 @@ KERNEL="$(uname -r)"
 ARCH="$(uname -m)"
 umask 022
 
-# old linuxrc version:
-[ -d /cdrom ]      && export LIVECD_PATH=/cdrom
-# initramfs layout until around December 2012:
-[ -d /live/image ] && export LIVECD_PATH=/live/image
-# initramfs layout since around December 2012:
-[ -d /lib/live/mount/medium ] && export LIVECD_PATH=/lib/live/mount/medium
+# initramfs layout since December 2012, backwards compatibility:
+[ -d /lib/live/mount/medium ] && export LIVECD_PATH='/lib/live/mount/medium'
+# initramfs layout since December 2018:
+[ -d /run/live/medium ] && export LIVECD_PATH='/run/live/medium'
 
 # Ignore these signals in non-interactive mode: INT, TERM, SEGV
 [ -z "$PS1" ] && trap "" 2 3 11
@@ -31,17 +29,22 @@ fi
 
 service_wrapper() {
   if [ "$#" -lt 2 ] ; then
-    echo "Usage: service_wrapper <service> <action>" >&2
+    echo "Usage: service_wrapper <service> <action> [background]" >&2
     return 1
   fi
 
   local service="$1"
   local action="$2"
+  local background="$3"
 
   if $SYSTEMD ; then
     systemctl "$action" "$service"
   else
-    /etc/init.d/"$service" "$action"
+    if [ "${background:-}" = "background" ] ; then
+      /etc/init.d/"$service" "$action" &
+    else
+      /etc/init.d/"$service" "$action"
+    fi
   fi
 }
 
@@ -183,11 +186,15 @@ VMWARE=false
 
 if vmware-detect &>/dev/null; then
   VIRTUAL=true; VMWARE=true; VIRTUAL_ENV='VMware'
-elif [ "$(virt-what 2>/dev/null)" = "kvm" ] || \
-   [ "$(imvirt 2>/dev/null)" = "KVM" ] ; then
+fi
+
+if virt-what 2>/dev/null | grep -q 'kvm' || \
+  [ "$(imvirt 2>/dev/null)" = "KVM" ] ; then
   VIRTUAL=true; KVM=true; VIRTUAL_ENV='KVM'
-elif [ "$(virt-what 2>/dev/null)" = "virtualbox" ] || \
-   [ "$(imvirt 2>/dev/null)" = "VirtualBox" ] ; then
+fi
+
+if virt-what 2>/dev/null | grep -q 'virtualbox' || \
+  [ "$(imvirt 2>/dev/null)" = "VirtualBox" ] ; then
   VIRTUAL=true; VIRTUALBOX=true; VIRTUAL_ENV='VirtualBox'
 fi
 # }}}
@@ -201,36 +208,6 @@ else
 fi
 # }}}
 
-# {{{ debug
-config_debug(){
- checkbootparam 'debug'            && BOOTDEBUG="yes"
- checkbootparam "BOOT_IMAGE=debug" && BOOTDEBUG="yes"
-
- rundebugshell(){
-  if [ -n "$BOOTDEBUG" ]; then
-     einfo "Starting intermediate shell stage $stage as requested by \"debug\" option."
-     if [ grep -q "debug=noscreen" "$CMDLINE" ] ; then
-        einfo "Notice that the shell does not provide job handling: ctrl-z, bg and fg won't work!"
-        einfo "Just exit the shell to continue boot process..."
-        /bin/zsh
-     else
-        eindent
-        if [ -r /etc/grml/screenrc ] ; then
-           einfo "Starting GNU screen to be able to use a full featured shell environment."
-           einfo "Just exit the shells (and therefore screen) to continue boot process..."
-           /bin/zsh -c "screen -c /etc/grml/screenrc"
-        else
-           einfo "Notice that the shell does not provide job handling: ctrl-z, bg and fg won't work!"
-           einfo "Just exit the shell to continue boot process..."
-           /bin/zsh
-        fi
-        eoutdent
-     fi
-  fi
- }
-}
-# }}}
-
 # {{{ log
 config_log(){
 if checkbootparam 'log' || checkbootparam 'debug' ; then
@@ -250,165 +227,190 @@ fi
 ### {{{ language configuration / localization
 config_language(){
 
- einfo "Activating language settings:"
- eindent
 einfo "Activating language settings:"
 eindent
 
- # people can specify $LANGUAGE and $CONSOLEFONT in a config file
- [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig
 # people can specify $LANGUAGE and $CONSOLEFONT in a config file
 [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig
 
- # check for bootoption which overrides config from /etc/grml/autoconfig
- BOOT_LANGUAGE="$(getbootparam 'lang' 2>>$DEBUG)"
- [ -n "$BOOT_LANGUAGE" ] && LANGUAGE="$BOOT_LANGUAGE"
 # check for bootoption which overrides config from /etc/grml/autoconfig
 BOOT_LANGUAGE="$(getbootparam 'lang' 2>>$DEBUG)"
 [ -n "$BOOT_LANGUAGE" ] && LANGUAGE="$BOOT_LANGUAGE"
 
- # set default to 'en' in live-cd mode iff $LANGUAGE is not set yet
- if [ -z "$INSTALLED" ] ; then
 # set default to 'en' in live-cd mode iff $LANGUAGE is not set yet
 if [ -z "$INSTALLED" ] ; then
     [ -n "$LANGUAGE" ] || LANGUAGE='en'
- fi
 fi
 
- if [ -x /usr/sbin/grml-setlang ] ; then
-   # if bootoption lang is used update /etc/default/locale accordingly
-   if [ -n "$BOOT_LANGUAGE" ] ; then
-     /usr/sbin/grml-setlang "$LANGUAGE"
-   # otherwise default to lang=en
-   else
-     /usr/sbin/grml-setlang "en"
-   fi
- fi
 if [ -x /usr/sbin/grml-setlang ] ; then
+    # if bootoption lang is used update /etc/default/locale accordingly
+    if [ -n "$BOOT_LANGUAGE" ] ; then
+      /usr/sbin/grml-setlang "$LANGUAGE"
+      # otherwise default to lang=en
+    else
+      /usr/sbin/grml-setlang "en"
+    fi
 fi
 
- # set console font
- if [ -z "$CONSOLEFONT" ] ; then
-    if ! checkbootparam 'nodefaultfont' >>$DEBUG 2>&1 ; then
-       if [ -r /usr/share/consolefonts/Uni3-Terminus16.psf.gz ] ; then
+  if ! $SYSTEMD ; then
+    # set console font
+    if [ -z "$CONSOLEFONT" ] ; then
+      if ! checkbootparam 'nodefaultfont' >>$DEBUG 2>&1 ; then
+        if [ -r /usr/share/consolefonts/Uni3-Terminus16.psf.gz ] ; then
           CONSOLEFONT='Uni3-Terminus16'
-       else
+        else
           ewarn "/usr/share/consolefonts/Uni3-Terminus16.psf.gz not available. Please upgrade package console-terminus." ; eend 1
-       fi
-       if ! hasfb ; then
+        fi
+        if ! hasfb ; then
           CONSOLEFONT='Lat15-Terminus16'
-       fi
+        fi
+      fi
     fi
- fi
+  fi # not running systemd
 
- # export it now, so error messages get translated, too
- [ -r /etc/default/locale ] && . /etc/default/locale
- export LANG LANGUAGE
-
- # configure keyboard layout, read in already set values first:
- [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
-
- # now allow keyboard override by boot commandline for later use:
- KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
- [ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD"
- # notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead:
- [[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys
- [[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys
-
- # modify /etc/sysconfig/keyboard only in live-cd mode:
- if [ -z "$INSTALLED" ] ; then
-
-   local LANGUAGE="$BOOT_LANGUAGE"
-   . /etc/grml/language-functions
-   # allow setting xkeyboard explicitly different than console keyboard
-   KXKEYBOARD="$(getbootparam 'xkeyboard' 2>>$DEBUG)"
-   if [ -n "$KXKEYBOARD" ]; then
-      XKEYBOARD="$KXKEYBOARD"
-      KDEKEYBOARD="$KXKEYBOARD"
-   elif [ -n "$KKEYBOARD" ]; then
-      XKEYBOARD="$KKEYBOARD"
-      KDEKEYBOARD="$KKEYBOARD"
-   fi
+  # export it now, so error messages get translated, too
+  [ -r /etc/default/locale ] && . /etc/default/locale
+  export LANG LANGUAGE
 
-   # duplicate of previous code to make sure /etc/grml/language-functions
-   # does not overwrite our values....
-   # now allow keyboard override by boot commandline for later use:
-   KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
-   [ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD"
-   # notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead:
-   [[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys
-   [[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys
-
-   # write keyboard related variables to file for later use
-   [ -d /etc/sysconfig ] || mkdir /etc/sysconfig
-   if ! [ -e /etc/sysconfig/keyboard ] ; then
-      echo "KEYTABLE=\"$KEYTABLE\""          > /etc/sysconfig/keyboard
-      echo "XKEYBOARD=\"$XKEYBOARD\""       >> /etc/sysconfig/keyboard
-      echo "KDEKEYBOARD=\"$KDEKEYBOARD\""   >> /etc/sysconfig/keyboard
-      echo "KDEKEYBOARDS=\"$KDEKEYBOARDS\"" >> /etc/sysconfig/keyboard
-   fi
- fi
+  if $SYSTEMD ; then
+    local KEYBOARD
+    KEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
+    [ -n "$KEYBOARD" ] || KEYBOARD="$LANGUAGE"
+    # "symbols/en" doesn't exist, so rewrite to "us"
+    [[ "$KEYBOARD" == 'en' ]] && KEYBOARD="us"
+
+    if [ -r /etc/default/keyboard ] ; then
+      sed -i "s/^XKBLAYOUT=.*/XKBLAYOUT=\"$KEYBOARD\"/" /etc/default/keyboard
+
+      case "$KEYBOARD" in
+       de|at)
+         sed -i "s/^XKBVARIANT=.*/XKBVARIANT=\"nodeadkeys\"/" /etc/default/keyboard
+         ;;
+      esac
 
- [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
+    fi
+    service_wrapper console-setup restart >>$DEBUG 2>&1 ; eend $?
+  else # not running systemd, keeing for backwards compatibility:
+    # configure keyboard layout, read in already set values first:
+    [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
+
+    # now allow keyboard override by boot commandline for later use:
+    KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
+    [ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD"
+    # notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead:
+    [[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys
+    [[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys
+
+    # modify /etc/sysconfig/keyboard only in live-cd mode:
+    if [ -z "$INSTALLED" ] ; then
+
+      local LANGUAGE="$BOOT_LANGUAGE"
+      . /etc/grml/language-functions
+      # allow setting xkeyboard explicitly different than console keyboard
+      KXKEYBOARD="$(getbootparam 'xkeyboard' 2>>$DEBUG)"
+      if [ -n "$KXKEYBOARD" ]; then
+        XKEYBOARD="$KXKEYBOARD"
+        KDEKEYBOARD="$KXKEYBOARD"
+      elif [ -n "$KKEYBOARD" ]; then
+        XKEYBOARD="$KKEYBOARD"
+        KDEKEYBOARD="$KKEYBOARD"
+      fi
 
- # activate unicode console if running within utf8 environment
- if [ -r /etc/default/locale ] ; then
-    if grep -q "LANG=.*UTF" /etc/default/locale ; then
-       einfo "Setting up unicode environment."
-       unicode_start >>$DEBUG 2>&1 ; eend $?
+      # duplicate of previous code to make sure /etc/grml/language-functions
+      # does not overwrite our values....
+      # now allow keyboard override by boot commandline for later use:
+      KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
+      [ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD"
+      # notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead:
+      [[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys
+      [[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys
+
+      # write keyboard related variables to file for later use
+      [ -d /etc/sysconfig ] || mkdir /etc/sysconfig
+      if ! [ -e /etc/sysconfig/keyboard ] ; then
+        echo "KEYTABLE=\"$KEYTABLE\""          > /etc/sysconfig/keyboard
+        echo "XKEYBOARD=\"$XKEYBOARD\""       >> /etc/sysconfig/keyboard
+        echo "KDEKEYBOARD=\"$KDEKEYBOARD\""   >> /etc/sysconfig/keyboard
+        echo "KDEKEYBOARDS=\"$KDEKEYBOARDS\"" >> /etc/sysconfig/keyboard
+      fi
     fi
- fi
 
- # Set default keyboard before interactive setup
- if [ -n "$KEYTABLE" ] ; then
-    einfo "Running loadkeys for ${WHITE}${KEYTABLE}${NORMAL} in background"
-    loadkeys -q $KEYTABLE &
-    eend $?
- fi
+    [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
+  fi
 
- # we have to set up all consoles, therefore loop it over all ttys:
- NUM_CONSOLES=$(fgconsole --next-available 2>/dev/null)
- if [ -n "$NUM_CONSOLES" ] ; then
-    NUM_CONSOLES=$(expr ${NUM_CONSOLES} - 1)
-    [ ${NUM_CONSOLES} -eq 1 ] && NUM_CONSOLES=6
- fi
- CUR_CONSOLE=$(fgconsole 2>/dev/null)
 
- if [ -x "$(which setfont)" ] ; then
-    use_setfont=true
- elif [ -x "$(which consolechars)" ] ; then
-    use_consolechars=true
- else
-    eerror "Neither setfont nor consolechars tool present, can not set font."
-    eend 1
-    return 1
- fi
+  if ! $SYSTEMD ; then
+    # we have to set up all consoles, therefore loop it over all ttys:
+    NUM_CONSOLES=$(fgconsole --next-available 2>/dev/null)
+    if [ -n "$NUM_CONSOLES" ] ; then
+      NUM_CONSOLES=$(expr ${NUM_CONSOLES} - 1)
+      [ ${NUM_CONSOLES} -eq 1 ] && NUM_CONSOLES=6
+    fi
+    CUR_CONSOLE=$(fgconsole 2>/dev/null)
+
+    if [ -x "$(which setfont)" ] ; then
+      use_setfont=true
+    elif [ -x "$(which consolechars)" ] ; then
+      use_consolechars=true
+    else
+      eerror "Neither setfont nor consolechars tool present, can not set font."
+      eend 1
+      return 1
+    fi
 
- if [ -n "$CHARMAP" ] ; then
-    einfo "Setting font to ${CHARMAP}"
-    RC=0
-    for vc in $(seq 0 ${NUM_CONSOLES}) ; do
   if [ -n "$CHARMAP" ] ; then
+      einfo "Setting font to ${CHARMAP}"
+      RC=0
+      for vc in $(seq 0 ${NUM_CONSOLES}) ; do
         if $use_setfont ; then
           setfont -C /dev/tty${vc} $CHARMAP ; RC=$?
         elif $use_consolechars ; then
           consolechars --tty=/dev/tty${vc} -m ${CHARMAP} ; RC=$?
         fi
-    done
-    if [ -n "$CUR_CONSOLE" ] ; then
-       [ "$CUR_CONSOLE" != "serial" ] && chvt $CUR_CONSOLE
+      done
+      if [ -n "$CUR_CONSOLE" ] ; then
+        [ "$CUR_CONSOLE" != "serial" ] && chvt $CUR_CONSOLE
+      fi
+      eend $RC
     fi
-    eend $RC
- fi
 
- if checkbootparam 'noconsolefont' ; then
-    ewarn "Skipping setting console font as requested on boot commandline." ; eend 0
- else
-    if [ -n "$CONSOLEFONT" ] ; then
-       einfo "Setting font to ${CONSOLEFONT}"
-       RC=0
-       for vc in $(seq 0 ${NUM_CONSOLES}) ; do
-           if $use_setfont ; then
-             setfont -C /dev/tty${vc} ${CONSOLEFONT} ; RC=$?
-           elif $use_consolechars ; then
-             consolechars --tty=/dev/tty${vc} -f ${CONSOLEFONT} ; RC=$?
-           fi
-       done
-       if [ -n "$CUR_CONSOLE" ] ; then
   if checkbootparam 'noconsolefont' ; then
+      ewarn "Skipping setting console font as requested on boot commandline." ; eend 0
   else
+      if [ -n "$CONSOLEFONT" ] ; then
+        einfo "Setting font to ${CONSOLEFONT}"
+        RC=0
+        for vc in $(seq 0 ${NUM_CONSOLES}) ; do
+          if $use_setfont ; then
+            setfont -C /dev/tty${vc} ${CONSOLEFONT} ; RC=$?
+          elif $use_consolechars ; then
+            consolechars --tty=/dev/tty${vc} -f ${CONSOLEFONT} ; RC=$?
+          fi
+        done
+        if [ -n "$CUR_CONSOLE" ] ; then
           [ "$CUR_CONSOLE" != "serial" ] && chvt $CUR_CONSOLE
-       fi
-       eend $RC
+        fi
+        eend $RC
+      fi
     fi
- fi
 
- eoutdent
+    # Set default keyboard before interactive setup
+    if [ -n "$KEYTABLE" ] ; then
+      einfo "Running loadkeys for ${WHITE}${KEYTABLE}${NORMAL} in background"
+      loadkeys -q $KEYTABLE &
+      eend $?
+    fi
+
+    # activate unicode console if running within utf8 environment
+    if [ -r /etc/default/locale ] ; then
+      if grep -q "LANG=.*UTF" /etc/default/locale ; then
+        einfo "Setting up unicode environment."
+        unicode_start ; eend $?
+      fi
+    fi
+  fi # not running systemd
+
+  eoutdent
 }
 # }}}
 
@@ -542,19 +544,28 @@ config_kernel(){
 
 # {{{ secure boot
 config_secureboot(){
+  # systemd does this for us, but if we are not running under systemd then mokutil
+  # doesn't work as needed as it relies on /sys/firmware/efi/efivars (while
+  # /sys/firmware/efi/vars would exist)
+  if ! $SYSTEMD ; then
+    if modprobe efivars &>/dev/null ; then
+      mount -t efivarfs efivarfs /sys/firmware/efi/efivars
+    fi
+  fi
+
   if [ -x /usr/bin/mokutil ] ; then
     local secstate=$(mokutil --sb-state 2>/dev/null) # "SecureBoot enabled"
     if [ -n "$secstate" ] ; then
       einfo "SecureBoot is enabled" ; eend 0
     else
-      ewarn "SecureBoot not detected" ; eend 0
+      einfo "SecureBoot not detected" ; eend 0
     fi
   else
     if modprobe efivars &>/dev/null ; then
       if od -An -t u1 /sys/firmware/efi/vars/SecureBoot-*/data 2>/dev/null | grep -q 1 ; then
         einfo "SecureBoot is enabled" ; eend 0
       else
-        ewarn "SecureBoot not detected" ; eend 0
+        einfo "SecureBoot not detected" ; eend 0
       fi
     fi
   fi
@@ -590,6 +601,11 @@ config_timezone(){
 # activate serial console {{{
 config_console(){
 if checkbootparam 'console'; then
+  # this hack is no longer necessary with systemd
+  if $SYSTEMD ; then
+    return
+  fi
+
   local line
   local ws
   ws='  '
@@ -763,7 +779,8 @@ fi
 # {{{ Start brltty
 config_brltty() {
   if checkbootparam 'brltty' ; then
-    [ -x /lib/brltty/brltty.sh ] && /lib/brltty/brltty.sh
+    einfo "Starting brltty service as requested on boot commandline."
+    service_wrapper brltty start ; eend $?
   fi
 }
 # }}}
@@ -896,63 +913,6 @@ if [[ $(grep -c processor /proc/cpuinfo) -gt 1 ]] ; then
 else
    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
 fi
-
-# no cpufreq setup inside VirtualBox
-if $VIRTUALBOX ; then
-   einfo 'Virtual Box detected, skipping cpufreq setup.' ; eend 0
-   return 0
-fi
-
-if ! [ -x /etc/init.d/loadcpufreq ] ; then
-  ewarn "loadcpufreq init script not available, ignoring cpu frequency scaling."
-  eend 0
-  return 0
-else
-   einfo "Trying to set up cpu frequency scaling:"
-   eindent
-   SKIP_CPU_GOVERNOR=''
-   LOADCPUFREQ=$(mktemp)
-   /etc/init.d/loadcpufreq start >"$LOADCPUFREQ" 2>&1 ; RC=$?
-   if grep -q FATAL "$LOADCPUFREQ" ; then
-      eindent
-        SKIP_CPU_GOVERNOR=1
-        oldIFS="$IFS"
-        IFS="
-"
-         for line in $(grep FATAL "$LOADCPUFREQ" | sed 's/.*FATAL: //; s/ (.*)//') ; do
-             eerror "$line" ; eend $RC
-         done
-         IFS="$oldIFS"
-      eoutdent
-   elif grep -q done "$LOADCPUFREQ" ; then
-      MODULE=$(grep done "$LOADCPUFREQ" | sed 's/.*done (\(.*\))./\1/')
-      if [ -n "$MODULE" -a "$MODULE" != none ]; then
-         einfo "Loading cpufreq kernel module $MODULE" ; eend 0
-      else
-         SKIP_CPU_GOVERNOR=1
-         ewarn "Could not find an appropriate kernel module for cpu frequency scaling." ; eend 1
-      fi
-   fi
-
-   rm -f "$LOADCPUFREQ"
-
-   if [ -z "$SKIP_CPU_GOVERNOR" ] ; then
-     if [ -r /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors ] ; then
-       if ! grep -q ondemand /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors ; then
-         einfo "Ondemand governor not available for CPU(s), not modifying governor configuration"
-       else
-         einfo "Setting ondemand governor"
-         RC=0
-         for file in $(find /sys/devices/system/cpu/ -name scaling_governor 2>/dev/null) ; do
-           echo ondemand > $file || RC=1
-         done
-         eend $RC
-       fi
-     fi
-   fi
-
-   eoutdent
-fi
 }
 # }}}
 
@@ -987,8 +947,9 @@ if checkbootparam 'ssh' ; then
    fi
 
    einfo "Starting secure shell server in background for root and user $localuser"
+   service_wrapper haveged start >>$DEBUG 2>>$DEBUG
    service_wrapper rmnologin start >>$DEBUG 2>>$DEBUG
-   service_wrapper ssh start >>$DEBUG 2>>$DEBUG &
+   service_wrapper ssh start background >>$DEBUG 2>>$DEBUG
    eend $?
 
 fi
@@ -1132,83 +1093,82 @@ fi
 
 # {{{ Sound
 config_mixer () {
-   if ! [ -x /usr/bin/amixer ] ; then
-      eerror "amixer binary not available. Can not set sound volumes therefore."
-      eend 1
-   else
-      if ! [ -r /proc/asound/cards ] ; then
-         ewarn "No soundcard present, skipping mixer settings therefore."
-         eend 0
-         return
+  if ! [ -x /usr/bin/amixer ] ; then
+    logger -t grml-autoconfig "amixer binary not available"
+    return
+  fi
+
+  if ! [ -r /proc/asound/cards ] ; then
+    ewarn "No soundcard present, skipping mixer settings therefore."
+    eend 0
+    return
+  fi
+
+  for card in $(cat /proc/asound/cards| grep -e '^\s*[0-9]' | awk '{print $1}') ; do
+    einfo "Configuring soundcard \"$(awk -F\[ '/^ *'$card' \[/{ FS=" "; $0=$2; print $1}' < /proc/asound/cards)\""
+    eindent
+
+    if checkbootparam 'vol' ; then
+      VOL="$(getbootparam 'vol' 2>>$DEBUG)"
+      if [ -z "$VOL" ] ; then
+        eerror "Bootoption vol found but no volume level/parameter given. Using defaults (75%)."
+        VOL='75'
+        eend 1
       fi
+    else
+      VOL='75'
+    fi
 
-      for card in $(cat /proc/asound/cards| grep -e '^\s*[0-9]' | awk '{print $1}') ; do
-         einfo "Configuring soundcard \"$(awk -F\[ '/^ *'$card' \[/{ FS=" "; $0=$2; print $1}' < /proc/asound/cards)\""
-         eindent
+    if checkbootparam 'nosound' ; then
+      einfo "Muting sound devices on request."
+      ERROR=$(amixer -q set Master mute)
+      RC=$?
+      if [ -n "$ERROR" ] ; then
+        eindent
+        eerror "Problem muting sound devices: $ERROR"
+        eoutdent
+      fi
+      eend $RC
+    elif [ -z "$INSTALLED" ] ; then
+      einfo "Setting mixer volumes to level ${WHITE}${VOL}${NORMAL}."
 
-         if checkbootparam 'vol' ; then
-            VOL="$(getbootparam 'vol' 2>>$DEBUG)"
-            if [ -z "$VOL" ] ; then
-               eerror "Bootoption vol found but no volume level/parameter given. Using defaults (75%)."
-               VOL='75'
-               eend 1
-            fi
-         else
-            VOL='75'
-         fi
-
-         if checkbootparam 'nosound' ; then
-            einfo "Muting sound devices on request."
-            ERROR=$(amixer -q set Master mute)
-            RC=$?
-            if [ -n "$ERROR" ] ; then
-               eindent
-               eerror "Problem muting sound devices: $ERROR"
-               eoutdent
-            fi
-            eend $RC
-         elif [ -z "$INSTALLED" ] ; then
-            einfo "Setting mixer volumes to level ${WHITE}${VOL}${NORMAL}."
+      if checkbootparam 'micvol' ; then
+        MICVOL="$(getbootparam 'micvol' 2>>$DEBUG)"
+        einfo "Setting microphone to ${WHITE}${MICVOL}${NORMAL}."
+      else
+        MICVOL=0
+      fi
 
-            if checkbootparam 'micvol' ; then
-               MICVOL="$(getbootparam 'micvol' 2>>$DEBUG)"
-               einfo "Setting microphone to ${WHITE}${MICVOL}${NORMAL}."
-            else
-               MICVOL=0
-            fi
+      CONTROLS=$(amixer -c $card scontrols | awk -F"Simple mixer control " '{print $2}')
+      IFSOLD=${IFS:-}
+      IFS=$'\n'
+      for CONTROL in ${=CONTROLS} ; do
+        # such devices can not be controlled with amixer ... unmute
+        [[ "$CONTROL" == *Console* ]] && continue
 
-            CONTROLS=$(amixer -c $card scontrols | awk -F"Simple mixer control " '{print $2}')
-            IFSOLD=${IFS:-}
-            IFS='
-'
-            for CONTROL in ${=CONTROLS} ; do
-               # such devices can not be controlled with amixer ... unmute
-               [[ "$CONTROL" == *Console* ]] && continue
-
-               if ! echo "${CONTROL}" | grep -q -i "mic" ; then
-                   if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*pswitch' ; then
-                      amixer -c $card -q set "${CONTROL}" unmute
-                   fi
-                   if amixer -c $card sget "${CONTROL}" | grep -q -P 'Capabilities:.*(pvolume| volume)' ; then
-                      amixer -c $card -q set "${CONTROL}" "${VOL}"%
-                   fi
-               fi
+        if ! echo "${CONTROL}" | grep -q -i "mic" ; then
+          if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*pswitch' ; then
+            amixer -c $card -q set "${CONTROL}" unmute
+          fi
+          if amixer -c $card sget "${CONTROL}" | grep -q -P 'Capabilities:.*(pvolume| volume)' ; then
+            amixer -c $card -q set "${CONTROL}" "${VOL}"%
+          fi
+        fi
 
-               if [ ${MICVOL} -ne 0 ] ; then
-                  if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*cswitch' ; then
-                     amixer -c $card -q set "${CONTROL}" unmute
-                  fi
-                  if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*cvolume' ; then
-                     amixer -c $card -q set "${CONTROL}" $MICVOL%
-                  fi
-                  eend $?
-               fi
-            done
-            IFS=$IFSOLD
-         fi # checkbootparam 'nosound'
-         eoutdent
+        if [ ${MICVOL} -ne 0 ] ; then
+          if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*cswitch' ; then
+            amixer -c $card -q set "${CONTROL}" unmute
+          fi
+          if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*cvolume' ; then
+            amixer -c $card -q set "${CONTROL}" $MICVOL%
+          fi
+          eend $?
+        fi
       done
-   fi
+      IFS=$IFSOLD
+    fi # checkbootparam 'nosound'
+    eoutdent
+  done
 }
 # }}}
 
@@ -1218,7 +1178,7 @@ config_syslog(){
     ewarn "Not starting syslog daemon as requested on boot commandline." ; eend 0
  else
     einfo "Starting rsyslog in background."
-    service_wrapper rsyslog start >>$DEBUG &
+    service_wrapper rsyslog start >>$DEBUG
     eend 0
  fi
 }
@@ -1233,8 +1193,7 @@ config_gpm(){
       eerror "No mouse found - not starting GPM." ; eend 1
     else
       einfo "Starting gpm in background."
-      service_wrapper gpm start >>$DEBUG &
-      # ( while [ ! -e /dev/psaux ]; do sleep 5; done; /etc/init.d/gpm start >>$DEBUG ) &
+      service_wrapper gpm start background >>$DEBUG
       eend 0
     fi
   fi
@@ -1255,7 +1214,7 @@ config_services(){
         service_wrapper "${service}" start >>$DEBUG
       else
         einfo "Starting service ${service} in background."
-        service_wrapper "${service}" start >>$DEBUG &
+        service_wrapper "${service}" start background >>$DEBUG
       fi
     done
     eend $?
@@ -1326,42 +1285,9 @@ config_netscript() {
 }
 # }}}
 
-# {{{ stats
-config_stats() {
- if ! checkbootparam 'nostats' ; then
-   BASE_URL="http://stats.grml.org/report/"
-   ACTION_NAME=Boot
-
-   HOST_ID=$(cat /proc/sys/kernel/random/boot_id)
-
-   grep -q " lm " /proc/cpuinfo && HAS_64BIT="1" || HAS_64BIT="0"
-   DATE_STRING=$(date +'h=%H&m=%M&s=%S')
-   [ -e /etc/grml_version ] && VERSION=$(cat /etc/grml_version) || \
-     VERSION=$(lsb_release -d | awk -F: '{gsub(/^[ \t]+/, "", $2); print $2}')
-
-   PARAMS="$( echo "$CMDLINE" | sed -e 's/=[^ ]*/=x/g' | tr " " "\n"|sort|tr "\n" " " )"
-
-   echo "$CMDLINE" | grep -q -e "fetch" -e "nfsroot" && BOOT="remote"
-   [ -z "$BOOT" ] && BOOT="local"
-
-   ADDITIONAL_PARAMS=""
-   ( [ -n "$COLUMNS" ] && [ -n "$LINES" ] ) && \
-     ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS&res=$((COLUMNS * 8))x$((LINES * 16))"
-
-   URI='$BASE_URL?action=${ACTION_NAME}\&$DATE_STRING\&unique_id=${HOST_ID}\&support_64bit=$HAS_64BIT\&version=$VERSION\&bootup=$BOOT\&params=$PARAMS$ADDITIONAL_PARAMS'
-
-   get_remote_file "$URI" "/dev/null"  >/dev/null 2>&1 &!
- fi
-}
-# }}}
-
 # {{{ start X window system via grml-x
 config_x_startup(){
 
-  if $SYSTEMD ; then
-    ewarn "The startx boot option isn't yet supported via systemd, sorry." ; eend 0
-    return
-  fi
 
 # make sure we start X only if startx is used *before* a nostartx option
 # so it's possible to disable automatic X startup using nostart
@@ -1376,17 +1302,25 @@ if checkbootparam 'startx' && ! echo "$CMDLINE" | grep -q 'startx.*nostartx' ; t
    fi
    einfo "Setting up and invoking grml-x ${WINDOWMANAGER}. Just exit X windows system to get full featured consoles."
    config_userlocal
- cat>|/etc/init.d/xstartup<<EOF
+   if $SYSTEMD ; then
+     if [ -n "$WINDOWMANAGER" ] ; then
+       mkdir -p /var/run/grml-x/
+       echo "$WINDOWMANAGER" > /var/run/grml-x/window-manager
+     fi
+     chvt 7
+     return
+   fi
+   cat>|/etc/init.d/startx<<EOF
 #!/bin/sh
-su $localuser -c "/usr/bin/grml-x ${WINDOWMANAGER}"
+su "${localuser}" -c "/usr/bin/grml-x ${WINDOWMANAGER}"
 EOF
-   chmod 755 /etc/init.d/xstartup
+   chmod 755 /etc/init.d/startx
 
-   # adjust inittab for xstartup
+   # adjust inittab for startx
    if grep -q '^6:' /etc/inittab ; then
-      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
+      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
    else # just append tty6 to inittab if no definition is present:
-      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
+      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
    fi
 
    /sbin/telinit q ; eend $?
@@ -1645,7 +1579,7 @@ config_swraid(){
        if ! checkbootparam 'swraid' ; then
           eindent
           if $SYSTEMD ; then
-            einfo "Just run 'Start mdmonitor' to assemble md arrays or boot using 'swraid' as bootoption for autostart."
+            einfo "Just run 'mdadm --assemble --scan' to assemble md arrays or boot using 'swraid' as bootoption for autostart."
           else
             einfo "Just run 'Start mdadm-raid' to assemble md arrays or boot using 'swraid' as bootoption for autostart."
           fi
@@ -1654,9 +1588,8 @@ config_swraid(){
           einfo "Bootoption swraid found. Searching for software RAID arrays:"
           eindent
            IFSOLD=${IFS:-}
-           IFS='
-'
-           for line in $(mdadm --assemble --scan --auto=yes --symlink=no 2>&1) ; do
+           IFS=$'\n'
+           for line in $(mdadm --assemble --scan 2>&1) ; do
                case $line in
                  *'No arrays found'*)
                    ewarn "$line" ; eend 0
@@ -1676,8 +1609,7 @@ config_swraid(){
                ewarn "No active arrays found" ; eend 0
             else
                IFSOLD=${IFS:-}
-               IFS='
-'
+               IFS=$'\n'
                for line in $(grep '^md[0-9]' /proc/mdstat) ; do
                    einfo "active arrays: $line" ; eend 0
                done
@@ -1711,8 +1643,7 @@ config_dmraid(){
     [ -n "$1" ] || return 1
 
     IFSOLD=${IFS:-}
-    IFS='
-'
+    IFS=$'\n'
     eindent
 
     for line in $(dmraid $1 ; echo errcode:$?); do
@@ -1776,16 +1707,24 @@ config_lvm(){
           einfo "You seem to have logical volumes (LVM) on your system."
           eindent
           if $SYSTEMD ; then
-            einfo "Just run 'Start lvm2-lvmetad' to activate them or boot using 'lvm' as bootoption for autostart."
+            einfo "Just run 'Start lvm2-pvscan@name' to activate LV or VG 'name' or boot using 'lvm' as bootoption for autostart."
           else
             einfo "Just run 'Start lvm2' to activate them or boot using 'lvm' as bootoption for autostart."
           fi
           eend 0
           if checkbootparam 'lvm' ; then
-             einfo "Bootoption LVM found. Searching for logical volumes:"
              if $SYSTEMD ; then
-               service_wrapper lvm2-lvmetad start ; eend $?
+               einfo "Bootoption LVM found, enabling related services."
+               if [ -r /etc/init.d/lvm2-lvmetad ] ; then
+                 service_wrapper lvm2-lvmetad start ; eend $?
+               fi
+               if [ -r /etc/init.d/lvm2-lvmpolld ] ; then
+                 service_wrapper lvm2-lvmpolld start ; eend $?
+               fi
+               einfo "Searching for logical volumes and enabling them:"
+               vgchange -ay ; eend $?
              else
+               einfo "Bootoption LVM found. Searching for logical volumes and enabling them:"
                service_wrapper lvm2 start ; eend $?
              fi
           fi
@@ -1943,7 +1882,7 @@ if $VIRTUALBOX ; then
         vbautomation="$(getbootparam 'vbautomation' 2>>$DEBUG)"
       fi
 
-      if ! VBoxControl sharedfolder list | egrep -q "^[0-9]+ - ${vbautomation}$" ; then
+      if ! VBoxControl sharedfolder list | egrep -q "^[0-9]+ - ${vbautomation}(\s+|$)" ; then
         ewarn "No automount shared folder '$vbautomation' available"
         eend 0
       else
@@ -2003,7 +1942,6 @@ config_distri(){
 if checkbootparam 'distri'; then
   DISTRI="$(getbootparam 'distri' 2>>$DEBUG)"
   if [ -r "${LIVECD_PATH}"/desktop/"$DISTRI".jpg ] ; then
-     [ -n "$BOOTDEBUG" ] && einfo "Debug: bootoption distri found and file ${LIVECD_PATH}/desktop/${DISTRI} present" && eend 0
      # make sure the desktop.jpg file is not a symlink, so copying does not file then
      [ -L /usr/share/grml/desktop.jpg ] && rm /usr/share/grml/desktop.jpg
      cp "${LIVECD_PATH}"/desktop/"$DISTRI".jpg /usr/share/grml/desktop.jpg