From Gentoo Wiki
Jump to: navigation, search


dd is a utility used to copy raw data from source to sink, where source and sink can be a block device, file, or piped input/output.


As part of the GNU sys-apps/coreutils, is installed in any standard any Gentoo GNU/Linux system.


In the event that coreutils goes missing:

root #emerge --ask sys-apps/coreutils


By default dd takes input from stdin, optionally manipulates the data, and writes to stdout.


Some common tasks where dd is used:

Boot stick

This should work with any live media as long as the memory stick /dev/sdX is large enough.

Any data on the memory stick will be lost.
root #dd if=/home/myLiveCD.iso of=/dev/sdX bs=8M
  • if: Defines the source.
  • of: Defines the sink.
  • bs: Defines the block size (amount of data read/written at a time). The default is 512 bytes but most modern devices can read/write much faster. It is possible to define different sizes for source and sink using ibs and obs.

Master boot record backup

To backup the master boot record (MBR), copy only the first 512 bytes:

root #dd if=/dev/sdX of=/root/mbr.bin bs=512 count=1
  • count: The number of blocks to copy.
This is the complete MBR with the partition layout.

Input manipulation

As an example, convert any upper case character in a file to lowercase and reverse the input per line, then pipe the output to less to display the file:

user $dd if=/etc/portage/make.conf conv=swab,lcase,noerror | less
  • conv=swab: Revert the input per line by swapping any input byte (writing backwards).
  • conv=lcase: Convert any upper case letter to lower case. To convert lower case to upper case use conv=ucase.
  • conv=noerror: Continue if a read error occurs.

See also

  • Dcfldd — an enhanced dd tool that includes additional features for forensics and security.
  • Ddrescue — a tool provided by GNU to retrieve data from failing (block) storage devices like disk drives, CDROMs, or memory sticks, etc.
  • Pv — a tool to view verbose information about data streamed/piped through it.