#!/bin/bash # nems-fs-resize # # Resize the root filesystem of any SBC # By Robbie Ferguson - https://baldnerd.com/ # Designed for NEMS Linux - https://nemslinux.com/ # # Feel free to include this in your projects, but I'd appreciate it # if the credit was left in place (though you can do whatever you want). # # Tip me at https://donate.category5.tv or https://patreon.com/nems # ######################################################################### set -e if [ "$(id -u)" -ne "0" ]; then echo "This script requires root." exit 1 fi set -x # Detect the drive and partition fulldev=`/bin/mount | /bin/sed -n 's|^/dev/\(.*\) on / .*|\1|p'` if [[ $fulldev == "" ]]; then echo "Could not determine your root device." exit 1 fi rootdev=`echo $fulldev | cut -d "p" -f 1` if [[ $rootdev == $fulldev ]]; then rootdev="${fulldev//[!a-z]/}" fi rootpart=`echo $fulldev | cut -d "p" -f 2` if [[ $rootpart == $fulldev ]]; then rootpart="${fulldev//[!0-9]/}" fi resize() { if [[ -e /dev/${rootdev}p${rootpart} ]]; then # This one is a mmc device (with p in the name) datapartpath="/dev/${rootdev}p${rootpart}" else # This one is a sd device (with no p in the name) datapartpath="/dev/${rootdev}${rootpart}" fi # Check if bootable bit is set boot=$(fdisk -l -o device,boot /dev/${rootdev}|grep ${datapartpath}|awk '{print $2}') if [[ $boot == "*" ]]; then bootbit=1 else bootbit=0 fi # Re-create the partition using all available space start=$(fdisk -l -o device,start,end /dev/${rootdev}|grep ${datapartpath}|awk '{print $2}') echo "Starting Sector: ${start}" set +e fdisk /dev/${rootdev} <> /var/log/nems/patches.log fi # NEMS runs this script on first boot, so if this is NEMS, this entry will be removed sed -i "s,/root/nems/nems-admin/resize_rootfs/nems-fs-resize,,g" /etc/rc.local # PARTUUID has changed, so allow the Indiedroid Nova to update its kernel params /root/nems/nems-admin/build/160-indiedroid-nova fi echo "Done! If you don't see the free space, reboot."