Linux DD command parameters and usage details---Copy a file with a block of the specified size (you can also backup the whole disk)

Source: Internet
Author: User

Linux DD command parameters and usage details---Copy a file with a block of the specified sizeDate: 2010-06-14 click: 3830 Source: Unknown share to:

The Linux dd command uses a detailed

Main options for DD:

Specify the number of digits at the end of the following character multiplied by the corresponding number:

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

if=File

Enter a file name, which defaults to standard input.

Of=file

The output file name, which defaults to standard output.

Ibs=bytes

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

Obs=bytes

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

Bs=bytes

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

Cbs=bytes

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

Skip=blocks

Skip blocks blocks from the beginning of the input file before copying begins.

Seek=blocks

Skip blocks blocks from the beginning of the output file before copying begins. (typically only valid if the output file is a disk or tape).

Count=blocks

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

Conv=conversion[,conversion ...]

Converts the file with the specified parameters.

Conversion parameters:

The ASCII conversion EBCDIC is ASCII.

EBCDIC converts ASCII to EBCDIC.

IBM converts ASCII to alternate EBCDIC.

Block converts each row to a cbs-length record, and the insufficient portion is padded with spaces.

Unblock the length of each line is CBS, and the insufficient portion is padded with spaces.

LCase converts uppercase characters to lowercase characters.

UCase converts lowercase characters to uppercase characters.

Swab swap each byte of the input.

NoError does not stop when an error occurs.

NotruNC does not truncate the output file.

Sync fills each input block into IBS bytes, and the less part is padded with empty (NUL) characters.

2. Example Analysis

2.1. Data backup and Recovery

2.1.1 Full disk data backup and recovery
Backup:

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


DD IF=/DEV/HDX Of=/path/to/image
To back up the/DEV/HDX full data to the image file of the specified path


DD IF=/DEV/HDX | Gzip >/path/to/image.gz
Backup/DEV/HDX full data and compress with gzip tool to save to specified path


Recovery:
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. Using netcat remote Backup


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.

2.1.3. Backing up the MBR
Backup:

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


Recovery:

DD If=/path/to/image OF=/DEV/HDX
Writes the backed up MBR information to the disk start section

2.1.4. Backing up floppy disks

DD if=/dev/fd0 of=disk.img count=1 bs=1440k
Backing up floppy data to the current directory's disk.img file

2.1.5. Copying memory data to the hard disk

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

2.1.6. Copy ISO image from disc

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)


Mkswap /swapfile
Turn this file into a swap file.


swapon /swapfile
Enable this swap file


/swapfile swap swap defaults 0 0
Automatically load swap files on each boot, adding a line to the/etc/fstab file

2.3. Destroying disk data

DD If=/dev/urandom OF=/DEV/HDA1
The use of random data to populate the hard disk, in some necessary occasions can be used to destroy data. After you do this, the/dev/hda1 cannot be mounted, 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 best block size for the system can be determined by comparing the command execution time shown in the output of the DD instruction.


2.4.2 Test 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 drive can be calculated by the execution time of the last two command outputs.


2.4.3. Repairing the hard drive

DD IF=/DEV/SDA OF=/DEV/SDA
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 heads read these areas, they encounter difficulties and can cause 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.

Http://www.linuxso.com/command/dd.html

Linux DD command parameters and usage details---Copy a file with a block of the specified size (you can also backup the whole disk)

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.