Skip filesystem shrinking without error if small
This commit is contained in:
parent
43f1a885cd
commit
2d97ee2195
50
pishrink.sh
50
pishrink.sh
|
@ -332,36 +332,36 @@ fi
|
||||||
minsize=$(cut -d ':' -f 2 <<< "$minsize" | tr -d ' ')
|
minsize=$(cut -d ':' -f 2 <<< "$minsize" | tr -d ' ')
|
||||||
logVariables $LINENO currentsize minsize
|
logVariables $LINENO currentsize minsize
|
||||||
if [[ $currentsize -eq $minsize ]]; then
|
if [[ $currentsize -eq $minsize ]]; then
|
||||||
error $LINENO "Image already shrunk to smallest size"
|
info "Filesystem already shrunk to smallest size. Skipping filesystem shrinking."
|
||||||
exit 11
|
else
|
||||||
fi
|
#Add some free space to the end of the filesystem
|
||||||
|
extra_space=$(($currentsize - $minsize))
|
||||||
|
logVariables $LINENO extra_space
|
||||||
|
for space in 5000 1000 100; do
|
||||||
|
if [[ $extra_space -gt $space ]]; then
|
||||||
|
minsize=$(($minsize + $space))
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
logVariables $LINENO minsize
|
||||||
|
|
||||||
#Add some free space to the end of the filesystem
|
#Shrink filesystem
|
||||||
extra_space=$(($currentsize - $minsize))
|
info "Shrinking filesystem"
|
||||||
logVariables $LINENO extra_space
|
resize2fs -p "$loopback" $minsize
|
||||||
for space in 5000 1000 100; do
|
rc=$?
|
||||||
if [[ $extra_space -gt $space ]]; then
|
if (( $rc )); then
|
||||||
minsize=$(($minsize + $space))
|
error $LINENO "resize2fs failed with rc $rc"
|
||||||
break
|
mount "$loopback" "$mountdir"
|
||||||
|
mv "$mountdir/etc/rc.local.bak" "$mountdir/etc/rc.local"
|
||||||
|
umount "$mountdir"
|
||||||
|
losetup -d "$loopback"
|
||||||
|
exit 12
|
||||||
fi
|
fi
|
||||||
done
|
sleep 1
|
||||||
logVariables $LINENO minsize
|
|
||||||
|
|
||||||
#Shrink filesystem
|
|
||||||
info "Shrinking filesystem"
|
|
||||||
resize2fs -p "$loopback" $minsize
|
|
||||||
rc=$?
|
|
||||||
if (( $rc )); then
|
|
||||||
error $LINENO "resize2fs failed with rc $rc"
|
|
||||||
mount "$loopback" "$mountdir"
|
|
||||||
mv "$mountdir/etc/rc.local.bak" "$mountdir/etc/rc.local"
|
|
||||||
umount "$mountdir"
|
|
||||||
losetup -d "$loopback"
|
|
||||||
exit 12
|
|
||||||
fi
|
fi
|
||||||
sleep 1
|
|
||||||
|
|
||||||
#Shrink partition
|
#Shrink partition
|
||||||
|
info "Shrinking partition"
|
||||||
partnewsize=$(($minsize * $blocksize))
|
partnewsize=$(($minsize * $blocksize))
|
||||||
newpartend=$(($partstart + $partnewsize))
|
newpartend=$(($partstart + $partnewsize))
|
||||||
logVariables $LINENO partnewsize newpartend
|
logVariables $LINENO partnewsize newpartend
|
||||||
|
|
Loading…
Reference in New Issue