Skip to content

Instantly share code, notes, and snippets.

@tuklusan
Last active July 4, 2022 23:25
Show Gist options
  • Save tuklusan/cae51fb885661d75488e960f72ec5432 to your computer and use it in GitHub Desktop.
Save tuklusan/cae51fb885661d75488e960f72ec5432 to your computer and use it in GitHub Desktop.
Zero Out Free Disk Space on Virtual Machines and Compact them Before Backup: Solaris, Linux, Windows, OpenVMS: http://supratim-sanyal.blogspot.com/2016/12/zero-out-free-disk-space-on-virtual.html
#!/bin/bash -x
#
# ---
# zerofill.sh
# ---
#
# Poor man's zerofill to fill up unusued space with zeroes
# for better compaction of virtual hard-disk.
#
# For my simple solaris 11 openindiana installation, this zeroes out empty
# disk space on /tmp/ (user partitions are TBD)
# Zeroing out other partitions not supported yet
#
# This script just creates a big file with zeroes and deletes it. To monitor
# progress you can you something like
# while [ 1 ]; do date; ls -lh /tmp/zero* ; df -h; sleep 10; done
#
# Supratim Sanyal - http://mcaf.ee/sdlg9f
# License: GNU AGPLv3 (http://tuklusan.decsystem.org/agpl-3.0-standalone.html)
# ---
#
if cd /tmp/ ; then
cat /dev/zero > zero.delete-me
sync
rm -f zero.delete-me
sync
else
echo "FAIL - no directory to create zero file in"
fi
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment