Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Data transfer forms of dd
- blocks=$(isosize -d 2048 /dev/sr0)
- dd if=/dev/sr0 of=isoimage.iso bs=2048 count=$blocks status=progress
- Creates an ISO disk image
- from a CD-ROM, DVD or Blu-ray disk.[8]
- dd if=system.img of=/dev/sdc bs=4096 conv=noerror
- Restores a hard disk drive
- (or an SD card, for example)
- from a previously created image.
- dd if=/dev/sda2 of=/dev/sdb2 bs=4096 conv=noerror
- Clones one partition to another.
- dd if=/dev/ad0 of=/dev/ad1 bs=1M conv=noerror
- Clones a hard disk drive "ad0" to "ad1".
- Master boot record backup and restore
- It is possible to repair a master boot record. It can be transferred to and from a repair file.
- To duplicate the first two sectors of a floppy drive:
- dd if=/dev/fd0 of=MBRboot.img bs=512 count=2
- To create an image of the entire x86 master boot record (including a MS-DOS partition table and MBR magic bytes):
- dd if=/dev/sda of=MBR.img bs=512 count=1
- To 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):
- dd if=/dev/sda of=MBR_boot.img bs=446 count=1
- Data modification
- dd can modify data in place. For example, this overwrites the first 512 bytes of a file with null bytes:
- dd if=/dev/zero of=path/to/file bs=512 count=1 conv=notrunc
- The 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.
- To duplicate a disk partition as a disk image file on a different partition:
- dd if=/dev/sdb2 of=partition.image bs=4096 conv=noerror
- Disk wipe
- Main article: Data erasure
- For security reasons, it is sometimes necessary to have a disk wipe of a discarded device.
- To wipe a disk by writing zeros to it, dd can be used this way:
- dd if=/dev/zero of=/dev/sda bs=16M
- Another approach could be to wipe a disk by writing random data to it:
- dd if=/dev/urandom of=/dev/sda bs=16M
- When 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]
- The 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]
- Modern 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.
- The shred program offers multiple overwrites as well as more-secure deletion of individual files.
- Data recovery
- The 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.
- 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 its own programming-language interpreter.
- Benchmarking drive performance
- To make drive benchmark test and analyze the sequential (and usually single-threaded) system read and write performance for 1024-byte blocks:
- dd if=/dev/zero bs=1024 count=1000000 of=file_1GB
- dd if=file_1GB of=/dev/null bs=1024
- Generating a file with random data
- To make a file of 100 random bytes using the kernel random driver:
- dd if=/dev/urandom of=myrandom bs=100 count=1
- Converting a file to upper case
- To convert a file to uppercase:
- dd if=filename of=filename1 conv=ucase,notrunc
- Limitations
- As 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]
- Dcfldd
- dcfldd 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.
- See also
- Free software portal Information technology portal
- Backup
- Disk cloning
- Disk Copy
- Disk image
- .img (filename extension)
- List of Unix programs
- ddrescue a GNU version that copies data from corrupted files
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement