cleanup-image: smart image shrink using fstrim

Linux loop driver support TRIM operation for some time (from 3.1
kernel), which is mapped to hole punch operation in underlying
filesystem (which must support it - ext* and xfs have it).
This is much faster and less space consuming than previous cp --sparse
method.
This commit is contained in:
Marek Marczykowski 2013-04-28 22:38:40 +02:00
parent 30155ba17b
commit 75a63613bc

View File

@ -23,11 +23,7 @@ export INSTALLDIR=`pwd`/mnt/
$SCRIPTSDIR/09_cleanup.sh $SCRIPTSDIR/09_cleanup.sh
echo "--> Compacting image file..." echo "--> Compacting image file..."
dd if=/dev/zero of=mnt/fillme bs=1M > /dev/null 2>&1 || true fstrim mnt/
sync
rm mnt/fillme
umount mnt umount mnt
cp --sparse=always $IMG $IMG.new
mv $IMG.new $IMG
ls -als $IMG ls -als $IMG