This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| IMG="$1" | |
| if [[ -e $IMG ]]; then | |
| P_START=$( fdisk -lu $IMG | grep Linux | awk '{print $2}' ) # Start of 2nd partition in 512 byte sectors | |
| P_SIZE=$(( $( fdisk -lu $IMG | grep Linux | awk '{print $3}' ) * 1024 )) # Partition size in bytes | |
| losetup /dev/loop2 $IMG -o $(($P_START * 512)) --sizelimit $P_SIZE | |
| fsck -f /dev/loop2 | |
| resize2fs -M /dev/loop2 # Make the filesystem as small as possible |