Difference between revisions of "Securely wipe disk"

From ArchWiki
Jump to: navigation, search
(Overwrite the disk: Add resource links, improve grammar)
(Overwrite the disk: Add command to find block size)
Line 72: Line 72:
 
{{warning|There is no confirmation regarding the sanity of this command so '''repeatedly check''' that the correct drive or partition has been targeted. Make certain that the {{ic|<nowiki>of=...</nowiki>}} option points to the target drive and not to a system disk.}}
 
{{warning|There is no confirmation regarding the sanity of this command so '''repeatedly check''' that the correct drive or partition has been targeted. Make certain that the {{ic|<nowiki>of=...</nowiki>}} option points to the target drive and not to a system disk.}}
  
If you have a modern hard drive it is recommended that you specify a block size larger than the default 512 bytes. To speed up the overwriting process choose a block size matching your drive's physical geometry by appending the block size option to the dd command (i.e. {{ic|<nowiki>bs=4M</nowiki>}}). For more information read the [[Wikipedia:Block size#Block size|Block size]] section on Wikipedia and the [http://www.linfo.org/get_block_size.html How to Find the Block Size] on The Linux Information Project.
+
If you have a modern hard drive it is recommended that you specify a block size larger than the default 512 bytes. To speed up the overwriting process choose a block size matching your drive's physical geometry by appending the block size option to the dd command (i.e. {{ic|<nowiki>bs=4M</nowiki>}}). For more information read the [[Wikipedia:Block size#Block size|Block size]] section on Wikipedia.
 +
 
 +
To quickly find the block size of the device issue the following command:
 +
# dumpe2fs -h /dev/sdX | grep 'Block size:'
 +
For more information read [http://www.linfo.org/get_block_size.html How to Find the Block Size] on The Linux Information Project.
  
 
Zero-fill the disk by writing a zero byte to every addressable location on the disk using the [[Wikipedia:/dev/zero|/dev/zero]] stream.
 
Zero-fill the disk by writing a zero byte to every addressable location on the disk using the [[Wikipedia:/dev/zero|/dev/zero]] stream.

Revision as of 03:24, 21 September 2012

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end

Wiping a disk is done by simply writing new data over every single bit.

Tip: Where refered to "disks" in this article you can of course apply the same procedure for your loopback-devices or anything else.

As mentioned in the Disk Encryption-Article there might be different scenarios for why you want to wipe a disk.

Wipe all data left on the device. There may be (possibly unencrypted) data left on the device and you want to protect against simple Forensic Investigation that would be possible with i.e. File Recovery-Software.

Preparation for block device encryption. You want to prepare your drive to securely set up Block device encryption inside the wiped area afterwards.

Introduction

Wipe all data left on the device

If you are not going to set up block device encryption but just want to roughly wipe everything from the disk you could consider using /dev/zero or simple patterns instead of a cryptographically strong random number generator. (Referred to as RNG in this article from now on.) This allows to wipe big disks with maximum performance.

However you might consider prefering the RNG-Method due to Security concerns. This is covered up in the Section about #Preparations for block device encryption.

Also read the section on the possibility of #Data remanence if you want to take wiping serious.

Preparations for block device encryption

Warning: If Block device encryption is mapped on a partition that contains anything else than random/encrypted data, disclosure of usage patterns on the encrypted drive is possible and weakens the encryption the kind of it does for filesystem-level-encryption. Do never use /dev/zero, simple patterns (badblocks, eg.) or other unrandomn data before setting up Block device encryption if you are serious about it!

Performance

The Kernel built-in RNG /dev/random provides you the same quality random data you would use for keygeneration, but can be nearly impractical to use at least for wiping current HDD capacitys. What makes disk wiping take so long with is to wait for it to gather enough true entropy. In an entropy starved situation (e.g. remote server) this might never end while doing search operations on large directories or if your at your desktop running a first person shooter can speed up things a lot.

You can always compare /proc/sys/kernel/random/entropy_avail against /proc/sys/kernel/random/poolsize to keep an eye on your entropy pool.

Note: Everything regarding Benchmarking disk wipes should be merged there

Pseudorandom Data

A Good Compromise between Performance and Security might be the use of a pseudorandom number generator (like Frandom) or a cryptographically secure pseudorandom number generator like Yarrow (FreeBSD/OS-X) or Fortuna (the intended successor of Yarrow)

Tip: The cryptsetup FAQ mentions a very simple procedure to use an existing dm-crypt-Volume to act as a simple PRNG and wipe all free space accesible trough the underlying partition. It is also claimed to protect against disclosure of usage patterns. dd if=/dev/zero of=/dev/mapper/luks Thats it! Obviously this will wipe all data written to your dm-crypt Volume.

Conclusion

If you want to wipe sensitive data you can use anything matching your needs.

If you want to setup block device encryption you should always wipe at least with Pseudorandom data.

As a matter of course the best wiping practice is to never write unencrypted data.

Select a target

Note: Fdisk will not work on GPT formatted devices. Use gdisk instead.

Use fdisk to locate all read/write devices. This will include USB drives if the user can access them. List the partition tables:

# fdisk -l

Check the output for lines that start with devices such as /dev/sda. For example:

Disk /dev/sdc: 4063 MB, 4063232000 bytes
125 heads, 62 sectors/track, 1024 cylinders
Units = cylinders of 7750 * 512 = 3968000 bytes
Disk identifier: 0x00000000

In the preceding example the USB thumb drive is listed as /dev/sdc.

Overwrite the disk

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: Shouldn't it be bs=4K as there is no HDD with 4MB-Sectors? (Discuss in Talk:Securely wipe disk#)
Warning: There is no confirmation regarding the sanity of this command so repeatedly check that the correct drive or partition has been targeted. Make certain that the of=... option points to the target drive and not to a system disk.

If you have a modern hard drive it is recommended that you specify a block size larger than the default 512 bytes. To speed up the overwriting process choose a block size matching your drive's physical geometry by appending the block size option to the dd command (i.e. bs=4M). For more information read the Block size section on Wikipedia.

To quickly find the block size of the device issue the following command:

# dumpe2fs -h /dev/sdX | grep 'Block size:'

For more information read How to Find the Block Size on The Linux Information Project.

Zero-fill the disk by writing a zero byte to every addressable location on the disk using the /dev/zero stream.

# dcfldd if=/dev/zero of=/dev/sdX bs=4M

or the /dev/random stream:

# dcfldd if=/dev/urandom of=/dev/sdX bs=4M

The process is finished when dcfldd reports, No space left on device. For example:

18944 blocks (75776Mb) written.dcfldd:: No space left on device

Common tools

There are a variety of applications that can securely wipe disks like dd (that should be present on arch through util-linux) or shred.

Checking progress of dd while running

By default, there is no output of dd until the task has finished. With kill and the "USR1"-Signal you can force status output without actually killing the program. Simply open up a 2nd root terminal and issue the following command:

# killall -USR1 dd
Note: Obviously this will affect all other running dd-processes as well.

Or:

# kill -USR1 <PID_OF_dd_COMMAND>

For example:

# kill -USR1 $(pidof dd)

This causes the terminal in which dd is running to output the progress at the time the command was run. For example:

605+0 records in
605+0 records out
634388480 bytes (634 MB) copied, 8.17097 s, 77.6 MB/s

Dcfldd

dcfldd is an enhanced version of dd with features useful for forensics and security. It accepts most of dd's parameters and includes status output. Install dcfldd from the official repositories.

Note: Dcfldd's source has been untouched since 19.12.2006.

Data remanence

Data remanence after wiping is possible for a bunch of reasons.

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: Reliable good resources should be linked instead of that much Wikipedia Articles. (Discuss in Talk:Securely wipe disk#)
residual magnetism

Wiped HDD and other magnetic storage can get disassembled in a cleanroom and then analyzed with HighTech Equipment like a magnetic force microscope to guess on the overwritten data by computing around the measured residual magnetics.

Note: This is more kind of theoretical for current HDD's at the moment and assumes an attacker extremely heavy on financial resources. Nevertheless degaussing is still practiced.

To seriously make sure you wiped it out for ever you nevertheless might want to use random data and if you think you will really be able to sleep better feel free to give it more than one iteration.

Note: In case your disk is a ordinary HDD going trough more than one iteration may not significantly decrease the ability to reconstruct the data. (Resources: Secure deletion: a single overwrite will do it, Overwriting Hard Drive Data: The Great Wiping Controversy).
Tip: If you know exactly what you want to wipe and where it's located on the disk and that it has never been copied anywhere else you can do very secure wiping in precious few seconds with any RNG.
older magnetic storage

Secure wiping of any "older" magnetic storage (especially Floppys, Magnetic Tape, ...) is much harder due to much lower memory storage density. Many iterations with random data might be needed to wipe any sensitive data ever copied there. Most resources even advise physical destruction in addition if you want to be really sure!

Flash-Storage

But not only old Media can be hard to wipe. Flash-Storage behaves very unforgiving as well due to wear leveling, transparent compression, ...

Resources:

Reliably Erasing Data From Flash-Based Solid State Drives

Filesystem, OS, Programms

The OS, executed Programs or a (journaling) filesystem also can do a lot to copy and spread your unencrypted data over the block device, but because you are writing to plain disks this should only be relevant in conjunction with one of the above.

Resources