· 8 years ago · Apr 10, 2018, 07:20 PM
1
2Data transfer forms of dd
3
4blocks=$(isosize -d 2048 /dev/sr0)
5dd if=/dev/sr0 of=isoimage.iso bs=2048 count=$blocks status=progress
6
7 Creates an ISO disk image
8from a CD-ROM, DVD or Blu-ray disk.[8]
9
10dd if=system.img of=/dev/sdc bs=4096 conv=noerror
11
12 Restores a hard disk drive
13(or an SD card, for example)
14from a previously created image.
15
16dd if=/dev/sda2 of=/dev/sdb2 bs=4096 conv=noerror
17
18 Clones one partition to another.
19
20dd if=/dev/ad0 of=/dev/ad1 bs=1M conv=noerror
21
22 Clones a hard disk drive "ad0" to "ad1".
23
24Master boot record backup and restore
25
26It is possible to repair a master boot record. It can be transferred to and from a repair file.
27
28To duplicate the first two sectors of a floppy drive:
29
30dd if=/dev/fd0 of=MBRboot.img bs=512 count=2
31
32To create an image of the entire x86 master boot record (including a MS-DOS partition table and MBR magic bytes):
33
34dd if=/dev/sda of=MBR.img bs=512 count=1
35
36To create an image of only the boot code of the master boot record (without the partition table and without the magic bytes required for booting):
37
38dd if=/dev/sda of=MBR_boot.img bs=446 count=1
39
40Data modification
41
42dd can modify data in place. For example, this overwrites the first 512 bytes of a file with null bytes:
43
44dd if=/dev/zero of=path/to/file bs=512 count=1 conv=notrunc
45
46The notrunc conversion option means do not truncate the output file — that is, if the output file already exists, just replace the specified bytes and leave the rest of the output file alone. Without this option, dd would create an output file 512 bytes long.
47
48To duplicate a disk partition as a disk image file on a different partition:
49
50dd if=/dev/sdb2 of=partition.image bs=4096 conv=noerror
51
52Disk wipe
53Main article: Data erasure
54
55For security reasons, it is sometimes necessary to have a disk wipe of a discarded device.
56
57To wipe a disk by writing zeros to it, dd can be used this way:
58
59dd if=/dev/zero of=/dev/sda bs=16M
60
61Another approach could be to wipe a disk by writing random data to it:
62
63dd if=/dev/urandom of=/dev/sda bs=16M
64
65When compared to the data modification example above, notrunc conversion option is not required as it has no effect when the dd's output file is a block device.[9]
66
67The bs=16M option 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.[10] However, with other kinds of drives such as flash memories, much data may still be recoverable by special laboratory techniques.[citation needed]
68
69Modern hard disk drives 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 drives (flash drives). As of 2017, it does not work on USB flash drives nor on Secure Digital flash memories.[citation needed] When available, this is both faster than using dd, and more secure.[citation needed] On Linux machines it is accessible via the hdparm command's --security-erase-enhanced option.
70
71The shred program offers multiple overwrites as well as more-secure deletion of individual files.
72
73Data recovery
74
75The early history of open-source software for data recovery and restoration of files, drives and partitions included the GNU dd, whose copyright notice starts in 1985,[11] with one block size per dd process, and no recovery algorithm other than the user's interactive session running one form of dd after another. Then, a C program called dd_rescue[12] was written in October 1999, having two block sizes in its algorithm. However, the author of the 2003 shell script dd_rhelp, which enhances dd_rescue's data recovery algorithm, recommends GNU ddrescue,[13][14] a data recovery program unrelated to dd that was initially released in 2004.
76
77To 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 its own programming-language interpreter.
78Benchmarking drive performance
79
80To make drive benchmark test and analyze the sequential (and usually single-threaded) system read and write performance for 1024-byte blocks:
81
82dd if=/dev/zero bs=1024 count=1000000 of=file_1GB
83dd if=file_1GB of=/dev/null bs=1024
84
85Generating a file with random data
86
87To make a file of 100 random bytes using the kernel random driver:
88
89dd if=/dev/urandom of=myrandom bs=100 count=1
90
91Converting a file to upper case
92
93To convert a file to uppercase:
94
95dd if=filename of=filename1 conv=ucase,notrunc
96
97Limitations
98
99As stated in a part of documentation provided by Seagate, "certain disc utilities, such as DD, which depend on low-level disc access may not support 48-bit LBAs until they are updated".[15][citation needed] Using ATA hard disk drives over 128 GiB in size requires system support 48-bit LBA; however, in Linux, dd uses the kernel to read or write to raw device files instead of accessing hardware directly.[b] At the same time, support for 48-bit LBA has been present since version 2.4.23 of the kernel, released in 2003.[16][17]
100Dcfldd
101
102dcfldd is a fork of dd that is an enhanced version developed by Nick Harbour, who at the time was working for the United States' Department of Defense Computer Forensics Lab.[18][19][20] Compared to dd, dcfldd allows for more than one output file, supports simultaneous multiple checksum calculations, provides a verification mode for file matching, and can display the percentage progress of an operation.
103See also
104
105 Free software portal Information technology portal
106
107 Backup
108 Disk cloning
109 Disk Copy
110 Disk image
111 .img (filename extension)
112 List of Unix programs
113 ddrescue a GNU version that copies data from corrupted files