Skip to content

Instantly share code, notes, and snippets.

@Robokishan
Last active November 23, 2021 23:16
Show Gist options
  • Save Robokishan/4dc13947b980bdcdfc20543b75c1f0fb to your computer and use it in GitHub Desktop.
Save Robokishan/4dc13947b980bdcdfc20543b75c1f0fb to your computer and use it in GitHub Desktop.
Expand pi image
#sudo bash expand-pi-image.sh <img-file>
#sudo setup-chroot.sh <img-file>
#run changes and type exit
if [ "$1" ]; then
real_file_path=`realpath "${1}"`
echo "Img File: ${real_file_path}"
dd if=/dev/zero bs=1M count=1024 >> $real_file_path
sudo kpartx -v -a $real_file_path
loop_device=`losetup --list | grep "${real_file_path}" | cut -d ' ' -f1 | cut -d'/' -f3`
echo "Loop Device => /dev/${loop_device}"
sudo parted --script "/dev/${loop_device}" "resizepart 2 -1s"
sudo kpartx -d $real_file_path
sudo kpartx -v -a $real_file_path
loop_device=`losetup --list | grep "${real_file_path}" | cut -d ' ' -f1 | cut -d'/' -f3`
mapper_loop_device="/dev/mapper/${loop_device}p2"
echo "Mapper loop device ${mapper_loop_device}"
sudo e2fsck -f $mapper_loop_device
sudo resize2fs $mapper_loop_device
sudo kpartx -d $real_file_path
else
echo "Please Provide img file"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment