Support LVM
[grml-autoconfig.git] / autoconfig.functions
index 7960772..1707c5f 100755 (executable)
@@ -4,7 +4,7 @@
 # Authors:       grml-team (grml.org), (c) Klaus Knopper <knopper@knopper.net>, (c) Michael Prokop <mika@grml.org>
 # Bug-Reports:   see http://grml.org/bugs/
 # License:       This file is licensed under the GPL v2.
-# Latest change: Mon Apr 16 19:32:25 CEST 2007 [mika]
+# Latest change: Son Jul 01 20:34:14 CEST 2007 [mika]
 ################################################################################
 
 # {{{ path, variables, signals, umask, zsh
@@ -1046,8 +1046,12 @@ if [ -z "$INSTALLED" ] ; then
                      if grep -q $p /proc/swaps ; then
                         ewarn "Not using swap partition ${WHITE}${p}${NORMAL} as it is already in use." ; eend 0
                      else
+                        if [ -b "$p" ] ; then
                         einfo "Using swap partition ${WHITE}${p}${NORMAL}."
                         swapon $p 2>>$DEBUG ; eend $?
+                        else
+                        ewarn "$p is not a valid block device - not using it therefore." ; eend 0
+                        fi
                      fi
                      ;;
              esac # dd-check
@@ -1068,14 +1072,16 @@ if [ -z "$INSTALLED" ] ; then
 
         # use a swapfile
         if [ -z "$NOSWAP" ] ; then
-           mount -o "$MOUNTOPTS" -t $f $p $m 2>>$DEBUG || continue
+           mount -o "$MOUNTOPTS" -t $f $p $m 2>>$DEBUG && MOUNTED=1 || continue
            # Activate swapfile, if exists
            SWAPFILE="$(/bin/ls -1d $m/[Gg][Rr][Mm][Ll].[Ss][Ww][Pp] 2>/dev/null)"
         fi
         if [ -z "$NOSWAP" -a -n "$SWAPFILE" -a -f "$SWAPFILE" ]; then
            mount -o remount,rw $m && MOUNTED=1
            if swapon "$SWAPFILE" 2>>$DEBUG ; then
-              einfo "Using GRML swapfile ${SWAPFILE}."
+              eindent
+                einfo "Using GRML swapfile ${WHITE}${SWAPFILE}${NORMAL}."
+              eoutdent
               fnew="$SWAPFILE swap swap defaults 0 0"
               stringinfile "$fnew" "/etc/fstab" || echo "$fnew" >> /etc/fstab
               GRML_SWP="$GRML_SWP $SWAPFILE"
@@ -2038,6 +2044,33 @@ config_swraid(){
 }
 # }}}
 
+# {{{ LVM (Logical Volumes)
+config_lvm(){
+  if [ -z "$INSTALLED" ] ; then
+  # notice: checkbootparam "forensic" is just for users who don't know how to really use the bootoption
+  if checkbootparam 'nolvm' ; then
+     ewarn "Skipping LVM code as requested on boot commandline." ; eend 0
+  else
+    if ! [ -x /sbin/lvm -a -x /etc/init.d/lvm2 -a -x /sbin/lvdisplay ] ; then
+       eerror "LVM not available, can not execute it." ; eend 1
+    else
+       if lvdisplay 1>/dev/null 2>&1 ; then
+         einfo "You seem to have logical volumes (LVM) on your system."
+          eindent
+          einfo "Just run 'Start lvm2' to activate them or boot using 'lvm' as bootoption for autostart."
+         eend 0
+          if checkbootparam 'lvm' ; then
+             einfo "Bootoption LVM found. Searching for logical volumes:"
+            /etc/init.d/lvm2 start ; eend $?
+         fi
+          eoutdent
+       fi
+    fi # check for lvm binary
+  fi # check for bootoption nolvm
+  fi # run only in live-cd mode
+}
+# }}}
+
 # {{{ debnet: setup network based on an existing one found on a partition
 config_debnet(){
 if checkbootparam "debnet" ; then
@@ -2150,20 +2183,28 @@ config_debootstrap(){
 
 if stringinstring "BOOT_IMAGE=debian2hd " "$CMDLINE" ; then
 
+einfo "Bootoption debian2hd found. Setting up environment for automatic installation via grml-debootstrap." ; eend 0
+
 if ! [ -x /usr/sbin/grml-debootstrap ] ; then
+   eindent
    eerror "Bootoption debian2hd found, but grml-debootstrap is not available." ; eend 1
-   eerror "Dropping you to a shell, just exit it to continue booting." ; eend 1
-   /bin/zsh
+   eoutdent
+   exit 1
 fi
 
-if checkbootparam "partition" ; then
-  PARTITION=''
-  PARTITION="$(getbootparam 'partition' 2>>$DEBUG)"
+if checkbootparam "target" ; then
+  TARGET=''
+  TARGET="$(getbootparam 'target' 2>>$DEBUG)"
   # notice: the following checks whether the given partition is available, if not the skip
   # execution of grml-debootstrap as it might result in data loss...
-  if ! [ -r $PARTITION ] ; then
-     ewarn "Partition $PARTITION does not exist. Skipping execution of grml-debootstrap therefore." ; eend 1
+  if ! [ -r "$TARGET" ] ; then
+     eerror "Target $TARGET does not exist. Skipping execution of grml-debootstrap therefore." ; eend 1
   fi
+else
+  eindent
+  eerror "No bootoption named target found, can not continue execution of grml-debootstrap." ; eend 1
+  eoutdent
+  exit 1
 fi
 
 if checkbootparam "grub" ; then
@@ -2186,34 +2227,44 @@ if checkbootparam "mirror" ; then
   MIRROR="$(getbootparam 'mirror' 2>>$DEBUG)"
 fi
 
+if checkbootparam "boot_append" ; then
+  BOOT_APPEND=''
+  BOOT_APPEND="$(getbootparam 'boot_append' 2>>$DEBUG)"
+fi
+
 if checkbootparam "password" ; then
   PASSWORD=''
   PASSWORD="$(getbootparam 'password' 2>>$DEBUG)"
 fi
 
 # now check which options are available
-if [ -n "PARTITION" ] ; then
-   PARTITIONCMD="--target $PARTITION"
+if [ -n "TARGET" ] ; then
+   TARGETCMD="--target $TARGET"
 else
-   PARTITIONCMD=''
-   ewarn "Partion not set via bootoption. Skipping execution of grml-debootstrap therefore."; eend 1
+   TARGETCMD=''
+   eindent
+   eerror "Target not set via bootoption. Skipping execution of grml-debootstrap therefore."; eend 1
+   eoutdent
+   exit 1
 fi
 [ -n "$GRUB" ]     && GRUBCMD="--grub $GRUB"               || GRUBCMD=''
 [ -n "$GROOT" ]    && GROOTCMD="--groot $GROOT"            || GROOTCMD=''
 [ -n "$RELEASE" ]  && RELEASECMD="--release $RELEASE"      || RELEASECMD=''
 [ -n "$MIRROR" ]   && MIRRORCMD="--mirror $MIRROR"         || MIRRORCMD=''
-[ -n "$PASSWORD" ] && PASSWORDCMD="--password $PASSWORD" ] || PASSWORDCMD=''
+[ -n "$PASSWORD" ] && PASSWORDCMD="--password $PASSWORD"   || PASSWORDCMD=''
+[ -n "$BOOT_APPEND" ] && BOOT_APPEND="--boot_append $BOOT_APPEND" || BOOT_APPEND=''
 
 # and finally write script and execute it
 cat>|/usr/bin/grml-debootstrap_noninteractive<<EOF
 #!/bin/sh
-AUTOINSTALL='yes' grml-debootstrap $PARTITIONCMD $GRUBCMD $GROOTCMD $RELEASECMD $MIRRORCMD $PASSWORDCMD
+AUTOINSTALL='yes' grml-debootstrap $TARGETCMD $GRUBCMD $GROOTCMD $RELEASECMD $MIRRORCMD $PASSWORDCMD $BOOT_APPEND
 EOF
 
 chmod 750  /usr/bin/grml-debootstrap_noninteractive
-einfo "Bootoption debian2hd found. Running automatic installation via grml-debootstrap." && eend 0
 
-screen /usr/bin/grml-debootstrap_noninteractive ; einfo "Invoking a shell, just exit to continue booting..." ; /bin/zsh
+screen /usr/bin/grml-debootstrap_noninteractive
+einfo "Invoking a shell, just exit to continue booting..."
+/bin/zsh
 
 fi # stringinstring "BOOT_IMAGE=debian2hd
 }
@@ -2225,6 +2276,8 @@ if checkbootparam "distri"; then
   DISTRI="$(getbootparam 'distri' 2>>$DEBUG)"
   if [ -r /cdrom/desktop/"$DISTRI".jpg ] ; then
      [ -n "$BOOTDEBUG" ] && einfo "Debug: bootoption distri found and file /cdrom/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 /cdrom/desktop/"$DISTRI".jpg /usr/share/grml/desktop.jpg
   fi
 fi