diff --git a/pishrink.sh b/pishrink.sh index 5a481ef..f2df6b9 100755 --- a/pishrink.sh +++ b/pishrink.sh @@ -60,16 +60,51 @@ if [ "$should_skip_autoexpand" = false ]; then mountdir=`mktemp -d` mount $loopback $mountdir - if [ `md5sum $mountdir/etc/rc.local | cut -d ' ' -f 1` != "a27a4d8192ea6ba713d2ddd15a55b1df" ]; then + if [ `md5sum $mountdir/etc/rc.local | cut -d ' ' -f 1` != "c4eb22d9aa99915af319287d194d4529" ]; then echo Creating new /etc/rc.local mv $mountdir/etc/rc.local $mountdir/etc/rc.local.bak ###Do not touch the following 6 lines including EOF### -cat <<\EOF > $mountdir/etc/rc.local +cat <<\EOFE > $mountdir/etc/rc.local #!/bin/bash -/usr/bin/raspi-config --expand-rootfs -rm -f /etc/rc.local; cp -f /etc/rc.local.bak /etc/rc.local; reboot -exit 0 +do_expand_rootfs() { + ROOT_PART=$(cat /proc/cmdline | tr -s ' ' '\n' | grep root= | cut -d '=' -f 2) + if [[ "$ROOT_PART" != /dev/mmcblk0* ]] ; then + echo $ROOT_PART is not an SD card... + return 0 + fi + PART_NUM=$(echo $ROOT_PART | cut -d 'p' -f 2) + + # Get the starting offset of the root partition + PART_START=$(fdisk -l /dev/mmcblk0 | grep $ROOT_PART | tr -s ' ' | cut -d ' ' -f 2) + [ "$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 < /etc/rc.local && +#!/bin/sh +resize2fs $ROOT_PART +rm -f /etc/rc.local; cp -f /etc/rc.local.bak /etc/rc.local; /etc/rc.local + +EOF +reboot +exit +} +do_expand_rootfs +rm -f /etc/rc.local; cp -f /etc/rc.local.bak /etc/rc.local; /etc/rc.local +exit 0 +EOFE ###End no touch zone### chmod +x $mountdir/etc/rc.local fi