Linux/unix DD command is a very good management disk command
DD Command function: A block of a specified size copies a file and, at the same time as a copy, a specified conversion, playing the role of an initialization disk
1. Introduction to the Order
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
If=file
Enter a filename, which defaults to standard input.
Of=file
The output file name, which defaults to standard output.
Ibs=bytes
Read bytes bytes 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
At the same time, the size of the read-write block 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
Skips blocks blocks from the start of the input file before copying.
Seek=blocks
Skips blocks blocks from the start of the output file before copying. (usually only works if the output file is 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 a file with the specified parameters.
Conversion parameters:
ASCII conversion EBCDIC to ASCII.
EBCDIC converts ASCII to EBCDIC.
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. Do not take the entire instruction
Sync fills each input block to IBS bytes, and the insufficient part is padded with empty (NUL) characters.
DD Application Example
1. Backup local/dev/hdb whole disk to/DEV/HDD
DD if=/dev/hdb f=/dev/hdd hdb–> memory-> HDD
This paper url:http://www.bianceng.cn/os/linux/201410/45618.htm
2./dev/hdb The overall data back to the specified path image file
DD if=/dev/hdb f=/root/image hdb–> memory-> image file
3. Restore the backup file to the specified disk
DD if=/root/image f=/dev/hdb image file –> memory-> HDB
4. Backup/DEV/HDB overall data, and use the Gzip tool to compress, 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 F=/dev/hdb
6.512-byte MBR master boot record information to the specified file at the beginning of the backup disk
DD If=/dev/hda f=/root/image count=1 bs=512 read 512 bytes from hard disk 0 cylinder 0 Track 1 sectors by default
Count=1 refers to copying only one block, and the bs=512 block size is 512 bytes.
Recovery: DD If=/root/image F=/dev/hda
7. Backup floppy disk
DD if=/dev/fd0 f=disk.img count=1 bs=1440k (i.e. block size 1.44M)
8. Copy the contents of the memory to the hard disk
DD If=/dev/mem F=/root/mem.bin bs=1024 (Specify block size of 1k)
9. Copy the contents of the CD to the specified folder and save it as a cd.iso image file
DD If=/dev/cdrom (HDC) Of=/root/cd.iso
10. Increase Swap partition file size
First step: Create a file size of 256M:
DD If=/dev/zero of=/swapfile bs=1024 count=262144
Step Two: Turn this file into swap swap partition file:
Mkswap/swapfile
Step three: Enable this swap partition file:
Swapon/swapfile
Fourth step: Edit the/etc/fstab file so that the swap partition file is automatically loaded at each boot:
/swapfile Swap default 0 0
11. Destroying disk data
DD If=/dev/urandom F=/DEV/HDA1
Note: Using random data to populate a hard disk can be used to destroy data on some necessary occasions.
12. Test hard disk read and write speed
DD If=/dev/zero bs=1024 count=1000000 f=/root/1gb.file Write speed
DD If=/root/1gb.file bs=64k | DD F=/dev/null Read speed
The read and write speed of the hard drive can be computed by the command execution time of the above two commands.
13. Determine the best block blocks size of the hard disk: Initialize the hard drive
DD If=/dev/zero bs=1024 count=1000000 f=/root/1gb.file initialize the hard drive
DD If=/dev/zero bs=2048 count=500000 f=/root/1gb.file initialize the hard drive
DD If=/dev/zero bs=4096 count=250000 f=/root/1gb.file initialize the hard drive
DD If=/dev/zero bs=8192 count=125000 f=/root/1gb.file initialize the hard drive
By comparing the command execution times shown in the above command output, you can determine the optimal block size for the system.
14. Repair hard disk: Self-initialized hard drive
DD IF=/DEV/SDA F=/DEV/SDA SCSI hard drive or DD If=/dev/hda F=/dev/hda IDE
When the hard disk is not used for a long time (more than one year), the magnetic flux point electromagnetic dot phenomenon is generated on the disk, which is difficult when the head is read to these areas and may cause I/O errors. When this situation affects the first sector of the hard disk, the MBR (Master bootstrapper 446, hard disk partition table 64, hard disk Identification 2 bytes), the hard disk may be scrapped. The commands above may bring the data back to the dead. And the process is safe and efficient.