Skip to content

Instantly share code, notes, and snippets.

View magneticore's full-sized avatar

Jorge Morales magneticore

View GitHub Profile
#!/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