DD Command Feature
Copies the specified input file to the specified output file and can be formatted for conversion 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.
DD Command Use method
DD [Options]
For example:
DD If=/dev/zero Of=/tmp/swap BS=1MB count=1024
data backup and recovery
Backup and recovery of 2.1.1 Whole disk data
Backup:
DD IF=/DEV/HDX of=/dev/hdy #将本地的/DEV/HDX full disk Backup to/dev/hdy
DD IF=/DEV/HDX of=/path/to/image #将/DEV/HDX full data Backup to the image file on the specified path
DD IF=/DEV/HDX | Gzip >/path/to/image.gz
#备份/DEV/HDX The overall data and use the Gzip tool to compress and save to the specified path
Recovery:
DD If=/path/to/image OF=/DEV/HDX #将备份文件恢复到指定盘
gzip-dc/path/to/image.gz | DD OF=/DEV/HDX #将压缩的备份文件恢复到指定盘
2.1.2. Remote Backup with Netcat
DD If=/dev/hda bs=16065b | Netcat < TARGETHOST-IP > 1234 #在源主机上执行此命令备份/dev/hda
Netcat-l-P 1234 | DD OF=/DEV/HDC bs=16065b #在目的主机上执行此命令来接收数据并写入/DEV/HDC
Netcat-l-P 1234 | bzip2 > Partition.img
Netcat-l-P 1234 | gzip > Partition.img
#以上两条指令是目的主机指令的变化分别采用bzip2 gzip to compress the data and save the backup file in the current directory.
2.1.3. Backup MBR
Backup: 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
Recovery: 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 #创建一个足够大的文件 (256M)
Mkswap/swapfile #把这个文件变成swap文件
Swapon/swapfile #启用这个swap文件
/swapfile Swap defaults 0 0 #在每次开机的时候自动加载swap文件, you need to add one line 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
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 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.
DD Command Parameter Introduction
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.