From 84348c39af2ed3fd6303999880480616bca0df4b Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Sat, 27 Jul 2013 16:39:52 -0400 Subject: [PATCH] fix(build_library): Re-enable zeroing free-space but in a sane way. As of Linux 3.2 loopback supports discard by punching holes in the underlying file. This doesn't actually seem to impact things right now since we are writing to fresh filesystems but might as well do this to prevent wasted space from sneaking in later on. --- build_library/base_image_util.sh | 19 ++++--------------- build_library/dev_image_util.sh | 4 ++++ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/build_library/base_image_util.sh b/build_library/base_image_util.sh index b91b920597..d06610a306 100755 --- a/build_library/base_image_util.sh +++ b/build_library/base_image_util.sh @@ -36,17 +36,6 @@ cleanup_mounts() { set -e } -zero_free_space() { - local fs_mount_point=$1 - info "Zeroing freespace in ${fs_mount_point}" - # dd is a silly thing and will produce a "No space left on device" message - # that cannot be turned off and is confusing to unsuspecting victims. - info "${fs_mount_point}/filler" - ( sudo dd if=/dev/zero of="${fs_mount_point}/filler" bs=4096 conv=fdatasync \ - status=noxfer || true ) 2>&1 | grep -v "No space left on device" - sudo rm "${fs_mount_point}/filler" -} - create_base_image() { local image_name=$1 local rootfs_verification_enabled=$2 @@ -281,10 +270,10 @@ create_base_image() { # create /usr/local or /var on host (already exist on target). setup_symlinks_on_root "/usr/local" "/var" "${stateful_fs_dir}" - # Zero rootfs free space to make it more compressible so auto-update - # payloads become smaller - # TODO(ifup): - #zero_free_space "${root_fs_dir}" + # Zero all fs free space to make it more compressible so auto-update + # payloads become smaller, not fatal since it won't work on linux < 3.2 + sudo fstrim "${root_fs_dir}" || true + sudo fstrim "${stateful_fs_dir}" || true cleanup_mounts diff --git a/build_library/dev_image_util.sh b/build_library/dev_image_util.sh index 7dc24c3e90..1a0bfff54a 100755 --- a/build_library/dev_image_util.sh +++ b/build_library/dev_image_util.sh @@ -88,6 +88,10 @@ EOF sudo chmod a+rx "${path}" fi + # Zero all fs free space, not fatal since it won't work on linux < 3.2 + sudo fstrim "${root_fs_dir}" || true + sudo fstrim "${stateful_fs_dir}" || true + info "Developer image built and stored at ${image_name}" cleanup_mounts