From c2e09c32bc5baeb917a54d0e0b4e07f247f39822 Mon Sep 17 00:00:00 2001 From: Phuong Vu Date: Sun, 5 Dec 2021 14:30:29 +0700 Subject: [PATCH] Changed code to handle situation where mmcblk0 is not the default device --- pishrink.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pishrink.sh b/pishrink.sh index c7b1fb3..58a0119 100755 --- a/pishrink.sh +++ b/pishrink.sh @@ -90,18 +90,20 @@ cat <<\EOF1 > "$mountdir/etc/rc.local" do_expand_rootfs() { ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p') - PART_NUM=${ROOT_PART#mmcblk0p} - if [ "$PART_NUM" = "$ROOT_PART" ]; then + if ! [[ "$ROOT_PART" =~ mmcblk.+ ]]; then echo "$ROOT_PART is not an SD card. Don't know how to expand" return 0 fi + PART_NUM=${ROOT_PART: -1} + DEV=$(ls /dev/mmcblk[0-9]) + # Get the starting offset of the root partition - PART_START=$(parted /dev/mmcblk0 -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g') + PART_START=$(parted $DEV -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g') [ "$PART_START" ] || return 1 # Return value will likely be error for fdisk as it fails to reload the # partition table because the root fs is mounted - fdisk /dev/mmcblk0 <