dd system ‘dd’ command
Overview
The dd command copies data from an input file or device to an output
file or device, optionally performing conversions along the way. It is
commonly used for tasks such as backing up and restoring raw disk
partitions, creating disk images, and converting data formats.
The name dd stands for “convert and copy” (historically “disk dump”).
It reads from stdin by default and writes to stdout by default,
making it useful in pipelines and for low-level I/O operations.
Configuration
Enable the command with CONFIG_SYSTEM_DD. This option is enabled by
default unless CONFIG_DEFAULT_SMALL is set.
The following configuration options are available:
CONFIG_SYSTEM_DD_PROGNAMEProgram name for the
ddcommand. Default:dd.CONFIG_SYSTEM_DD_PRIORITYTask priority for the
ddcommand. Default: 100.CONFIG_SYSTEM_DD_STACKSIZEStack size for the
ddcommand. Default:DEFAULT_TASK_STACKSIZE.CONFIG_SYSTEM_DD_STATSEnable transfer statistics output. Default: yes.
Usage
dd [if=<infile>] [of=<outfile>] [bs=<sectsize>] [count=<sectors>] [skip=<sectors>] [seek=<sectors>] [verify] [conv=<nocreat,notrunc>]
Options
if=<infile>Input file. If not specified,
stdinis used.of=<outfile>Output file. If not specified,
stdoutis used.bs=<sectsize>Block size in bytes. Default: 512 bytes.
count=<sectors>Number of blocks to copy. Default: copy until end of input.
skip=<sectors>Skip
<sectors>blocks at the start of the input.seek=<sectors>Skip
<sectors>blocks at the start of the output.verifyVerify that the output matches the input after copying. Requires both
ifandofto be specified.conv=<nocreat,notrunc>Conversion options:
nocreat: Do not create the output file if it does not exist.notrunc: Do not truncate the output file before writing.
Multiple conversion options can be separated by commas.
--helpDisplay usage information and exit.
Examples
Copy from stdin to stdout:
nsh> dd if=/dev/zero of=/tmp/zero.bin bs=1024 count=10
10+0 records in
10+0 records out
Create a disk image:
nsh> dd if=/dev/sda of=/tmp/disk.img bs=512
1024+0 records in
1024+0 records out
Restore a disk image:
nsh> dd if=/tmp/disk.img of=/dev/sda bs=512
1024+0 records in
1024+0 records out
Copy with verification:
nsh> dd if=/dev/sda of=/tmp/sda_backup.img bs=512 verify
1024+0 records in
1024+0 records out
Skip blocks in input:
nsh> dd if=/dev/sda of=/tmp/partition.img bs=512 skip=63 count=1024
1024+0 records in
1024+0 records out
Display usage information:
nsh> dd --help
usage:
dd [if=<infile>] [of=<outfile>] [bs=<sectsize>] [count=<sectors>] [skip=<sectors>] [seek=<sectors>] [verify] [conv=<nocreat,notrunc>]
Notes
The default block size is 512 bytes, which is the standard sector size for most storage devices.
When
countis not specified,ddcopies until the end of the input is reached.The
verifyoption requires bothifandofto be specified. It reads back the output and compares it to the input.Transfer statistics are displayed when
CONFIG_SYSTEM_DD_STATSis enabled. The output shows the number of records read/written and the transfer rate.The
convoptions can be combined by separating them with commas. For example,conv=nocreat,notrunc.ddis often used in pipelines with other commands. For example,dd if=/dev/urandom bs=1 count=10 | hexdump.