DD Command Explanation

Source: Internet
Author: User


DD command
DD: Copies a file with a block of the specified size and makes the specified conversion at the same time as the copy.

The place where the number is specified is multiplied by the corresponding number if it ends with the following characters: b=512;c=1;k=1024;w=2

Parameter comment:

if= file name: Enter a file name, default to standard input. The source file is specified. < If=input file >
of= file name: Output file name, default is standard output. That is, the specified destination file. < Of=output file >
Ibs=bytes: Reads a bytes byte at a time, which specifies a block size of bytes bytes.
Obs=bytes: Outputs bytes bytes at a time, that is, specifying a block size of bytes bytes.
Bs=bytes: Set the read/output block size to bytes bytes at the same time.
Cbs=bytes: Converts bytes bytes at a time, that is, specifies the conversion buffer size.
Skip=blocks: Skips blocks blocks from the beginning of the input file before copying begins.
Seek=blocks: Skips blocks blocks from the beginning of the output file before copying begins.
Note: Usually only works when the output file is a disk or tape, that is, when backing up to disk or tape.
Count=blocks: Copies only blocks blocks, the block size equals the number of bytes specified by IBS.
Conv=conversion: Transforms the file with the specified parameters.
ASCII: convert EBCDIC to ASCII
EBCDIC: convert ASCII to EBCDIC
IBM: Convert ASCII to alternate EBCDIC
Block: Converts each row to a CBS length, with less space padding
Unblock: Make each line the length of the CBS, the less part filled with spaces
LCase: Converting uppercase characters to lowercase characters
UCase: Converting lowercase characters to uppercase characters
Swab: Swap each byte of the input
NoError: Do not stop when error occurs
Notrunc: Output File not truncated
Sync: Fills each input block into IBS bytes, and the less part is padded with empty (NUL) characters.

DD Application:

1. Back up the local/dev/hdb full disk to the/DEV/HDD
DD If=/dev/hdb OF=/DEV/HDD

2. Back up the/DEV/HDB full data to the image file of the specified path
DD If=/dev/hdb Of=/root/image

3. Restore the backup file to the specified disk
DD If=/root/image OF=/DEV/HDB

4. Back up the/DEV/HDB full data and compress it with the Gzip tool to save to the specified path
DD If=/dev/hdb | gzip >/root/image.gz

5. Restore the compressed backup file to the specified disk
gzip-dc/root/image.gz | DD Of=/dev/hdb

6. Backup and restore MBR

The backup disk starts with 512 byte-sized MBR information to the specified file:
DD If=/dev/hda of=/root/image count=1 bs=512

Count=1 refers to copying only one block; bs=512 refers to a block size of 512 bytes.

Recovery:
DD If=/root/image Of=/dev/had

Writes the backed up MBR information to the disk start section
7. Backup floppy disk
DD if=/dev/fd0 of=disk.img count=1 bs=1440k (i.e. block size 1.44M)

8. Copy the memory contents to the hard disk
DD If=/dev/mem Of=/root/mem.bin bs=1024 (Specify block size 1k)

9. Copy the contents of the disc to the specified folder and save it as a Cd.iso file
DD If=/dev/cdrom (HDC) Of=/root/cd.iso

10. Increase the size of the swap partition file

The first step: Create a file of size 256M:
DD If=/dev/zero of=/swapfile bs=1024 count=262144

Step Two: Turn this file into a swap file:
Mkswap/swapfile

Step three: Enable this swap file:
Swapon/swapfile

Fourth step: Edit the/etc/fstab file to automatically load swap files at each boot:

/swapfile Swap swap default 0 0

11. Destroying disk data
DD If=/dev/urandom OF=/DEV/HDA1

Note: Populating the hard disk with random data can be used to destroy the data in some necessary situations.

12. Test the read/write speed of the hard drive
DD If=/dev/zero bs=1024 count=1000000 of=/root/1gb.file
DD If=/root/1gb.file bs=64k | DD Of=/dev/null

With the command execution time of the above two commands output, the read and write speed of the hard disk can be calculated.

13. Determine the optimal block size for your hard drive:

DD If=/dev/zero bs=1024 count=1000000 of=/root/1gb.file
DD If=/dev/zero bs=2048 count=500000 of=/root/1gb.file
DD If=/dev/zero bs=4096 count=250000 of=/root/1gb.file
DD If=/dev/zero bs=8192 count=125000 of=/root/1gb.file

By comparing the execution time of the command shown in the above command output, you can determine the optimal block size for the system.

14. Repair the hard drive:
DD IF=/DEV/SDA OF=/DEV/SDA or DD If=/dev/hda Of=/dev/hda

When the hard disk is placed unused for a longer period of time (more than one year), magnetic flux point is generated on the disk, which can cause difficulties when the heads are read to these areas and may result in I/O errors. When this condition affects the first sector of the hard disk, it may cause the hard disk to retire. The above command may bring the data back to the dead. And the process is safe and efficient.

15. Remote Backup with Netcat
DD If=/dev/hda bs=16065b | Netcat < TARGETHOST-IP > 1234

Perform this command on the source host backup/dev/hda
Netcat-l-P 1234 | DD OF=/DEV/HDC bs=16065b

Execute this command on the destination host to receive data and write to/DEV/HDC
Netcat-l-P 1234 | bzip2 > Partition.img
Netcat-l-P 1234 | gzip > Partition.img

The above two instructions are the change of the destination host instruction using BZIP2, gzip to compress the data, and save the backup file in the current directory.

16. Change the value of byte I in a large video file to 0x41 (that is, the ASCII value of capital a)

echo A | DD of=bigfile seek= $i Bs=1 count=1 conv=notrunc

DD Command Explanation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.