dd seem an unfriendly command, but if you start to use it, you’ll see that it’s a powerful command able to do many different things, backup a partition, CD or USB stick for example or do some simple tests on the speed of your disks or your CPU.
The man page say:
dd is an application that will “convert and copy a file”
But let’s see some trick with it.
The GNU clone of
dd is part of fileutils package, and i’d say that any Linux should have it installed.
Unlike most Unix commands,
dd uses a keyword=value format for its parameters.
The dd utility copies the specified input file to the specified output with possible conversions. The standard input and output are used by default. The input and output block sizes may be specified to take advantage of raw physical I/O. Sizes are specified in bytes; a number may end with k, b, or w to specify multiplication by 1024, 512, or 2, respectively. Numbers may also be separated by x to indicate multiplication.
So the basic options are:
if= file Specifies the input path. Standard input is the default.
of= file Specifies the output path. Standard output is the default.
# dd if=/dev/sda of=/dev/sdb
This command will do the exact copy of /dev/sda in /dev/sdb.
#dd if=/dev/dvd of=dvd.iso
This command will do a copy of the DVD in the file dvd.iso
#dd if=/dev/zero of=/dev/sda
Fill partition /dev/sda with zero, useful to wipe out a phisical (or logical) partition.
# dd if=/dev/hda | gzip > hda.img.gz
This command will do a copy of /dev/hda and piping it through the gzip compression program.
Add the Block Size and the number of blocks
dd you can use also 2 important parameters :
bs= n Sets both input and output block sizes to n bytes.
count= n Copies only n input blocks.
# dd if=/dev/zero of=/dev/null bs=1M count=32768 32768+0 records in 32768+0 records out 34359738368 bytes (34 GB) copied, 2.64483 s, 13.0 GB/s
This command give you a Processor/memory bandwidth in GB/s (in the example, a VPS on linode.com)
#dd if=/dev/sda of=/home/sam/MBR.image bs=512 count=1
This command creates an image of the entire master boot record (including the partition table).
#dd if=/dev/zero bs=1024 count=1000000 of=/home/sam/1Gb.file #dd if=/home/sam/1Gb.file bs=64k | dd of=/dev/null
These commands can be used to do a drive benchmark test and analyze the sequential read and write performance for 1024 byte blocks.
Seek and Skip
These 2 options are a bit less common but can be used to do particular tasks.
skip= n Skips n input blocks (using the specified input block size) before starting to copy. On seekable files, the implementation reads the blocks or seeks past them. On non-seekable files, the blocks are read and the data is discarded.
seek= n Skips n blocks (using the specified output block size) from beginning of output file before copying.
#dd if=/dev/mem bs=1k skip=768 count=256 2>/dev/null | strings -n 8
This command display BIOS Information read the memory from C:0000 to F:FFFF without the need of dmidecode.
#dd bs=1k if=image.nrg of=image.iso skip=300
This command converts a Nero Image File to ISO removing the 300k header from a Nero image file converting it to ISO format
This is just a small overview of the more common options for
dd, there is also the option convert that permits to convert a lot of different file formats, perhaps it will be the topic of another article.
- None Found
Find me on Google+