summaryrefslogtreecommitdiff
path: root/recipes-core/fs-init
diff options
context:
space:
mode:
authorMax Krummenacher <max.krummenacher@toradex.com>2014-03-19 17:28:47 +0100
committerMax Krummenacher <max.krummenacher@toradex.com>2014-04-01 10:11:35 +0200
commit7be9aa2c5df225fdd1e37e61635c9d8b6c4ce415 (patch)
tree165cc81ec1027e8e4c3f5a5eb843211b1ab474e3 /recipes-core/fs-init
parent4855af146958e42b029b0fda44e8938b73589397 (diff)
resizefs.sh: add iMX6 specifics
Diffstat (limited to 'recipes-core/fs-init')
-rwxr-xr-xrecipes-core/fs-init/files/mx6/resizefs.sh53
-rwxr-xr-xrecipes-core/fs-init/files/resizefs.sh9
2 files changed, 58 insertions, 4 deletions
diff --git a/recipes-core/fs-init/files/mx6/resizefs.sh b/recipes-core/fs-init/files/mx6/resizefs.sh
new file mode 100755
index 0000000..8f066d1
--- /dev/null
+++ b/recipes-core/fs-init/files/mx6/resizefs.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+# resize the rootfs ext filesystem size to its full partition size
+# usually used on first boot in a postinstall script
+# or set in an autostart file from a postinstall script
+
+DISK="mmcblk0"
+PART="mmcblk0p2"
+
+logger "resizing $PART to fill its full partition size"
+# get the disk total size
+DISK_SIZE=`cat /sys/block/$DISK/size`
+
+# get partition start and size
+PART_OFF=`cat /sys/block/$DISK/$PART/start`
+PART_SIZE=`cat /sys/block/$DISK/$PART/size`
+
+# calculate size after the partition to the end of disk
+SPARE=`expr $DISK_SIZE - $PART_OFF - $PART_SIZE`
+
+# new filesystem size, it must not overlap the secondary gpt header
+# assume 1024kB as GPT size (is 34 sectors)
+if [ $SPARE -lt 2048 ]
+then
+ FSSIZE=`expr $PART_SIZE - 2048`
+else
+ FSSIZE=$PART_SIZE
+fi
+
+# resize now
+
+#reduce I/O load by doing this in STEPSIZE increments
+#idea stolen from here:
+#https://codereview.chromium.org/551127
+
+#start from the current size in blocks of 512 byte, add STEPSIZE on each iteration
+STEPSIZE=`expr 64 \* 1024 \* 2`
+NEXTSIZE=`df /dev/$PART | grep /dev/root | awk '{print $2}'`
+NEXTSIZE=`expr $NEXTSIZE \* 2`
+NEXTSIZE=`expr $NEXTSIZE + $STEPSIZE`
+while [ $NEXTSIZE -lt $FSSIZE ]; do
+ FSSIZEMEG=`expr $NEXTSIZE / 2 / 1024`"M"
+ resize2fs /dev/$PART $FSSIZEMEG
+ sleep 1
+ NEXTSIZE=`expr $NEXTSIZE + $STEPSIZE`
+done
+FSSIZEMEG=`expr $FSSIZE / 2 / 1024`"M"
+resize2fs /dev/$PART $FSSIZEMEG
+
+#job done, remove it from systemd services
+systemctl disable resizefs.service
+
+logger "resizing $PART finished, new size is $FSSIZEMEG"
+
diff --git a/recipes-core/fs-init/files/resizefs.sh b/recipes-core/fs-init/files/resizefs.sh
index 78addeb..4f38d0b 100755
--- a/recipes-core/fs-init/files/resizefs.sh
+++ b/recipes-core/fs-init/files/resizefs.sh
@@ -28,19 +28,20 @@ fi
# resize now
-#reduce I/O load by doing this in 32M increments
+#reduce I/O load by doing this in STEPSIZE increments
#idea stolen from here:
#https://codereview.chromium.org/551127
-#get the current size in blocks of 512 byte
+#start from the current size in blocks of 512 byte, add STEPSIZE on each iteration
+STEPSIZE=`expr 64 \* 1024 \* 2`
NEXTSIZE=`df /dev/$PART | grep /dev/root | awk '{print $2}'`
NEXTSIZE=`expr $NEXTSIZE \* 2`
-NEXTSIZE=`expr $NEXTSIZE + 32 \* 1024 \* 2`
+NEXTSIZE=`expr $NEXTSIZE + $STEPSIZE`
while [ $NEXTSIZE -lt $FSSIZE ]; do
FSSIZEMEG=`expr $NEXTSIZE / 2 / 1024`"M"
resize2fs /dev/$PART $FSSIZEMEG
sleep 1
- NEXTSIZE=`expr $NEXTSIZE + 32 \* 1024 \* 2`
+ NEXTSIZE=`expr $NEXTSIZE + $STEPSIZE`
done
FSSIZEMEG=`expr $FSSIZE / 2 / 1024`"M"
resize2fs /dev/$PART $FSSIZEMEG