Difference between revisions of "Dd (command)"

From wikieduonline
Jump to navigation Jump to search
Tags: Mobile web edit, Mobile edit
 
(9 intermediate revisions by the same user not shown)
Line 6: Line 6:
 
:<code>oflag=sync</code><ref>https://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html#dd-invocation</ref>
 
:<code>oflag=sync</code><ref>https://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html#dd-invocation</ref>
 
:<code>iflag=[fullblock|nocache]</code>
 
:<code>iflag=[fullblock|nocache]</code>
 
+
:<code>conv=notrunc,noerror</code><ref>https://askubuntu.com/a/227933</ref>. notrunc is only important to prevent truncation when writing into a file. This has no effect on a block device such as sda or sdb<ref>https://stackoverflow.com/a/20531600</ref>
  
 
== Examples ==
 
== Examples ==
 
* Write a 10G file with random data: 10 G (<code>bs=10G count=1</code>), with random data (<code>[[/dev]]/[[urandom]]</code>)<ref>https://superuser.com/a/470957</ref>:
 
* Write a 10G file with random data: 10 G (<code>bs=10G count=1</code>), with random data (<code>[[/dev]]/[[urandom]]</code>)<ref>https://superuser.com/a/470957</ref>:
<code>dd iflag=fullblock if=/dev/[[urandom]] of=sample_output_file.txt bs=10G count=1 status=progress</code>
+
<code>dd iflag=fullblock if=/dev/[[urandom]] of=sample_output_file.txt bs=10G count=1 status=[[progress]]</code>
 
<pre>
 
<pre>
 
  10737418240 bytes (11 GB, 10 GiB) copied, 66 s, 162 MB/s
 
  10737418240 bytes (11 GB, 10 GiB) copied, 66 s, 162 MB/s
Line 17: Line 17:
 
  10737418240 bytes (11 GB, 10 GiB) copied, 66.4367 s, 162 MB/s
 
  10737418240 bytes (11 GB, 10 GiB) copied, 66.4367 s, 162 MB/s
 
</pre>
 
</pre>
 +
status=progress not supported on [[macOS]]
  
* Write a 10G with zeroes: 10 G (<code>bs=10G count=1</code>), file with "zeroes" (<code>/dev/zero</code>):
+
* Write a 10G with zeroes: 10 G (<code>bs=10G count=1</code>), file with "zeroes" (<code>[[/dev/zero]]</code>):
 
<code>dd iflag=fullblock if=[[/dev/zero]] of=sample_output_file.txt bs=10G count=1 status=progress</code>
 
<code>dd iflag=fullblock if=[[/dev/zero]] of=sample_output_file.txt bs=10G count=1 status=progress</code>
 
<pre>
 
<pre>
Line 32: Line 33:
 
</pre>
 
</pre>
  
* if=/dev/vda | [[gzip -1]] | ssh your.server.com dd of=/mnt/storage/imagename.img.gz
+
* <code>if=/dev/vda | [[gzip -1]] | ssh your.server.com dd of=/mnt/storage/imagename.img.gz</code>
  
  
* Clone an [[SD card]]<ref>https://askubuntu.com/questions/227924/sd-card-cloning-using-the-dd-command</ref>
+
* [[Clone an SD card with dd]]
:1) Copy content: <code>sudo dd if=/dev/sdt of=~/sd-card-clone.img</code>
 
:2) Change card
 
:3) Overwrite card with copied image: <code>sudo dd if=~/sd-card-copy.img of=[[/dev/]]sdt</code>
 
  
 
== Activities ==
 
== Activities ==
Line 47: Line 45:
  
 
Advanced
 
Advanced
# Understand iflags, such us fullblock <code>iflag=fullblock</code> meaning
+
# Understand iflags, such us [[fullblock]] <code>iflag=fullblock</code> meaning
 
# Try to interrupt/kill your command: <code>dd iflag=fullblock if=/dev/urandom of=sample_output_file.txt bs=10G count=1</code> and explain outcome.
 
# Try to interrupt/kill your command: <code>dd iflag=fullblock if=/dev/urandom of=sample_output_file.txt bs=10G count=1</code> and explain outcome.
  
Line 56: Line 54:
 
* {{cp}}
 
* {{cp}}
 
* {{Io performance commands}}
 
* {{Io performance commands}}
* [[pv]]
+
* {{pv}}
 
* [[Benchmarking tools]]
 
* [[Benchmarking tools]]
 
* {{files}}
 
* {{files}}

Latest revision as of 10:21, 21 September 2020

dd[1][2] is a command-line utility for Linux and Unix-like operating systems used to copy or create files on block devices (HDD).

Warning: write operations will not ask for confirmation if you are overwriting an existing file.

Options:

oflag=sync[3]
iflag=[fullblock|nocache]
conv=notrunc,noerror[4]. notrunc is only important to prevent truncation when writing into a file. This has no effect on a block device such as sda or sdb[5]

Examples[edit]

  • Write a 10G file with random data: 10 G (bs=10G count=1), with random data (/dev/urandom)[6]:

dd iflag=fullblock if=/dev/urandom of=sample_output_file.txt bs=10G count=1 status=progress

 10737418240 bytes (11 GB, 10 GiB) copied, 66 s, 162 MB/s
 1+0 records in
 1+0 records out
 10737418240 bytes (11 GB, 10 GiB) copied, 66.4367 s, 162 MB/s
status=progress not supported on macOS
  • Write a 10G with zeroes: 10 G (bs=10G count=1), file with "zeroes" (/dev/zero):

dd iflag=fullblock if=/dev/zero of=sample_output_file.txt bs=10G count=1 status=progress

 10737418240 bytes (11 GB, 10 GiB) copied, 66 s, 162 MB/s
 1+0 records in
 1+0 records out
 10737418240 bytes (11 GB, 10 GiB) copied, 66.4367 s, 162 MB/s
dd iflag=fullblock if=/dev/zero of=sample_output_file.txt bs=10G count=1
dd: memory exhausted by input buffer of size 10737418240 bytes (10 GiB)
  • if=/dev/vda | gzip -1 | ssh your.server.com dd of=/mnt/storage/imagename.img.gz


Activities[edit]

Basic

  1. Write a 10GB file with random data and review your disk performance: dd iflag=fullblock if=/dev/urandom of=sample_output_file.txt
  2. Read Linux I/O Performance Tests using dd: https://www.thomas-krenn.com/en/wiki/Linux_I/O_Performance_Tests_using_dd
  3. /Benchmark disk performance using dd/

Advanced

  1. Understand iflags, such us fullblock iflag=fullblock meaning
  2. Try to interrupt/kill your command: dd iflag=fullblock if=/dev/urandom of=sample_output_file.txt bs=10G count=1 and explain outcome.

Related terms[edit]

See also[edit]

  • http://man7.org/linux/man-pages/man1/dd.1.html
  • https://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html#dd-invocation
  • https://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html#dd-invocation
  • https://askubuntu.com/a/227933
  • https://stackoverflow.com/a/20531600
  • https://superuser.com/a/470957
  • Advertising: