Zeroing Out a Partition


References
  1. Disk Duplicate - dd
  2. Data Sink - /dev/zero

Introduction

This pages describes how to write zeros (the first character in the ASCII character set) to an entire partition or hard drive. Why would you want to wipe out an entire disk in one fell swoop? There are three good reasons for this:

1. When re-installing Windows XP it will try to reuse the previous installation. If the previous installation is virus ridden or damaged in some other way, you will certainly want to make sure it is completely wiped out. In this case you should zero out the entire hard drive to make sure any partition table viruses are removed. Do of course, back up your virus free data first.

2. If you want to make an exact mirror image of a partition, it's very important to zero out the partition first. The reason is that all the free space will then have zeros which will compress down to next to nothing. Refer to Disk Mirror Imaging for instructions on this procedure.

3. This is an easy way to wipe a disk or partition clean so others cannot read it.

Linux Bootable Rescue Disks:

Before zeroing your partition or hard drive, you need to boot to Linux. You can do this with a Linux boot floppy or CD if you don't already have a Linux installation on your computer. There are many sources for obtaining Linux boot disks (also called "rescue" disks). Many distributions, such as Slackware and SuSE, are configured with a rescue mode as part of the bootable installation CD. There are also many of the biz card type (50 Mb) rescue CDs that will work fine too.

Here are some links to ISO images of bootable CDs that you can download and burn on a CD:

You can use cdrecord to write an ISO image (.iso) to a CD.

Step-by-Step Instructions

Here are step-by-step instructions to zero out a partition or an entire hard drive (or other storage device).

All the keystrokes that you sould type in at the command prompt are in green.

BE SURE TO BACK UP ALL DATA THAT YOU WANT TO KEEP BEFORE ZEROING IT OUT!

  1. Boot to Linux If you plan to use a boot floppy or CD, be sure the BIOS is set to boot to that device before the hard drive.

    As Linux boots it will display all the stuff it's setting up and configuring, unlike Windows which does most all the same stuff but hides it all.

    Each Linux boot disk has a little different user interface, but they all involve the same basic steps and each one should give you enough information so you can answer the prompts (if there are any) and get to a login prompt. You will need to log in as "root" which should be indicated on the screen above the login prompt.

    Every once in a while, a boot disk will not work right or hang on a certain machine. If this happens, try a different one, some disks are configured to work with a wider variety of hardware than others. Older versions of boot disks tend to work better with older hardware - but always try the latest version first.

  2. Gather Disk and Partition Information If you have more than one drive, It's a good idea to check and make sure you know which drive is which. You wouldn't want to zero out the wrong drive! Before listing drive information, you need to understand a little bit about Linux.

    Linux assigns names to disks and partitions in a much more logical, but different way, than windows does. Windows assigns letters to the primary partitions first and then to extended partitions. If you have a variety of primary and extended partitions, this can make for a jumbled up set of drive letters. Linux on the other hand, assigns names to each of the IDE drives connected to the mainboard as follows:

         IDE0, Master:  /dev/hda
         IDE0, Slave:   /dev/hdb
    
         IDE1, Master:  /dev/hdc
         IDE1, Slave:   /dev/hdd
    
         SCSI ID0:      /dev/sda
         SCSI ID1:      /dev/sdb
    

    Partitions are then assigned numbers in order as follows:

         First primary partition of hda:   /dev/hda1
         Second primary partition of hda:  /dev/hda2
         Third primary partition of hda:   /dev/hda3
         Fourth primary partition of hda:  /dev/hda4
         First extended partition of hda:  /dev/hda5
    

    With that bit of information understood, now have a look at the drive configuration in the computer. Most bootable Linux disks keep a log of the boot messages. From the log messages, you can see what brand and size of drives are in the computer.

    Use dmesg to display the boot time messages.

    Here are drive info. lines extract from my boot log:

    dmesg -s65536 | less

      hdb: 55704096 sectors (28520 MB) w/512KiB Cache, CHS=3467/255/63, UDMA(33)
      hdc: 37615536 sectors (19259 MB) w/418KiB Cache, CHS=37317/16/63, UDMA(33)
      SCSI device sda: 17783240 512-byte hdwr sectors (9105 MB)
      

    In the above example, I used the pager command, less (instead of more ), if you don't know how to use it, press h after having entered the above line.

    After detemining which drive(s) you want to zero out, use fdisk to list the partitions on the drive(s).

        fdisk -l /dev/hda      
    
    Disk /dev/hda: 3227 MB, 3227148288 bytes
    128 heads, 63 sectors/track, 781 cylinders
    Units = cylinders of 8064 * 512 = 4128768 bytes
    
       Device Boot      Start         End      Blocks   Id  System
       /dev/hda1   *           1           9       36256+   b  W95 FAT32
       /dev/hda2              10         777     3096576   83  Linux
       /dev/hda4             778         781       16128    5  Extended
       /dev/hda5             778         779        8032+  83  Linux
       /dev/hda6             780         781        8032+  83  Linux
    

    In this case, I want to zero out the win95 partition, /dev/hda1

  3. Zero Out the Disk or Partition Actually zeroing out the desired partition is about the easiest part, it's accomplished with the dd command as follows:
        dd if=/dev/zero of=/dev/hda1      
    

    To zero out the entire drive, use:

        dd if=/dev/zero of=/dev/hda      
    

    After the dd command finishes (it can take a while), your drive or partition will be wiped cleaned and ready to use. You can restart the computer by pressing Ctrl-Alt-Del or running the reboot command.


Please drop me a quick email if this helps or if you have comments.