Erase (zero out) free disk space on OSX, Windows and Ubuntu

Three operating systems, three file systems, three methods to zero out disk space.  Fortunately, they are all pretty simple. Doing this is a good idea right before creating a drive image for backup, as it makes compression more efficient.

OSX – HFS+ (Mac OSX Journaled)

  1. Open Disk Utility
  2. Click on the OSX partition
  3. Click Erase from the tabbar menu
  4. Click Erase free space… button
  5. Choose the Fastest option – this will fill the partition with zeros one time.

Windows 7 – FAT32, NTFS, exFAT

  1. Download SDelete from Microsoft Technet
  2. Copy sdelete.exe to C:\Windows\System32 (or any folder in your system PATH).
  3. Run SDelete from the command-line using:  
    sdelete -p 1 -z c:\

    (where ‘c’ is the target drive letter)

Ubuntu – ext3, ext4

  1. Install the secure-delete package: 
    sudo apt-get install secure-delete
  2. Use fdisk to find the correct drive partition:
    fdisk -l

     The drive in question will be something like /dev/sda or /dev/sdb.  Each partition is numbered, like /dev/sdb1 and /dev/sdb2

  3. Mount the drive partition (if it is not already):  
    sudo mount /dev/sdb1 /mnt/hdd1
  4. Run 
    sfill -Ilz /mnt/hdd1

    where ‘hdd1’ is the location of the mounted partition in the filesystem.

2 Comments

  1. With Linux (Ubuntu or RedHat), the “sfill -Ilz” command doesn’t works fine with ext3, ext2.. and others file system formats. It’s likely that the space is increased rather than reduced.

    I have test this on 2 VMs with ext formats and different linux OS.

    Regards,
    Drk.

  2. Joseph Spenner

    May 30, 2014 at 11:48 am

    In Linux, another way to do this is use dd and /dev/zero. To fill up a filesystem, do something like:

    dd if=/dev/zero of=/path/to/zero.file; rm /path/to/zero.file

    This will fill it up with zeros, then delete it.

    If your system is carved up into multiple partitions, you’d execute the above command such that the zero.file ends up somewhere in that filesystem.

Leave a Reply

Your email address will not be published.

*

© 2017 Eric Terpstra

Theme by Anders NorénUp ↑