1Disk Management1.1DD1.1.1function Description
read, convert and output Data .
1.1.2Grammar
DD [bs=<Number of bytes;] [cbs=<Number of bytes;] [conv=<Key Words;] [count=<Number of blocks;] [ibs=<Number of bytes;] [if=<file;] [obs=<Number of bytes;] [of=<file;] [seek=<Number of blocks;] [skip=<Number of blocks;] [--help] [--version]
1.1.3Additional Information
DD can read data from a standard input or file, convert data in a specified format, and then output to a file, device, or standard output.
1.1.4Parameters
bs=< bytes > IBS ( input ) to obs ( output ) is set to the specified number of bytes.
cbs=< bytes > conversions, only the specified number of bytes is converted at a time.
conv=< keyword > Specifies how the file is converted.
Conv = ASCII converts the 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 the change bit to a fixed character.
CONV = Ublock Converts the fixed bit into a change bit.
CONV = UCase Converts the letter from lowercase to uppercase.
CONV = LCase converts letters from uppercase to lowercase.
CONV = Notrunc does not truncate the output file.
CONV = swab swaps each pair of input bytes.
CONV = NoError does not stop processing when an error occurs.
Conv = Sync puts the size of each input record to the size of the IBS (filled with NUL ).
count=< number of blocks > Read Only the specified number of chunks.
ibs=< bytes > number of bytes read each time.
if=< file > read from file.
obs=< number of bytes > bytes per output.
of=< file > output to file.
seek=< number of blocks > First output, skips the specified number of chunks.
skip=< blocks > skips the specified number of chunks when it starts reading.
--help Help.
--version Displays version information.
1.1.5Example
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. 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.
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
4. Backup floppy disk
DD if=/dev/fd0 of=disk.img count=1 bs=1440k
Backing up floppy data to the current directory's disk.img file
5. copy memory data to 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
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
7. 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 ( 256Mhere)
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
8. 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.
9. 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.
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.
Repair 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.
This article is from "Dream" blog, please be sure to keep this source http://snbo520.blog.51cto.com/3069187/1412114