Added support for grub2 and parted
Kyle Sheumaker [Fri, 9 Dec 2011 00:42:42 +0000 (18:42 -0600)]
etc/cloner/installer.sh
etc/cloner/prep_disks.sh

index 373acac..d9b898e 100755 (executable)
@@ -162,6 +162,12 @@ do
                elif  [ -x /cloner/mnt/usr/sbin/grub-install ]
                then
                        GRUB_PATH="/usr/sbin/grub-install"
+                elif [ -x /cloner/mnt/sbin/grub2-install ]
+                then
+                        GRUB_PATH="/sbin/grub2-install"
+                elif  [ -x /cloner/mnt/usr/sbin/grub2-install ]
+                then
+                        GRUB_PATH="/usr/sbin/grub2-install"
                else
                        fatal_error "Can't find the grub-install binary on mounted filesystem, no bootloader installed"
                fi
index 75fd721..e7a8438 100755 (executable)
@@ -66,9 +66,151 @@ then
                        ok_msg
                fi
        done
+
+       for i in `ls -1 /cloner/setup/*.parted 2> /dev/null`
+       do
+
+               count=0
+               while read line
+               do
+                       if [ "${count}" == "0" ]
+                       then
+                               echo -n ""              
+                       # this is the disk label info
+                       elif [ "${count}" == "1" ]
+                       then
+                               PED_DEV_NAME=`echo $line | cut -d":" -f1`
+                               PED_DEV_END=`echo $line | cut -d":" -f2`
+                               PED_DEV_TRANS=`echo $line | cut -d":" -f3`
+                               PED_DEV_SECTOR=`echo $line | cut -d":" -f4`
+                               PED_DEV_PHYS=`echo $line | cut -d":" -f5`
+                               PED_DEV_LABEL=`echo $line | cut -d":" -f6`
+                               PED_DEV_MODEL=`echo $line | cut -d":" -f7`
+               
+                               msg -n "Creating ${ANSI_BLUE}${PED_DEV_LABEL}${ANSI_DONE} label on $PED_DEV_NAME"
+                               CMD="mklabel $PED_DEV_LABEL"
+                               /usr/sbin/parted -s $PED_DEV_NAME $CMD
+               
+                               if [ "$?" != 0 ]
+                               then
+                                       fail_msg
+                                       fatal_error "Failed to create disk label"
+                               else
+                                       ok_msg
+                               fi
+
+               
+                       # this is the partition
+                       else
+                               PED_PART_NUM=`echo $line | cut -d":" -f1`
+                               PED_PART_START=`echo $line | cut -d":" -f2`
+                               PED_PART_END=`echo $line | cut -d":" -f3`
+                               PED_PART_LENGTH=`echo $line | cut -d":" -f4`
+                               PED_PART_FSTYPE=`echo $line | cut -d":" -f5`
+                               PED_PART_NAME=`echo $line | cut -d":" -f6`
+                               PED_PART_FLAGS=`echo $line | cut -d":" -f7`
+                               PED_PART_FLAGS=`echo $PED_PART_FLAGS | sed s/\;//g`
+                               PED_PART_FLAGS=`echo $PED_PART_FLAGS | sed s/\,//g`
+               
+                               if [ "${PED_DEV_LABEL}" == "msdos" ]
+                               then
+               
+                                       PED_PART_TYPE="primary"
+                                       if [ "${PED_PART_FLAGS}" == "lba" ]
+                                       then
+                                               PED_PART_TYPE="extended"
+                                       elif [ "${PED_PART_NUM}" -gt "4" ]
+                                       then
+                                               PED_PART_TYPE="logical"
+                                       fi
+               
+                                       msg -n "Creating partition ${ANSI_BLUE}${PED_PART_START} - ${PED_PART_END}${ANSI_DONE} on $PED_DEV_NAME"
+                                       CMD="mkpart $PED_PART_TYPE $PED_PART_FSTYPE $PED_PART_START $PED_PART_END"
+                                       /usr/sbin/parted -s $PED_DEV_NAME $CMD
+       
+                                       if [ "$?" != 0 ]
+                                       then
+                                               fail_msg
+                                               fatal_error "Failed to create disk partition"
+                                       else
+                                               ok_msg
+                                       fi
+
+                               elif [ "${PED_DEV_LABEL}" == "gpt" ]
+                               then
+                                       msg -n "Creating partition ${ANSI_BLUE}${PED_PART_START} - ${PED_PART_END}${ANSI_DONE} on $PED_DEV_NAME"
+                                       CMD="mkpart $PED_PART_FSTYPE $PED_PART_START $PED_PART_END"
+                                       /usr/sbin/parted -s $PED_DEV_NAME $CMD
+                                       if [ "$?" != 0 ]
+                                       then
+                                               fail_msg
+                                               fatal_error "Failed to create disk partition"
+                                       else
+                                               ok_msg
+                                       fi
+               
+                               fi
+                               if [ "${PED_PART_FLAGS}" != "" ]
+                               then
+                                       for flag in ${PED_PART_FLAGS}
+                                       do
+                                               msg -n "Setting flag ${ANSI_BLUE}${flag}${ANSI_DONE} on $PED_PART_NUM"
+                                               CMD="set $PED_PART_NUM $flag on"
+                                               /usr/sbin/parted -s $PED_DEV_NAME $CMD
+
+                                               if [ "$?" != 0 ]
+                                               then
+                                                       fail_msg
+                                                       fatal_error "Failed to create disk partition"
+                                               else
+                                                       ok_msg
+                                               fi
+                                       done
+                               fi
+               
+                       fi
+               
+                       count=`expr ${count} + 1`
+               done < $i
+       done
 fi
        
-if [ -e /cloner/setup/raidconf ]
+if [ -e /cloner/setup/raidconf2 ]
+then
+       header "Setting up software RAID devices"
+
+       while read line
+       do
+               MD_DEVICE=`echo $line | awk '{print $1}'`
+               MD_LEVEL=`echo $line | awk '{print $2}'`
+               MD_METADATA=`echo $line | awk '{print $3}'`
+               MD_DISK_QTY=`echo $line | awk '{print $4}'`
+               MD_SPARE_QTY=`echo $line | awk '{print $5}'`
+               MD_DISKS=`echo $line | awk '{print $6}'`
+               MD_SPARES=`echo $line | awk '{print $7}'`
+
+               T1=`echo $MD_DISKS | sed 's/,/ /g'`
+               T2=`echo $MD_SPARES | sed 's/,/ /g'`
+               MD_DISK_STRING="${T1} ${T2}"
+               
+
+               msg -n "Creating ${ANSI_BLUE}${MD_DEVICE}${ANSI_DONE} - $MD_LEVEL on $MD_DISK_QTY disk(s)"
+               if [ ${MD_LEVEL} == "raid0" ];
+               then
+                       /usr/bin/mdadm --create ${MD_DEVICE} --metadata=${MD_METADATA} --force --run --level=${MD_LEVEL} --chunk=128 --raid-devices=${MD_DISK_QTY} ${MD_DISK_STRING} >> /tmp/stdout.log 2>> /tmp/stderr.log
+               else
+                       /usr/bin/mdadm --create ${MD_DEVICE} --metadata=${MD_METADATA} --force --run --level=${MD_LEVEL} --chunk=128 --raid-devices=${MD_DISK_QTY} --spare-devices=${MD_SPARE_QTY} ${MD_DISK_STRING} >> /tmp/stdout.log 2>> /tmp/stderr.log
+               fi
+
+               if [ "$?" != "0" ];
+               then
+                       fail_msg
+                       fatal_error "Failed to create RAID device ${MD_DEVICE}"
+               else
+                       ok_msg
+               fi
+       done < /cloner/setup/raidconf2
+elif [ -e /cloner/setup/raidconf ]
 then
        header "Setting up software RAID devices"
 
@@ -89,9 +231,9 @@ then
                msg -n "Creating ${ANSI_BLUE}${MD_DEVICE}${ANSI_DONE} - $MD_LEVEL on $MD_DISK_QTY disk(s)"
                if [ ${MD_LEVEL} == "raid0" ];
                then
-                       /usr/bin/mdadm --create ${MD_DEVICE} --force --run --level=${MD_LEVEL} --chunk=128 --raid-devices=${MD_DISK_QTY} ${MD_DISK_STRING} >> /tmp/stdout.log 2>> /tmp/stderr.log
+                       /usr/bin/mdadm --create ${MD_DEVICE} -e 0.90 --force --run --level=${MD_LEVEL} --chunk=128 --raid-devices=${MD_DISK_QTY} ${MD_DISK_STRING} >> /tmp/stdout.log 2>> /tmp/stderr.log
                else
-                       /usr/bin/mdadm --create ${MD_DEVICE} --force --run --level=${MD_LEVEL} --chunk=128 --raid-devices=${MD_DISK_QTY} --spare-devices=${MD_SPARE_QTY} ${MD_DISK_STRING} >> /tmp/stdout.log 2>> /tmp/stderr.log
+                       /usr/bin/mdadm --create ${MD_DEVICE} -e 0.90 --force --run --level=${MD_LEVEL} --chunk=128 --raid-devices=${MD_DISK_QTY} --spare-devices=${MD_SPARE_QTY} ${MD_DISK_STRING} >> /tmp/stdout.log 2>> /tmp/stderr.log
                fi
 
                if [ "$?" != "0" ];