[Rear-users] SF.net SVN: rear:[670] trunk/usr/share/rear/layout/prepare/default/ 40_autoresize_disks.sh

jhoekx at users.sourceforge.net jhoekx at users.sourceforge.net
Fri Jul 8 12:13:18 CEST 2011


Revision: 670
          http://rear.svn.sourceforge.net/rear/?rev=670&view=rev
Author:   jhoekx
Date:     2011-07-08 10:13:17 +0000 (Fri, 08 Jul 2011)

Log Message:
-----------
layout: improve disk resizing.

Now it's also useful for reducing disk sizes on disks with more than one resizeable partition.

Modified Paths:
--------------
    trunk/usr/share/rear/layout/prepare/default/40_autoresize_disks.sh

Modified: trunk/usr/share/rear/layout/prepare/default/40_autoresize_disks.sh
===================================================================
--- trunk/usr/share/rear/layout/prepare/default/40_autoresize_disks.sh	2011-07-07 16:38:07 UTC (rev 669)
+++ trunk/usr/share/rear/layout/prepare/default/40_autoresize_disks.sh	2011-07-08 10:13:17 UTC (rev 670)
@@ -23,13 +23,18 @@
 
         let oldsize=$size
 
+        let difference=$newsize-$oldsize # can be negative!
+        Log "Total resize of ${difference}B"
+
         Log "Searching for resizeable partitions on disk $device ($newsize)B"
 
         # Find partitions that could be resized
         partitions=()
+        resizeable_size=0
         while read type part size start name flags name junk; do
             if [ "${flags/lvm/j}" != "${flags}" ] || [ "${flags/raid/j}" != "$flags" ] ; then
                 partitions=( "${partitions[@]}" "$name|${size%B}" )
+                let resizeable_size=$resizeable_size+${size%B}
                 Log "Will resize partition $name."
             fi
         done < <(grep "^part $device" $LAYOUT_FILE)
@@ -39,18 +44,20 @@
             continue
         fi
 
+        if [ $resizeable_size -eq 0 ] || [ $resizeable_size -lt $difference ] ; then
+            LogPrint "No space to automatically resize partitions on disk $device."
+            continue
+        fi
+
         # evenly distribute the size changes
-        let difference=$newsize-$oldsize
-        let delta=$difference/${#partitions[@]} # can be negative!
-        Log "Total resize of ${difference}B (${delta}x${#partitions[@]})"
-
         for data in "${partitions[@]}" ; do
             name=${data%|*}
             current_size=${data#*|}
 
+            delta=$(echo "$current_size $resizeable_size $difference" | awk '{ printf "%d", ($1/$2)*$3; }')
+            let new_size=current_size+delta
+
             nr=$(echo "$name" | sed -r 's/.+([0-9])$/\1/')
-
-            let new_size=$current_size+$delta
             sed -r -i "s|^(part $device) ${current_size}(.+)$nr$|\1 ${new_size}\2$nr|" $LAYOUT_FILE.tmp
             Log "Resized partition $name from ${current_size}B to ${new_size}B."
         done


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rear-users mailing list