dd is a utility that lets you copy data from one device/file to another while letting you change the block size and perform conversions if desired.

Wiping a Disk[edit]

Since UEFI, GPT, and RAID information is typically saved to both the start and end of a disk, in order to clear the metadata, you'll have to write to both ends of the disk.

To wipe the first and last 1MB of a disk:

## Wipe first 1MB
# dd bs=512 if=/dev/zero of=/dev/sdb count=2048

## Wipe last 1MB
# dd bs=512 if=/dev/zero of=/dev/sdb count=2048 seek=$((`blockdev --getsz /dev/sdb` - 2048))

Ignoring Errors[edit]

To make dd ignore errors, such as when cloning a failing drive, add the conv=noerror option.

The conv option specifies the type of conversion that dd needs to do to the input data. In this case, specifying noerror 'converts' errors from the input medium into nulls in the output medium.

# dd conv=noerror,sync if=/dev/sda1 > /mnt/rescue.img

There are lots of other conversions that dd can handle such as case conversion, EBCDIC, byte swapping, and more. (see https://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html#dd-invocation)

Manipulating by Bytes[edit]

Use the iflag=skip_bytes,count_bytes flags when working with data in bytes. The bs block size value will be ignored when these flags are used.

Question: When using the count_bytes flag, is this equivalent to bs=1? (It looks like it...)

Offset / Skipping Bytes[edit]

If you need to extract a chunk of data, say everything past byte 199232000 from a file:

$ dd if=blah.dat iflag=skip_bytes,count_bytes skip=199232000 | xxd

To get only 200 bytes of data instead:

$ dd if=blah.dat iflag=skip_bytes,count_bytes skip=199232000 count=200 | xxd

Or 2 kilobytes (2048 bytes):

$ dd if=blah.dat iflag=skip_bytes,count_bytes skip=199232000 count=2k | xxd

Use-Case Example[edit]

I had a broken multi-archive .rar archive which was incomplete. rar didn't like the file and refused to extract the file past this broken archive:

$ rar e -kb something.iso.part001.rar something.iso
something.iso - checksum error
Unexpected end of archive
something.iso : packed data checksum error in volume something.iso.part009.rar

I needed the file, even if it was corrupt in the middle. rar's repair tool didn't seem to help either. So, I appended the difference from the archive before it so that the file is 'complete' (ie. it has the same size as the other part archives) and then retried extracting the file again.

This time, rar complained packed data checksum error in volume but continued on with the extraction and while the file is 'broken', the -kb option kept the file.

See Also[edit]