4

In preparation for making compressed disk images of a number of hard drives, I'm looking for software that will zero-fill unused parts of the disk (long runs of zeros compress quite well).

Requirements:

  • Runs under either Linux or Windows 98.
  • Supports NTFS and FAT32 disk formats.
  • Zeros out as much as possible (empty space both unallocated and within allocations, unused directory entries, etc.)
  • Free

Nice to have:

  • Support for ext2 and ext3 disk formats.
4
  • Windows 98? Did that ever support NTFS at all? Aug 28, 2015 at 12:34
  • 2
    SysInternals SDelete if you can afford at least Windows XP. Aug 28, 2015 at 12:35
  • truth is, that Win 98 + NTFS could be an oxymoron... probably there ase some external utils to read NTFS.. but who cares about dead OS??
    – Dee
    Aug 28, 2015 at 14:17
  • @Thomas, one of the computers I'm going to image has Win98 installed and is too slow to run WinXP. If I'm going to do this with a single program, it needs to be either Win98 (to run from that computer's installed OS) or Linux (to run from a combined boot floppy and network filesystem).
    – Mark
    Aug 28, 2015 at 19:49

5 Answers 5

2

You can use WipeFreeSpace which runs on linux. Supports various filesystems including FAT32 (Win98). You have to pass trough manual building process, as there is no binary...

Or you can use hacers tool THC-SecureDelete.

For firs try I do recommend you to backup all the data first, so therefore tar the data to another disk and wipe whole disk and tar it back is acceptable option if you do it only once.

Updated: SysInternals SDelete for at least Windows XP as Thomas mentioned in upper comment is only free Windows solution.

0

I would suggest booting from a Linux USB key that gives read/write access to the drive that you wish to zero and using a python script, (most Linux installations include python), to do something like:

import os

def DoIt(drive_path):
    """ Fill a drive with zeros then delete them """    
    info = os.statvfs(drive_path)  # Get a the file system info. NOT AVAILABLE ON WINDOWS!
    zerodir = os.path.join(drive_path, 'ZerosDir')  # Create a directory name
    os.makedirs(zerodir)  # And the directory
    filename_pattern = os.path.join(zerodir, 'Z%07d.000')  # File name pattern
    bsize = max(info.f_bsize, info.f_frsize)  # Decide the block size
    zeros = "\x00" * bsize  # Create a block of zeros that size

    try:  # We don't wish to abort the whole script on an error
        for n in xrange(info.f_files):  # For the max number of files allowed
            with open(filename_pattern % n, 'wb') as zf:  # Open a file
                zf.write(zeros)  # write the file
                zf.flush()  # Make sure it is written
                os.fsync(zf)  # REALLY Sure
    except IOError, e:
        pass # Carry on to the end of the script even if there is a problem
    print 'Finished Creating Files'

    for n in xrange(info.f_files):  # For the max number of files allowed
       try:  # Don't wish to abort even if there is a file we can't delete
           os.os.remove(filename_pattern % n) # Remove the file
       except OSError, e:  # In case of problems
           print e  # Print the problem but carry on
    os.rmdir(zerodir)
    print 'Done!'

if __name__ == "__main__":
    import sys
    if len(sys.argv) < 2:
        print "Please supply the path(s) to the drive(s) to fill with zeros"
    for arg in sys.argv[1:]:
        DoIt(arg)

Important Note

The above is 100% untested Use at your own risk

1
  • Doesn't look like it will zero the slack space in FAT32 and other cluster-based filesystems, and it doesn't even touch unused directory entries.
    – Mark
    Aug 28, 2015 at 19:46
0

Historically, my solution to do as you have described would be to mount the source filesystem and use the dd command to create a zero-fill file, and then delete the temporary file:

$ mount /dev/source_hard_drive /mnt
$ cd /mnt
$ dd if=/dev/zero of=some_random_temp_file bs=1M ; rm some_random_temp_file
3
  • 1
    That won't zero the slack space of partially-used sectors.
    – Mark
    Aug 30, 2015 at 6:31
  • Would running defrag first help with this issue?
    – baitisj
    Aug 30, 2015 at 21:14
  • No. Defragmentation won't pack multiple files into a single sector if the filesystem isn't designed for it, and I don't believe any of the filesystems I'm interested in support it.
    – Mark
    Aug 31, 2015 at 5:03
0

Consider using Partclone instead of zeroing out unused space on your drive. Partclone is free software, and supports NTFS, FAT32, and EXT2 & EXT3 disk formats, as well as many other formats.

Instead of zeroing out unused space, Partclone can be configured to copy only the used blocks present on the disk. It can generate what is called a domain file, which specifies what blocks on the disk are actually in use. This will save you time and allow for a non-destructive copy of your source data.

0

Zeros out as much as possible (empty space both unallocated and within allocations, unused directory entries, etc.)

ntfswipe worked well on linux. It can get all unused bits, such as undelete information and deleted file, not just free space.

Support for ext2 and ext3 disk formats.

For that you can use zerofree.

2
  • That's three out of four formats covered. Do you have a suggestion for FAT32 as well?
    – Mark
    Oct 9, 2016 at 7:27
  • @mark no, sorry, these are just the ones I found trying to do the same thing
    – endolith
    Oct 9, 2016 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.