Dd
Template:UnixTemplate:Lowercase dd (doesn't stand for anything that matters) is a powerful and dangerous unix program that performs raw block copies of data. In particular, it is often used for copying hard disk data raw partition-to-partition, partition-to-file, and/or file-to-partition.
Contents
Synopsis
Often the invocation is as simple as
dd if=<input file = stdin> of=<output file = stdout> bs=<block size = 512> count=<block count = until end of input>
That is, from the beginning of if copy count blocks of bs bytes to the file of.
Block sizes
bs can use human suffixes. Use e.g. kB, MB, GB for decimal meanings (1000^n), but use e.g. K, M, G or KiB, MiB, GiB for the binary equivalents (1024^n).
bs can be replaced by ibs and obs to set in and out block sizes separately.
Writing to files in-place
See conv=notrunc, seek=, skip=.
Hard disk recovery
When recovering a failing drive, among the recommendations are:
- Use a small block size, such as 512 bytes
- Use the conv option noerror, which causes the program to continue even if a read fails
- Use the conv option sync, which causes short (erroneously read) blocks to be padded out so that any good output still aligns correctly
In other words:
dd bs=512 if=/dev/<some device> of=output.img conv=noerror,sync
Print status messages
By default, dd keeps quiet about its progress. In most versions, there is a way to send it a signal to request a progress report.
In Linux, this signal is the USR1 signal. The following command will cause all running dd processes to echo status every second:
while killall -USR1 dd; do sleep 1; done
killall can be replaced with the equivalent kill command and pid to signal only one process.
dcfldd
The program dcfldd is a fork of dd that has special security- and display-related options. The USR1 signal is not necessary to produce a readout; by default, a status is printed to stderr every 256 blocks. Set statusinterval=<number of blocks>
to change the interval.