dd is a very useful command under Linux/UNIX to copy a file with a block of the specified size and perform the specified conversion while copying
After the dd command is executed, the speed of copying data during dd will be printed. Therefore, many people use dd to test the I/O of the disk. I hope to use the result as a reference data, compared with different service providers or different hardware configurations. Disk read and write capabilities. Although an average speed is displayed after the command is executed, no information is displayed during execution, which causes the operator to wait in an endless stream when copying large files.
This article will introduce the progress of observing the running dd, I hope this method is helpful to everyone.
Step 1: Create a new window and find the PID corresponding to the current dd command.
The code is as follows: pgrep -l '^dd$'.pgrep -l '^ Dd$'
The result:
8269 dd.8269 dd
Step 2: Send the USR1 instruction to the dd process
The code is as follows: kill -USR1 8269.kill -USR1 8269 At this point, you will see the size of the data that has been copied and the speed per second in the window where the dd command is being executed.
Of course, if you only have one dd process executing, you can also use the following command:
The code is as follows: kill -USR1 `pgrep ^dd`.kill -USR1 `pgrep ^dd`
If you can't wait, you can use this command to output every second:
The code is as follows: watch -n1 'sudo kill -USR1 `pgrep ^dd`'.watch -n1 'sudo kill -USR1 `pgrep ^dd`'
Of course, you can also do this, and when you execute the dd command, let him automatically output:
The code is as follows: dd if=/dev/zero of=/home/test & pid=$!; while [[ -d /proc/$pid ]]; do kill -USR1 $pid && sleep 1 && clear; done.dd if=/dev/zero of=/home/test & pid=$!; while [[ -d /proc/$pid ]] ; do kill -USR1 $pid && sleep 1 && clear; done
dd Parameter Explanation
1. if=filename: input file name, default is standard Input. That is, specify the source file. < if=input file >
2. of=filename: The output file name, the default is standard output. That is, specify the destination file. < of=output file >
3. ibs=bytes: Read bytes bytes at a time, that is, specify a block size of bytes.
obs=bytes: Output bytes bytes at a time, that is, specify a block size of bytes.
bs=bytes: Also set the read/output block size to bytes.
4. cbs=bytes: Convert bytes bytes at a time, that is, specify the size of the conversion buffer.
5. skip=blocks: Skip the blocks from the beginning of the input file and start copying.
6. seek=blocks: Skips the blocks from the beginning of the output file and starts copying.
Note: It is usually only valid when the output file is a disk or tape, that is, it is valid when backing up to disk or tape.
7. count=blocks: Copy only blocks, the block size is equal to the number of bytes specified by ibs.
8. conv=conversion: Convert files with the specified parameters.
ascii: Convert ebcdic to ascii
ebcdic: convert ascii to ebcdic
ibm: convert ascii to alternate ebcdic
block: convert each line to The length is cbs, the insufficient part is filled with spaces
unblock: make each line length cbs, the insufficient part is filled with spaces
lcase: convert uppercase characters to lowercase characters
ucase: converts lowercase characters to uppercase characters
swab: swaps each pair of bytes of input
noerror: does not stop when an error occurs
notrunc: does not truncate output File
sync: fills each input block to ibs bytes, and the insufficient portion is filled with null (NUL) characters.
Some application examples of dd
1. Back up the local /dev/hdb disk to /dev/hdd
The code is as follows: dd If=/dev/hdb of=/dev/hdd.dd if=/dev/hdb of=/dev/hdd
2. Back up the /dev/hdb full disk data to the image file of the specified path
The code is as follows: dd if=/dev/hdb of=/root/image.dd if=/dev/hdb of=/root/image
3. Will be backed up File recovery to the specified disk
The code is as follows: dd if=/root/image of=/dev/hdb.dd if=/root/image of=/dev/hdb
4. Back up /dev/hdb full disk data, and use gzip tool to compress and save to the specified path
The code is as follows: dd if=/dev/hdb |
Gzip > /root/image.gz.dd if=/dev/hdb |
Gzip > /root/image.gz
5. Restore the compressed backup file to the specified disk
The code is as follows: gzip -dc /root/image.gz |
Dd of=/dev/hdb.gzip -dc /root/image.gz |
Dd of=/dev/hdb
6. Back up the 512-byte MBR information from the disk to the specified file
The code is as follows: dd if=/dev/hda of=/root /image count=1 bs=512 #count=1 means copying only one block; bs=512 means that the block size is 512 bytes. #恢: dd if=/root/image of=/dev/hda.
7.Backup floppy disk
The code is as follows: dd if=/dev/fd0 of =disk.img count=1 bs=1440k #(ie block size is 1.44M).dd if=/dev/fd0 of=disk.img count=1 bs=1440k #(ie block size is 1.44M)
8. Copy the contents of the memory to the hard disk
The code is as follows: dd if=/dev/mem of=/root/mem.bin bs=1024 #(Specify the block size is 1k ).dd if=/dev/mem of=/root/mem.bin bs=1024 #(Specify the block size is 1k)
9. Copy the contents of the disc to the specified folder and save it as cd.iso File
The code is as follows: dd if=/dev/cdrom(hdc) of=/root/cd.iso.dd if=/dev/cdrom(hdc) of=/root/Cd.iso
10. Increase the size of the swap partition file
The code is as follows: #Step: Create a file with a size of 256M: dd if=/dev/zero of=/swapfile bs =1024 count=262144 #Step 2: Turn this file into a swap file: mkswap /swapfile #Step 3: Enable this swap file: swapon /swapfile #Step 4: Edit the /etc/fstab file so that every time The swap file is automatically loaded at boot time: /swapfile swap swap default 0 0 .#Step 1: Create a file with a size of 256M: dd if=/dev/zero of=/swapfile bs=1024 count=262144 #Step 2: Turn this file into a swap file: mkswap /swapfile #third Step: Enable this swap file: swapon /swapfile #Step 4: Edit the /etc/fstab file to automatically load the swap file each time you boot: /swapfile swap swap default 0 0
11. Destroy the disk The data
code is as follows: dd if=/dev/urandom of=/dev/hda1 #Note: Fill the hard disk with random data, which can be used to destroy data in some necessary occasions. .dd if=/dev/urandom of=/dev/hda1 #Note: Fill the hard drive with random data and use it to destroy the data if necessary.
12. Test the read and write speed of the hard disk
The code is as follows: dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file dd if=/root/1Gb.file bs=64k |
Dd of=/dev/null #The command execution time output by the above two commands can calculate the read and write speed of the hard disk. .dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file dd if=/root/1Gb.file bs=64k |
Dd of=/dev/null #The command execution time output by the above two commands can calculate the read and write speed of the hard disk.
13. Determine the optimal block size of the hard disk:
The code is as follows: 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 # By comparing the command execution time displayed in the above command output, you can determine the optimal block size of the system. .
14. Repairing the hard disk
The code is as follows: dd if=/dev/sda of=/dev/sda.dd if=/dev/sda of=/dev/sda
When the hard disk is left unused for a long time (for example, 1, 2 years), a magnetic fluxpoint is generated on the disk. When the head reads these areas, it encounters difficulties and may cause I/O errors. When this situation affects the first sector of the hard disk, it may cause the hard disk to be scrapped. The above command has the potential to bring these data back to life. And this process is safe and efficient.
The process is simply a process of executing a program, it is a dynamic concept. No matter what sys
Today, I suddenly had a whim and wanted to experience Mac Os. I heard that the virtual machine inst
DevOps is the key to more and more large companies and organizations, so it is important for us to r
Matthew Garrett, Core Developer from Red Hat, publishes a detailed article on Fedora 18. It will int
How to re-hang the mongo replica set slave server for a long time to re-attach to the set
Linux and Windows function battle open source system
Teach you to query the time when installing Win7 system
The program does not have MySQL reports on the Linux server. Error
Making embedded Linux file system with busybox
Automotive industry dealing with the Linux operating system
Linux shell awk get external variables (variable value) Introduction
Webmail Roundcube installation configuration basic tutorial
Realize linux and windows file transfer
Win 7 and iPhone do not get into trouble with Intel chipset
Can my XP be upgraded to Windows 7?
WinXP: Do not pass the secret technology summary
How Win10 changes folder icons to distinguish between different roles
How to set the system to automatically restart when the system has a blue screen
Two points that are most likely to be wrong in mass production U disk
Vista system, remember to use Comodo time machine to restore
What should I do if the system changes card after Win7 exits the game?