aboutsummaryrefslogtreecommitdiffstats
path: root/stage2
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-07-09 19:10:16 +0200
committerSven Gothel <[email protected]>2021-07-09 19:10:16 +0200
commit10dfacb2e414bb4067616876a507fdc01b44d143 (patch)
tree05c56f1b02ccef27f1ae18ecbeb68cca42919d0d /stage2
parenta6af9dcfb10e9ea27676912f2301f1111ed5f887 (diff)
stage2's: /etc/init.d/resize2fs_once: Add maximizing rootfs partition size before resize2fs.
The install image's partition has been downsized to match the shrunken rootfs for efficient storage and copy to sdcard. Hence 'resize2fs_once' must also resize the parition to the end of the sdcard, then resize2fs for maximum size.
Diffstat (limited to 'stage2')
-rw-r--r--stage2/01-sys-tweaks/files/resize2fs_once31
1 files changed, 27 insertions, 4 deletions
diff --git a/stage2/01-sys-tweaks/files/resize2fs_once b/stage2/01-sys-tweaks/files/resize2fs_once
index 38a4d47..f1506a6 100644
--- a/stage2/01-sys-tweaks/files/resize2fs_once
+++ b/stage2/01-sys-tweaks/files/resize2fs_once
@@ -12,10 +12,33 @@
case "$1" in
start)
log_daemon_msg "Starting resize2fs_once"
- ROOT_DEV=$(findmnt / -o source -n) &&
- resize2fs $ROOT_DEV &&
- update-rc.d resize2fs_once remove &&
- rm /etc/init.d/resize2fs_once &&
+ ROOT_PART=$(findmnt / -o source -n)
+ ROOT_DEV_BASE=`lsblk -asr ${ROOT_PART} | tail -1 | awk ' { print $1 }'`
+ ROOT_DEV="/dev/${ROOT_DEV_BASE}"
+ # Test ROOT_DEV deduction: (1) substring
+ if [ -n "${ROOT_PART} -a -n "${ROOT_DEV} -a -z "${ROOT_PART##*"${ROOT_DEV}"*}" ]; then
+ PARTED_OUT=`parted -s -m $ROOT_DEV unit B print`
+ PART_NO=`echo "$PARTED_OUT" | grep ext4 | awk -F: ' { print $1 } '`
+ # Test ROOT_DEV deduction: (2) identified partition number
+ if [ "${ROOT_PART}" = "${ROOT_DEV}p${PART_NO}" -o "${ROOT_PART}" = "${ROOT_DEV}${PART_NO}" ]; then
+ PART_END=`echo "${PARTED_OUT}" | grep "^${PART_NO}:" | awk -F: ' { print substr($3,1,length($3)-1) } '`
+ PART_NEW_END=`parted -s -m $ROOT_DEV unit B print free | tail -1 | awk -F: ' { print substr($3,1,length($3)-1) } '`
+ if [ -n "${PART_END}" -a -n "${PART_NEW_END}" -a ${PART_NEW_END} -gt ${PART_END} ]; then
+ echo "Resize partition ${PART_NO} from ${PART_END} to ${PART_NEW_END}"
+ parted -s $ROOT_DEV unit B resizepart ${PART_NO} ${PART_NEW_END}
+ echo "Resize fs on partition ${PART_NO}, ${ROOT_PART}"
+ resize2fs $ROOT_PART
+ else
+ echo "Resize partition 2 requirement failed: End ${PART_END} < new_end ${PART_NEW_END}"
+ fi
+ else
+ echo "ROOT_PART ${ROOT_PART} not matching partition ${PART_NO} of ROOT_DEV ${ROOT_DEV}."
+ fi
+ else
+ echo "ROOT_DEV ${ROOT_DEV} not a substring of ROOT_PART ${ROOT_PART}."
+ fi
+ update-rc.d resize2fs_once remove
+ rm -f /etc/init.d/resize2fs_once
log_end_msg $?
;;
*)