Skip to content

Instantly share code, notes, and snippets.

@Cenness
Created May 4, 2017 13:44
Show Gist options
  • Save Cenness/17d31d999bc70e1234fe4b8b73d69ca1 to your computer and use it in GitHub Desktop.
Save Cenness/17d31d999bc70e1234fe4b8b73d69ca1 to your computer and use it in GitHub Desktop.
RaspberryPi - resize the main partition to fill the SD card if there is more than 1GiB of free space on reboot
#!/bin/bash
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
## resize the main partition to fill the SD card if there is more than 1GiB of free space
unused_space="$(parted /dev/mmcblk0 unit GiB print free | awk '/Free Space/{c++; sum += $3} END{print sum}' | awk '{print ($0>1)?1:0}')"
if (( $unused_space ))
then
if [ -f /root/scripts/resize.attempting ]
then
> /root/scripts/resize.FAILED
exit
else
> /root/scripts/resize.attempting
raspi-config --expand-rootfs
reboot
fi
else
rm -f /root/scripts/resize.attempting
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment