diff options
Diffstat (limited to 'scripts/install/install-get-partition')
-rwxr-xr-x | scripts/install/install-get-partition | 209 |
1 files changed, 78 insertions, 131 deletions
diff --git a/scripts/install/install-get-partition b/scripts/install/install-get-partition index 1a96ac81..32487379 100755 --- a/scripts/install/install-get-partition +++ b/scripts/install/install-get-partition @@ -49,7 +49,9 @@ warn_of_dire_consequences () { done } -check_for_old_raid () { +delete_old_raid () { + ldrive=$1 + # First, trigger construction of previously configured RAID groups echo -n "Looking for pre-existing RAID groups..." raid_config=`mdadm --examine --scan` @@ -66,132 +68,37 @@ check_for_old_raid () { raid_drives=$(cat /proc/partitions | awk '{ if ($4!="name") { print $4 } }' \ | grep "md" | egrep -v "^$") if [ -z "$raid_drives" ]; then - echo "Unable to configure any RAID groups." return fi - numraids=`echo $raid_drives | wc -w` - if [ $numraids -eq 1 ]; then - echo "The following RAID group is now configured:" - else - echo "The following RAID groups are now configured:" - fi - for drive in $raid_drives; do - cat /proc/mdstat | grep --after-context 2 ^$drive | sed -e 's/^/\t/' + members=`ls /sys/block/$drive/slaves` + for member in $members; do + cdrive=`lsblk -dn -o pkname /dev/$member` + if [ "$ldrive" == "$cdrive" ]; then + mdadm --stop --scan + for member in $members; do + drive=${member:0:3} + part=${member:3:1} + echo "Re-setting partition ID for RAID group $raid_drive member /dev/${member}:" + if [ -d /sys/firmware/efi ]; then + sgdisk --part-type /dev/$drive $part 0x83 + else + sfdisk --part-type /dev/$drive $part 0x83 + fi + echo "Clearing RAID superblock from RAID group $raid_drive member /dev/${member}." + mdadm --zero-superblock /dev/$member + done + fi + done done - - if [ $numraids -eq 1 ]; then - echo -n "Would you like to use this one? (Yes/No) [Yes]:" - else - echo -n "Would you like to use one of these? (Yes/No) [Yes]:" - fi - - response=$(get_response "Yes" "Yes No Y N") - if [ "$response" == "no" ] || [ "$response" == "n" ]; then - echo - echo "Ok. Not using existing RAID groups." - echo - - # pick the first RAID group to be broken - raid_drive=$(echo $raid_drives | /usr/bin/awk '{ print $1 }') - - echo "Would you like to break RAID group $raid_drive so that its" - echo "members can be re-used for a new installation, understanding" - echo -n "that doing so will destroy all data on it? (Yes/No) [No]:" - destroy_raid=$(get_response "No" "Yes No Y N") - echo - - if [ "${destroy_raid:0:1}" = "y" ]; then - echo "OK. Breaking the RAID group $raid_drive." - - members=`ls /sys/block/$raid_drive/slaves` - - echo "First, stopping all existing RAID groups:" - mdadm --stop --scan - - for member in $members ; do - drive=${member:0:3} - part=${member:3:1} - echo "Re-setting partition ID for RAID group $raid_drive member /dev/${member}:" - sfdisk --change-id /dev/$drive $part 0x83 - echo "Clearing RAID superblock from RAID group $raid_drive member /dev/${member}." - mdadm --zero-superblock /dev/$member - done - else - echo "OK. Stopping, but not breaking, existing RAID groups:" - mdadm --stop --scan - fi - - echo - return - fi - - if [ $numraids -eq 1 ]; then - INSTALL_DRIVE=$raid_drives - else - # take the first drive as the default - INSTALL_DRIVE=$(echo $raid_drives | /usr/bin/awk '{ print $1 }') - echo -n "Which one would you like to use? ($raid_drives) [$INSTALL_DRIVE]: " - INSTALL_DRIVE=$(get_response "$INSTALL_DRIVE" "$drives") - fi - - echo "Using RAID partition $INSTALL_DRIVE" - - raid_degraded=`cat /sys/block/$INSTALL_DRIVE/md/degraded` - raid_sync_action=`cat /sys/block/$INSTALL_DRIVE/md/sync_action` - - if [ "$raid_degraded" = "1" ]; then - echo - if [ "$raid_sync_action" = "recover" ]; then - echo "Error: This RAID set is degraded and is in the process of" - echo "rebuilding. It is not safe to install onto it while the" - echo "rebuild is in progress. Please wait for the rebuild to" - echo "complete and then re-start the installation. You may" - echo "monitor the progress of the RAID rebuild with the" - echo "command:" - echo - echo " show raid $INSTALL_DRIVE" - echo - exit 1 - fi - echo "Warning: This RAID set is degraded, but is not in the" - echo "process of rebuilding. It is safe to perform the installation" - echo "onto a degraded RAID set that is not in the process of" - echo "rebuilding. You may stop the installation now and rebuild the" - echo "RAID set, or continue installing onto it. If you continue" - echo "installing, do not attempt to rebuild the RAID set until the" - echo "installation has completed and you have rebooted the system." - echo - fi - - warn_of_dire_consequences - - ROOT_PARTITION=$INSTALL_DRIVE - ROOT_PARTITION_TYPE=new - - # make sure we aren't working on a mounted part - unmount "$INSTALL_DRIVE" - - # check for an old config on the partition - mkdir -p /mnt/tmp - output=$(mount -r /dev/"$ROOT_PARTITION" /mnt/tmp 2>&1) - if [ $? != 0 ]; then - echo "Cannot mount $ROOT_PARTITION to check for old config file" - lecho "Cannot mount $ROOT_PARTITION"."\n" - lecho "mount $ROOT_PARTITION /mnt/tmp\n" - lecho "$output" - else - save_old_info "$ROOT_PARTITION" - umount /mnt/tmp - fi - - # create the filesystem on the part - make_filesystem "$ROOT_PARTITION" } check_for_new_raid () { # Identify physical drives + driveName=() + driveSize=() + driveNameSize=() drives=$(cat /proc/partitions | awk '{ if ($4!="name") { print $4 } }' \ | egrep -v "[0-9]$" | egrep -v "^$") @@ -200,17 +107,63 @@ check_for_new_raid () { if mount | grep iso9660 | grep -q $instdrv then drives=${drives//"$instdrv"/} + else + driveName+=("$instdrv") + driveSize+=($(get_drive_size $instdrv)) + driveNameSize+=("$instdrv $(get_drive_size $instdrv) MB") fi done numdrives=`echo $drives | wc -w` - # Need at least two drives for RAID-1. We don't yet have the code - # to handle selection of two from a set of 3 or more, so for now, we - # only support two drives. - # - if [ $numdrives -ne 2 ]; then + # Need at least two drives for RAID-1. If there are more than two + # drives found we have the option to check for two drives of the same size + # or configure manually. + + if [ $numdrives -lt 2 ]; then return + elif [ $numdrives -gt 2 ]; then + echo "Found ${numdrives} drives." + echo -n "Would you like to configure RAID-1 mirroring? (Yes/No) [Yes]:" + response=$(get_response "Yes" "Yes No Y N") + if [ "$response" == "no" ] || [ "$response" == "n" ]; then + echo "Ok. Not configuring RAID-1." + return + else + echo -n "Would you like find and use 2 drives of the same size? (Yes/No) [Yes]:" + response=$(get_response "Yes" "Yes No Y N") + if [ "$response" == "yes" ] || [ "$response" == "y" ]; then + raiddrives=$(get_size_raid) + if [ -n "$raiddrives" ]; then + drives=$raiddrives + else + echo "No drives with the same size found." + echo -n "Would you like to manually select the drives? (Yes/No) [Yes]:" + response=$(get_response "Yes" "Yes No Y N") + if [ "$response" == "yes" ] || [ "$response" == "y" ]; then + raiddrives=$(get_manual_raid) + if [ -n "$raiddrives" ]; then + drives=$raiddrives + fi + else + echo "Ok. Not configuring RAID-1." + return + fi + fi + else + echo -n "Would you like to manually select the drives? (Yes/No) [Yes]:" + response=$(get_response "Yes" "Yes No Y N") + if [ "$response" == "yes" ] || [ "$response" == "y" ]; then + raiddrives=$(get_manual_raid) + if [ -n "$raiddrives" ]; then + drives=$raiddrives + fi + else + echo "Ok. Not configuring RAID-1." + return + fi + fi + fi fi drive1=`echo $drives | awk '{ print $1 }'` @@ -606,6 +559,8 @@ save_old_info() { delete_partitions () { ldrive=$1 + delete_old_raid $ldrive + # get the partitions on the drive # in the first grep below we add the optional [p] in order to # accomdate cciss drives @@ -950,13 +905,6 @@ while true; do progress_indicator stop echo "OK" - # try old raid - check_for_old_raid - if [ -n "$ROOT_PARTITION" ]; then - # got partition. done. - break - fi - # try new raid check_for_new_raid if [ -n "$ROOT_PARTITION" ]; then @@ -1005,4 +953,3 @@ fi echo "$ROOT_PARTITION_TYPE $ROOT_PARTITION $INSTALL_DRIVE" >$OUTFILE becho 'Done!' exit 0 - |