Linux Command-dd {copy and replace}, linux-dd
1. Command explanation:
Dd: Use a block of the specified size to copy an object and perform the specified conversion at the same time.
Note: If the following column ends with a specified number, multiply it by the corresponding number: B = 512; c = 1; k = 1024; w = 2
Parameter notes:
- Ascii: Convert ebcdic to ascii
- Ebcdic: Convert ascii to ebcdic
- Ibm: Convert ascii to alternate ebcdic
- Block: converts each row to the length of cbs. spaces are used to fill the remaining parts.
- Unblock: the length of each row is cbs, and the remaining part is filled with spaces.
- Lcase: converts uppercase to lowercase.
- Ucase: converts lowercase to uppercase.
- Swab: swap each pair of input bytes
- Noerror: Do not stop when an error occurs
- Notrunc: the output file is not truncated.
- Sync: Fill each input block into ibs bytes, and fill the remaining part with null (NUL) characters.
2. Application Example:
1. back up the local/dev/hdb disk to/dev/hddheng @ me: dd if =/dev/hdb of =/dev/hdd2. back up the full data of/dev/hdb to the image file heng @ me in the specified path: dd if =/dev/hdb of =/root/image3. restore the backup file to the specified disk heng @ me: dd if =/root/image of =/dev/hdb4. back up the full data of/dev/hdb, compress it with gzip, and save it to the specified path heng @ me: dd if =/dev/hdb | gzip>/root/image.gz 5. restore the compressed backup file to the specified disk heng @ me: gzip-dc/root/image.gz | dd of =/dev/hdb6. back up and restore the MBR information of the first 512 bytes starting from the MBR backup disk to the specified file: heng @ me: dd if =/dev/hda of =/root/image Count = 1 bs = 512 count = 1 indicates that only one block is copied; bs = 512 indicates that the block size is 512 bytes. Restore: heng @ me: dd if =/root/image of =/dev/had write the backup MBR information to the start part of the disk. backup floppy disk heng @ me: dd if =/dev/fd0 of = disk. img count = 1 bs = 1440 k (Block Size: 1.44 MB) 8. copy the memory content to the hard disk heng @ me: dd if =/dev/mem of =/root/mem. bin bs = 1024 (specify the block size as 1 k) 9. copy the content of the cd to the specified folder and save it as cd. iso file heng @ me: dd if =/dev/cdrom (hdc) of =/root/cd. iso10. increase the size of the swap partition file Step 1: create a file with a size of MB: heng @ me: dd if =/dev/zero of =/swapfile bs = 1024 count = 262144 Step 2: change this file to a swap file: heng @ me: mkswap/swapfile Step 3: Enable this swap file: heng @ me: swapon/swapfile Step 4: edit the/etc/fstab file so that the swap file is automatically loaded at each boot: /swapfile swap default 0 011. destroy disk data heng @ me: dd if =/dev/urandom of =/dev/hda1 Note: using random data to fill the hard disk can be used to destroy data in some necessary scenarios. 12. test hard disk read/write speed heng @ me: dd if =/dev/zero bs = 1024 count = 1000000 of =/root/1 GB. fileheng @ me: dd if =/root/1 GB. file bs = 64 k | dd of =/dev/null the command execution time output by the preceding two commands can calculate the Read and Write speeds of the hard disk. 13. determine the optimal disk size: heng @ me: dd if =/dev/zero bs = 1024 count = 1000000 of =/root/1 GB. fileheng @ me: dd if =/dev/zero bs = 2048 count = 500000 of =/root/1 GB. fileheng @ me: dd if =/dev/zero bs = 4096 count = 250000 of =/root/1 GB. fileheng @ me: dd if =/dev/zero bs = 8192 count = 125000 of =/root/1 GB. file: Compare the command execution time shown in the preceding command output to determine the optimal Block Size of the system. 14. hard Disk repair: heng @ me: dd if =/dev/sda of =/dev/sda or dd if =/dev/hda of =/dev/hda when the hard disk is longer (more than one year) after the disk is not used, magnetic flux point is generated on the disk. When the head reads these areas, it may encounter difficulties and may cause I/O errors. When this affects the first sector of the hard disk, the hard disk may be decommissioned. The above command may bring these data back to life. This process is safe and efficient. 15. use netcat to remotely back up heng @ me: dd if =/dev/hda bs = 16065b | netcat <targethost-ip> 1234 run this command on the source host to back up/dev/hdaheng @ me: netcat-l-p 1234 | dd of =/dev/hdc bs = 16065b execute this command on the target host to receive data and write it to/dev/hdcheng @ me: netcat-l-p 1234 | bzip2> partition. imgheng @ me: netcat-l-p 1234 | gzip> partition. img