diff options
author | Lucas Affonso Xavier de Morais | 2014-08-12 17:13:54 +0200 |
---|---|---|
committer | Michael Pereira Neves | 2014-10-28 14:14:49 +0100 |
commit | 5578edcf252f2e70aa1e143a171e2ed646133878 (patch) | |
tree | 5239335b933729699e28e6fed92e66d0810f8656 | |
parent | [partitioner] fixing the fetch of existent GPT partitions. (diff) | |
download | tm-scripts-5578edcf252f2e70aa1e143a171e2ed646133878.tar.gz tm-scripts-5578edcf252f2e70aa1e143a171e2ed646133878.tar.xz tm-scripts-5578edcf252f2e70aa1e143a171e2ed646133878.zip |
[partitioner] existent partitions detection working for GPT and MSDOS. TODO: Create the nonexistent partitions if there is enough freespace.
-rwxr-xr-x | remote/modules/partitioner/partitioner.sh | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/remote/modules/partitioner/partitioner.sh b/remote/modules/partitioner/partitioner.sh index 5822851a..f2a7dfc3 100755 --- a/remote/modules/partitioner/partitioner.sh +++ b/remote/modules/partitioner/partitioner.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +# set -e PARTITIONSPATH="/proc/partitions" CONFIGPATH="./config" @@ -84,11 +84,13 @@ if [ -n "$SLX_PARTITION_TABLE" ]; then else PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/bootable"]=1 fi - PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/exists?"]=0 + # set the partitions to non-existents + PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/exists"]=0 COUNTER=$(($COUNTER+1)) done + unset IFS fi -unset IFS +# PARTTBL starts at 1 and ends at COUNTER-1 # check if the choosen disk is greater than the new partition table size. DISKSIZE=$(($(cat $PARTITIONSPATH | grep -e $SLX_CHOOSEN_DISK$ | tr -s ' ' | cut -d ' ' -f4)*$BLOCKSIZE)) @@ -174,51 +176,57 @@ if [ $SLX_DELETE_PARTITION_TABLE = "yes" ]; then sfdisk -q -f /dev/$SLX_CHOOSEN_DISK < /tmp/partitiontable.tmp > /dev/null # rm -f /tmp/partitiontable.tmp elif [ $(sfdisk -d /dev/$SLX_CHOOSEN_DISK 2> /dev/null | grep $SLX_CHOOSEN_DISK'1' | tr -s ' ' | cut -d ' ' -f7 | cut -d '=' -f2) = 'ee' ]; then - # finding existent partitions in GPT echo 'GPT' PARTS=$(cat $PARTITIONSPATH | grep -e $SLX_CHOOSEN_DISK[0-9] | tr -s ' ' | cut -d ' ' -f5) # this line fix the empty PARTS error, continue from here - echo $PARTS for PART in $PARTS; do - for (( i = 1; i < $(($COUNTER-1)); i++ )); do + for (( i = 1; i < $COUNTER; i++ )); do + echo "i=$i PART=$PART" if [ $i -ne 4 ]; then - if [ ${PARTTBL["$SLX_CHOOSEN_DISK$i/exists?"]} -ne 1 ]; then - echo "sgdisk /dev/$SLX_CHOOSEN_DISK -i $i | grep \"unique GUID\" | cut -d ' ' -f4 | grep '${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}000000-0000-0000-0000-000000000000'" - sgdisk /dev/$SLX_CHOOSEN_DISK -i $i | grep "unique GUID" | cut -d ' ' -f4 | grep '${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}000000-0000-0000-0000-000000000000' + if [ ${PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]} = 0 ]; then + echo "sgdisk /dev/$SLX_CHOOSEN_DISK -i ${PART:3} | grep '${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}000000-0000-0000-0000-000000000000'" + sgdisk /dev/$SLX_CHOOSEN_DISK -i ${PART:3} | grep ${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}"000000-0000-0000-0000-000000000000" if [ $? -eq 0 ]; then echo "the partition $PART is the ${PARTTBL["$SLX_CHOOSEN_DISK$i/mountpoint"]} partition." - PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/exists?"]=1 - echo 'boa tarde1' + PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]=$PART + break fi fi fi - i=$(($i+1)) done done + # FREESPACE needed here else # finding existent partitions in MS-DOS + echo 'MSDOS' + PARTS=$(cat $PARTITIONSPATH | grep -e $SLX_CHOOSEN_DISK[0-9] | tr -s ' ' | cut -d ' ' -f5) # this line fix the empty PARTS error, continue from here for PART in $PARTS; do - for (( i = 1; i < $(($COUNTER-1)); i++ )); do + for (( i = 1; i < $COUNTER; i++ )); do + echo "i=$i PART=$PART" if [ $i -ne 4 ]; then - [ sfdisk -d /dev/$SLX_CHOOSEN_DISK | grep $PART | tr -s ' ' | cut -d ' ' -f7 | cut -d '=' -f2 = '${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}' ] - if [ $? -eq 0 ]; then - PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/exists?"]=1 - break; + if [ ${PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]} = 0 ]; then + echo "sfdisk -d /dev/$SLX_CHOOSEN_DISK 2> /dev/null | grep $PART | tr -s ' ' | cut -d ' ' -f7 | grep ${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}" + sfdisk -d /dev/$SLX_CHOOSEN_DISK 2> /dev/null | grep $PART | tr -s ' ' | cut -d ' ' -f7 | grep ${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]} + if [ $? -eq 0 ]; then + echo "the partition $PART is the ${PARTTBL["$SLX_CHOOSEN_DISK$i/mountpoint"]} partition." + PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]=$PART + break + fi fi fi - i=$(($i+1)) done done fi DIALOGSTR="New partitions created:\n\n" -echo "SLX_PARTITION_TYPE = "$SLX_PARTITION_TYPE if [ $SLX_PARTITION_TYPE = 'GPT' ]; then - # create the command that will convert the MSDOS type to GPT and change the unique GUIDs + # create the command (CMD) that will convert the MSDOS type to GPT and change the unique GUIDs CMD="sgdisk -g /dev/$SLX_CHOOSEN_DISK" for (( i = 1; i < $COUNTER; i++ )); do if [ $i -ne 4 ]; then - CMD=$CMD" -u "$i":"${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}"000000-0000-0000-0000-000000000000" + if [ ${PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]} = 0 ]; then + CMD=$CMD" -u "$i":"${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}"000000-0000-0000-0000-000000000000" + fi CMD=$CMD" -c "$i":\""${PARTTBL["$SLX_CHOOSEN_DISK$i/mountpoint"]}"\"" fi done |