From 75a63613bcd76282e86b40fab2356a6e7b5a540b Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Sun, 28 Apr 2013 22:38:40 +0200 Subject: [PATCH] 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. --- cleanup_image | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cleanup_image b/cleanup_image index 522d9d4..3716593 100755 --- a/cleanup_image +++ b/cleanup_image @@ -23,11 +23,7 @@ export INSTALLDIR=`pwd`/mnt/ $SCRIPTSDIR/09_cleanup.sh echo "--> Compacting image file..." -dd if=/dev/zero of=mnt/fillme bs=1M > /dev/null 2>&1 || true -sync -rm mnt/fillme +fstrim mnt/ umount mnt -cp --sparse=always $IMG $IMG.new -mv $IMG.new $IMG ls -als $IMG