Some days ago I decided to wipe my 750 GB hard disk in order to sell it, so I booted Ubuntu
off a live DVD and started the process with sudo dd if=/dev/zero of=/dev/sda
. I left dd
running during the night. When I came back in the morning I discovered that at some point of the process Ubuntu
freezed. I'm unable to determine at which point of the process the freeze happened, because whenever it happened it happened while the screen saver was on, so i wasn't able see bash
's output.
Question: How do I avoid starting dd over again?
I worked out a solution myself:
Quick answer
Assuming that your drive is
/dev/sdX
:dd if=/dev/zero | cmp - /dev/sdX
to spot the first non-zero byte of the device: in my case it was byte742300476649
<device_first_non_zero_block>=floor(<device_first_non_zero_byte>/<device_block_size>)+1
: you can check your<device_block_size>
runningfdisk -l /dev/sdX
in a terminal: in my case it was block1449805619
dd
again from there:dd if=/dev/zero bs=<device_block_size> skip=<device_first_non_zero_block>-1
: in my case the command wasdd if=/dev/zero of=/dev/sda bs=512 skip=1449805618
Long answer
Giving
cmp
-
asFILE1
will force it to readFILE1
fromstdin
, so a constant stream of zeros will makecmp
compare each byte ofFILE2
against zero untilEOF
, reporting (if any) the first non-zero byte: assuming that the drive is/dev/sdX
:dd if=/dev/zero | cmp - /dev/sdX
The first non-zero block of the device is the block containing the first non-zero byte, i.e.:
So, to start
dd
again from there, just skip the first<device_first_non_zero_block>-1
blocks:Testing
Creating a 512KB file containing only zeros to simulate a wiped hard drive:
$ dd if=/dev/zero of=hdd1 bs=512 count=1000
Creating a 512KB file containing only random bytes to simulate a hard drive containing data:
$ dd if=/dev/urandom of=hdd2 bs=512 count=1000
Merging the two files to simulate a partially wiped hard drive:
$ cat hdd1 hdd2 > hdd3
Output of the command on the test drives:
In this case:
So, to start
dd
again from there:Output of the command on
hdd3
:Checking if the procedure succeded:
Bingo!