Dd - Destroyer of Disks

From Noah.org
Revision as of 20:21, 6 March 2008 by Root (talk | contribs)
Jump to navigationJump to search

wipe a drive

This will destroy all data on a drive using `dd`. The downside is that it does not give you an estimate of how much time it will take to finish.

dd if=/dev/random of=/dev/sda bs=1M

Erase MBR

I had Linux with GRUB installed on a machine. I needed to get rid of it and put Windows on the machine. I used a Ghost recovery disk to restore Windows on it, but Ghost didn't restore the MBR. GRUB was still lurking in the Master Boot Record. On boot GRUB would try to start but would error out. Wiping out the MBR fixed the problem. This will wipe out the MBR of a disk (sda in this example):

dd if=/dev/zero of=/dev/sda bs=512 count=1

Image a drive over a network with dd and nc

Start the receiving side first. This assumes machine 192.168.1.100:

nc -l -p 2222 > disk_image.gz

Then start sending:

dd bs=1M if=/dev/sda | gzip -c - | nc 192.168.1.100 2222

Image a drive over a network with dd and ssh

I like this method better because this does it all from a single command on the sending side and the traffic is encrypted:

dd if=/dev/sda | gzip -c - | ssh user@example.com "dd of=disk_image.gz"

Notes

If you are doing this on a live server you will need to unmount the drive or switch to single user mode (reboot and set single for boot option in GRUB) or you can boot from a live CD. If you boot into single user mode, don't forget to manually start the network. I have not done a lot of testing with copying a mounted disk in single user mode. This is not the ideal way, but it seems to work. It's better if the drive is not mounted.