Linux system DD Command use method Encyclopedia

Source: Internet
Author: User
Tags manual lowercase

DD is a very useful command under Linux/unix to copy a file with a block of a specified size and to make a specified conversion at the same time as a copy.

Name: DD

Use rights: All user dd This instruction is defined in manual as convert and copy a file

How to use:

DD [option]

If you want to see manual online, try:

Info DD

If you want to see how this version is:

Input or output
DD If=[stdin] Of=[stdout]

Force input or output size to how many bytes

How many Bytes are you forced to do at a time?

Skip a paragraph before outputting

Skip a paragraph before entering

Of course you can use this to easily copy discs (Note that your disc is a standard iso9660 format to do so!) )

DD If=/dev/cdrom Of=cdrom.iso
The contents of the if and after are adjusted according to your requirements.

Then give the system the instructions to burn:

Cdrecord-v Cdrom.iso
This is not about Cdrecord, so the instructions above are the simplest but not necessarily compatible with your hardware environment ...
Function: Copies the specified input file to the specified output file, and can be converted to format during the copy process. You can use this command to realize the function of the diskcopy command under DOS. First use the DD command to write the data on the floppy disk as a storage file, and then put the storage file into the second floppy disk, complete the function of diskcopy. It should be noted that the storage files on the hard disk should be removed with the RM command. The system defaults to using standard input files and standard output files.

Syntax: DD [Options]

if = input file (or device name).

of = output file (or device name).

ibs = Bytes Read bytes bytes at a time, that is, the number of bytes read into the buffer.

Skip = Blocks skips the Ibs*blocks block at the beginning of the read buffer.

Obs = bytes Writes bytes bytes At a time, that is, the number of bytes written to the buffer.

BS = bytes Sets the number of bytes in the read/write buffer (equal to setting IBS and OBS).

CBS = byte convert bytes byte at a time.

Count=blocks only copies the input blocks blocks.

Conv = ASCII converts EBCDIC code to Ascil code.

Conv = EBCDIC converts ascil code to EBCDIC code.

CONV = IBM converts ascil code to alternate EBCDIC code.

CONV = block Converts a bit of change to a fixed character.

CONV = Ublock Converts a fixed bit into a change bit.

CONV = UCase converts letters from lowercase to uppercase.

CONV = LCase converts letters from uppercase to lowercase.

CONV = Notrunc does not truncate the output file.

CONV = Swab Exchange Each pair of input bytes.

CONV = NoError does not stop processing when an error occurs.

Conv = sync the size of each input record to the size of the IBS (filled with nul).

Main options for DD:

The place where the number is specified is multiplied by the corresponding number at the end of the following character:

b=512, C=1, k=1024, w=2, Xm=number m

Enter a filename, which defaults to standard input.

The output file name, which defaults to standard output.

Read bytes bytes at a time (that is, a block size of bytes bytes).

Write bytes bytes at a time (that is, a block size of bytes bytes).

At the same time, the size of the read-write block is bytes, which can replace IBS and OBS.

Converts bytes bytes at a time, that is, the size of the conversion buffer.

Skips blocks blocks from the start of the input file before copying.

Skips blocks blocks from the start of the output file before copying. (usually only works if the output file is disk or tape.)

Copies only blocks blocks, and the block size equals the number of bytes specified by IBS.

Conv=conversion[,conversion ...]
Converts a file with the specified parameters.

Conversion parameters:

ASCII conversion EBCDIC to ASCII.
IBM converts ASCII to alternate EBCDIC.
Block converts each line into a record length of CBS, with less than a space filled in.
Unblock the length of each row is CBS, and the less part is filled with spaces.
LCase converts uppercase characters to lowercase characters.
UCase converts lowercase characters to uppercase characters.
Swab exchange input for each pair of bytes.
NoError does not stop when an error occurs.
Notrunc does not truncate the output file.
Sync fills each input block to IBS bytes, and the insufficient part is padded with empty (NUL) characters.

2. Example Analysis

2.1. Data backup and Recovery

Backup and recovery of 2.1.1 Whole disk data

DD IF=/DEV/HDX Of=/dev/hdy
Back up the local/DEV/HDX whole disk to/dev/hdy

DD IF=/DEV/HDX Of=/path/to/image
/DEV/HDX The overall data back to the image file of the specified path

DD IF=/DEV/HDX | Gzip >/path/to/image.gz
Back up/DEV/HDX overall data and use the Gzip tool to compress and save to the specified path

DD If=/path/to/image OF=/DEV/HDX
Restore the backup file to the specified disk

gzip-dc/path/to/image.gz | DD OF=/DEV/HDX
Restores a compressed backup file to a specified disk

2.1.2. Remote Backup with Netcat

DD If=/dev/hda bs=16065b | Netcat < TARGETHOST-IP > 1234
Perform this command backup on the source host/dev/hda

Netcat-l-P 1234 | DD OF=/DEV/HDC bs=16065b
Executes 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 purpose of the host instruction changes using BZIP2 gzip to compress the data, and save the backup file in the current directory.

2.1.3. Backup MBR
DD IF=/DEV/HDX of=/path/to/image count=1 bs=512
The backup disk starts with the 512Byte size of MBR information to the specified file

DD If=/path/to/image OF=/DEV/HDX
Write back up the MBR information to the beginning of the disk

2.1.4. Backup floppy disk
DD if=/dev/fd0 of=disk.img count=1 bs=1440k
Back up the floppy drive data to the Disk.img file in the current directory

2.1.5. Copy memory data to hard disk
DD If=/dev/mem Of=/root/mem.bin bs=1024
Copy the data in memory to the Mem.bin file in the root directory

2.1.6. Copy ISO image from CD
DD If=/dev/cdrom Of=/root/cd.iso
Copy the disc data to the root folder and save it as a Cd.iso file

2.2. Increase the size of the swap partition file
DD If=/dev/zero of=/swapfile bs=1024 count=262144
Create a file that is large enough (256M here)

Turn this file into a swap file

Enable this swap file

/swapfile Swap Defaults 0 0
Automatically load the swap file every time you turn on, you need to add a row to the/etc/fstab file

2.3. Destroying disk data

DD If=/dev/urandom OF=/DEV/HDA1
The use of random data to fill the hard disk, in some necessary occasions can be used to destroy data. After you do this, the/dev/hda1 will not mount, and the Create and copy operations cannot be performed.

2.4 Disk Management

2.4.1. Get the most appropriate block size
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
The optimal block size of the system can be determined by comparing the command execution time shown in the DD instruction output

2.4.2 Test hard drive Read and write speed

DD If=/root/1gb.file bs=64k | DD Of=/dev/null
DD If=/dev/zero of=/root/1gb.file bs=1024 count=1000000
The read/write speed of the test hard disk can be computed by the execution time of the two command output

2.4.3. Repair the hard drive

Magnetic flux point is generated on the disk when the hard drive is not used for a long time (for example, 1, 2 years). When the head is read to these areas, it encounters difficulties and can cause I/O errors. When this condition affects the first sector of the hard disk, it may cause the hard drive to scrap. The commands above may bring the data back to the dead. And the process is safe and efficient.

All right, here we are. About the Linux system DD command is finished, this article is a very detailed tutorial.

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: 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.