Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Dd (Unix)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Examples == The examples below apply to many implementations, but are specifically written for GNU dd. Generally, the only difference between implementations is block size values and can be portable by using shell arithmetic expression instead of a size multiplier suffix. For example, instead of {{code|1=bs=64M}} use {{code|1=bs=$((64*1024*1024))|2=bash}} or {{code|1=bs=$((64 << 20))|2=bash}}. === Data transfer === The command can duplicate data across files, devices, partitions and volumes, and it can transform data during transfer as specified via option {{code|conv}}. In some cases, data transfer is faster with {{code|cat}}.<ref name="relevant" /> To create an [[ISO image|ISO]] [[disk image]] from a [[compact disc|CD-ROM]], [[DVD]] or [[Blu-ray]] disc:<ref>{{cite web | url=https://wiki.archlinux.org/title/Optical_disc_drive#Creating_an_ISO_image_from_a_CD,_DVD,_or_BD | title=Creating an ISO image from a CD, DVD, or BD | work=ArchWiki | accessdate=April 18, 2022 | archive-date=April 18, 2022 | archive-url=https://web.archive.org/web/20220418171303/https://wiki.archlinux.org/title/Optical_disc_drive#Creating_an_ISO_image_from_a_CD,_DVD,_or_BD | url-status=live }}</ref> <syntaxhighlight lang="bash"> blocks=$(isosize -d 2048 /dev/sr0) dd if=/dev/sr0 of=isoimage.iso bs=2048 count=$blocks status=progress </syntaxhighlight> To restore a drive from an image file: <syntaxhighlight lang="bash"> dd if=system.img of=/dev/sdc bs=64M conv=noerror </syntaxhighlight> To create an image of partition sdb2, using a 64 MiB block size: <syntaxhighlight lang="bash"> dd if=/dev/sdb2 of=partition.image bs=64M conv=noerror </syntaxhighlight> To [[Disk cloning|clone]] one [[Disk partitioning|partition]] to another: <syntaxhighlight lang="bash"> dd if=/dev/sda2 of=/dev/sdb2 bs=64M conv=noerror </syntaxhighlight> To clone drive ad0 to ad1; ignoring any errors: <syntaxhighlight lang="bash"> dd if=/dev/ad0 of=/dev/ad1 bs=64M conv=noerror </syntaxhighlight> === In-place modification{{anchor|data modification}} === The command can modify data in place. For example, this overwrites the first 512 bytes of a file with null bytes: <syntaxhighlight lang="bash"> dd if=/dev/zero of=path/to/file bs=512 count=1 conv=notrunc </syntaxhighlight> Option {{code|conv{{=}}notrunc}} requests to not truncate the output file. That is, if the output file already exists, replace the specified bytes and leave the rest of the output file as-is. Without this option, the command would create an output file 512 bytes long. === Master boot record backup and restore === The example above can also be used to backup and restore any region of a device to a file; including a [[master boot record]]. To duplicate the first two sectors of a floppy disk: <syntaxhighlight lang="bash"> dd if=/dev/fd0 of=MBRboot.img bs=512 count=2 </syntaxhighlight> === Disk wipe === {{Main|Data erasure}} For security reasons, it is sometimes necessary to have a [[disk wipe]] of a discarded device. This can be achieved by a "data transfer" from the Unix special files. * To write ''zeros'' to a disk, use <code>dd if=[[/dev/zero]] of=[[/dev/sda]] bs=16M</code>. * To write ''random data'' to a disk, use <code>dd if=[[/dev/urandom]] of=[[/dev/sda]] bs=16M</code>. When compared to the data modification example [[#Data modification|above]], {{code|notrunc}} conversion option is not required as it has no effect when the output file is a block device.<ref>{{cite web |url=https://stackoverflow.com/questions/20526198/why-using-conv-notrunc-when-cloning-a-disk-with-dd |title=linux - Why using conv=notrunc when cloning a disk with dd? |publisher=Stack Overflow |date=2013-12-11 |access-date=2014-03-24 |archive-date=2014-03-24 |archive-url=https://web.archive.org/web/20140324201126/http://stackoverflow.com/questions/20526198/why-using-conv-notrunc-when-cloning-a-disk-with-dd |url-status=live }}</ref> Option {{code|bs{{=}}16M}} makes dd read and write 16 [[mebibytes]] at a time. For modern systems, an even greater block size may be faster. Note that filling the drive with random data may take longer than zeroing the drive, because the random data must be created by the CPU, while creating zeroes is very fast. On modern hard-disk drives, zeroing the drive will render most data it contains permanently irrecoverable.<ref>{{cite conference | last1 = Wright | first1 = Craig S. | last2 = Kleiman | first2 = Dave | last3 = S. | first3 = Shyaam Sundhar R. | editor1-last = Sekar | editor1-first = R. | editor2-last = Pujari | editor2-first = Arun K. | contribution = Overwriting Hard Drive Data: The Great Wiping Controversy | doi = 10.1007/978-3-540-89862-7_21 | pages = 243β257 | publisher = Springer | series = Lecture Notes in Computer Science | title = Information Systems Security, 4th International Conference, ICISS 2008, Hyderabad, India, December 16-20, 2008. Proceedings | volume = 5352 | year = 2008}}</ref> However, with other kinds of drives such as flash memories, much data may still be recoverable by [[data remanence]]. Modern [[hard disk drive]]s contain a [[Secure Erase]] command designed to permanently and securely erase every accessible and inaccessible portion of a drive. It may also work for some [[solid-state drive]]s (flash drives). As of 2017, it does not work on [[USB flash drive]]s nor on [[Secure Digital]] flash memories.{{citation needed|date=August 2017}} When available, this is both faster than using dd, and more secure.{{citation needed|date=August 2017}} On [[Linux]] machines it is accessible via the [[hdparm]] command's {{code|--security-erase-enhanced}} option. The [[shred (Unix)|shred]] program offers multiple overwrites, as well as more secure deletion of individual files. === Data recovery === [[Data recovery]] involves reading from a drive with some parts potentially inaccessible. The command is a good fit with this job with its flexible skipping ({{code|seek}}) and other low-level settings. The vanilla {{code|dd}}, however, is clumsy to use as the user has to read the error messages and manually calculate the regions that can be read. The single block size also limits the granularity of the recovery, as a trade-off has to be made: either use a small one for more data recovered or use a large one for speed. A C program called ''dd_rescue''<ref>{{cite web|url=http://www.garloff.de/kurt/linux/ddrescue/|title=dd_rescue|work=garloff.de|access-date=2006-11-10|archive-date=2001-05-16|archive-url=https://web.archive.org/web/20010516091650/http://www.garloff.de/kurt/linux/ddrescue/|url-status=live}}</ref> was written in October 1999. It did away with the conversion functionality of {{code|dd}}, and supports two block sizes to deal with the dilemma. If a read using a large size fails, it falls back to the smaller size to gather as much as data possible. It can also run backwards. In 2003, a ''dd_rhelp'' script was written to automate the process of using ''dd_rescue'', keeping track of what areas have been read on its own.<ref>{{cite web|url=http://www.kalysto.org/utilities/dd_rhelp/index.en.html|title=dd_rhelp author's repository|author=LAB Valentin|date=19 September 2011|quote=Important note : For some times, dd_rhelp was the only tool (AFAIK) that did this type of job, but since a few years, it is not true anymore: Antonio Diaz did write a ideal replacement for my tool: GNU 'ddrescue'.|access-date=13 May 2008|archive-date=16 May 2008|archive-url=https://web.archive.org/web/20080516231947/http://www.kalysto.org/utilities/dd_rhelp/index.en.html|url-status=live}}</ref> In 2004, GNU wrote a separate utility, unrelated to {{code|dd}}, called [[ddrescue]]. It has a more sophisticated dynamic block-size algorithm and keeps track of what has been read internally. The authors of both ''dd_rescue'' and ''dd_rhelp'' consider it superior to their implementation.<ref>{{cite web|url=https://www.gnu.org/software/ddrescue/ddrescue.html|title=Ddrescue - GNU Project - Free Software Foundation (FSF)|work=gnu.org|access-date=2016-07-22|archive-date=2021-07-02|archive-url=https://web.archive.org/web/20210702144117/https://www.gnu.org/software/ddrescue/ddrescue.html|url-status=live}}</ref> To help distinguish the newer GNU program from the older script, alternate names are sometimes used for GNU's ''ddrescue'', including ''addrescue'' (the name on freecode.com and freshmeat.net), ''gddrescue'' ([[Debian]] package name), and ''gnu_ddrescue'' ([[openSUSE]] package name). Another open-source program called ''savehd7'' uses a sophisticated algorithm, but it also requires the installation of [[Seed7|its own programming-language interpreter]]. === Benchmark drive performance === To make drive benchmark test and analyze the sequential (and usually single-threaded) system read and write performance for 1024-byte blocks: * Write performance: <code>dd if=[[/dev/zero]] bs=1024 count=1000000 of=1GB_file_to_write</code> * Read performance: <code>dd if=1GB_file_to_read of=[[/dev/null]] bs=1024</code> === Generate a file with random data === To make a file of 100 random bytes using the random driver: <syntaxhighlight lang="bash"> dd if=/dev/urandom of=myrandom bs=100 count=1 </syntaxhighlight> === Convert a file to upper case === To convert a file to uppercase: <syntaxhighlight lang="bash"> dd if=filename of=filename1 conv=ucase,notrunc </syntaxhighlight> === Progress feedback === On request, the command reports progress. When it receives signal {{code|USR1}} ({{code|INFO}} on BSD systems), it writes the number of transferred blocks to standard error. The following bash script requests progress every 10 seconds until the transfer completes. The text ''PID'' stands for the {{code|dd}} process identifier. <syntaxhighlight lang="bash"> while kill -USR1 PID ; do sleep 10 ; done </syntaxhighlight> Newer versions of GNU ''dd'' support the option {{code|status{{=}}progress}} which enables periodic status feedback.<ref name=gnu_invok>{{cite web |url=https://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html |title=GNU Coreutils: dd invocation |website=The GNU Operating System and the Free Software Movement |access-date=2019-08-26 |archive-date=2019-08-22 |archive-url=https://web.archive.org/web/20190822014954/http://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html |url-status=live }}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)