Clone, Wipe, or Image Media Using dd to Create RAW Disk Images
I recently came across five Windows machines I needed to get working. These were all to be used for the same purpose and thus I would have had to do the same work five times over. I decided to do the work once and then just clone the original disk using dd
on Linux.
What follows are a number of example usages of the dd
utility:
- Make an ISO from a CD/DVD:
dd if=[device] of=disk.iso bs=2048 conv=sync
- Overwrite a disk with random data:
dd if=/dev/urandom of=[device]
One could use /dev/zero instead of /dev/urandom if they just wanted to zero out a disk.
Darik’s Boot And Nuke might be a better tool for this. - Clone a partition:
dd if=[device partition source] of=[device partition destination] bs=4K conv=noerror,sync
Create unformatted partitions first.
- Clone a disk:
dd if=[device source] of=[device destination] bs=4K conv=noerror,sync
- Create an image from a disk:
dd if=[device source] of=[image destination] bs=4K conv=noerror,sync
- Restore an image to a disk:
dd if=[image source] of=[device destination] bs=4K
.
- Create a compressed image from a disk:
dd if=[device source] bs=4K conv=noerror,sync | gzip -c > [image destination]
It would be a good idea to have your image name end with
.gz
so you later remember it is a compressed image and also clear out temporary directories.Adding
--fast
to gzip will not stress your CPU as badly (good for netbooks and the like). Adding--best
to gzip will give you the best compression but drastically slow you down.On a well-traveled filesystem zeroing out the free space can lead to huge space savings. In Linux you can use
cd [mounted filesystem] && sudo dd if=/dev/zero of=delme-0 bs=1M &> /dev/null ; sudo dd if=/dev/zero of=delme-1 bs=1 &> /dev/null ; sync && sudo rm delme-1 delme-0
on the mounted filesystem (if you have multiple partitions you should do it for each) while Windows offerssdelete -z [drive letter]:
. Depending on the amount of free space this could take a good long while. - Restore a compressed image to a disk:
gzip -d -c [image source] | dd of=[image destination]
If you do not have a working Linux installation you can always use a Live-CD. Use fdisk -l
or GParted
to figure out what a device is named.