Linux command-dd {copy and replace}

Source: Internet
Author: User

An order explains:

DD: Copies a file with a block of the specified size and makes the specified conversion at the same time as the copy.

Note: Where the number is specified, the number is multiplied by the following character: b=512;c=1;k=1024;w=2

Parameter comment:

  1. if= file name: Enter a file name, default to standard input. The source file is specified. < If=input file >
  2. of= file name: Output file name, default is standard output. That is, the specified destination file. < Of=output file >
  3. Ibs=bytes: Reads a bytes byte at a time, which specifies a block size of bytes bytes.
    Obs=bytes: Outputs bytes bytes at a time, that is, specifying a block size of bytes bytes.
    Bs=bytes: Set the read/output block size to bytes bytes at the same time.
  4. Cbs=bytes: Converts bytes bytes at a time, that is, specifies the conversion buffer size.
  5. Skip=blocks: Skips blocks blocks from the beginning of the input file before copying begins.
  6. Seek=blocks: Skips blocks blocks from the beginning of the output file before copying begins.
    Note: Usually only works when the output file is a disk or tape, that is, when backing up to disk or tape.
  7. Count=blocks: Copies only blocks blocks, the block size equals the number of bytes specified by IBS.
  8. Conv=conversion: Transforms the file with the specified parameters.
      • ebcdic: Convert ASCII to EBCDIC
      • IBM: Convert ASCII to alternate EBCDIC
      • unblock: The length of each row is CBS, the insufficient portion is filled with spaces
      • lcase: Converting uppercase characters to lowercase characters
      • swab: Swap each pair of bytes of input
      • noerror: Do not stop on error
      • notrunc: The output file is not truncated
      • sync: Fills each input block into IBS bytes, The insufficient part is padded with empty (NUL) characters.

Two application examples:

1. Back up the local/dev/hdb disk to/dev/hdd[email protected]: DD if=/dev/hdb of=/dev/hdd2. To back up the/DEV/HDB full data to the image file of the specified path [email Protected]:d D if=/dev/hdb of=/root/image3. Restore the backup file to the specified disk [email protected]:d D if=/root/image of=/dev/hdb4. Backup/dev/ HDB overall data, and useGzip tool to compress, save to specified path [email protected]:d D if=/dev/hdb | gzip >/root/image.gz5. Restore a compressed backup file to a specified disk [email protected]:gzip-dc/root/image.gz | DD OF=/DEV/HDB6. Backup and restore MBR backup disk starting with 512 byte-sized MBR information to the specified file: [email protected]:d d if=/dev/hda of=/root/image count=1 bs= 512count=1 refers to copying only one block; bs=512 refers to a block size of 512 bytes. Restore: [email protected]:d D If=/root/image Of=/dev/had writes the backed up MBR information to the disk Start section 7. backup floppy [email protected]:d D if=/dev/fd0 of= Disk.img Count=1 bs=1440k (i.e. block size 1.44M) 8. Copy memory contents to HDD [email protected]:d D if=/dev/mem Of=/root/mem.bin bs=1024 (Specify block size 1k) 9. Copy the contents of the disc to the specified folder and save it asCd.iso file [email protected]:d D if=/dev/cdrom (HDC) of=/root/cd.iso10. Increase swap partition file size The first step: Create a file of size 256M: [Email protected] :d d if=/dev/zero of=/swapfile bs=1024 count=262144 Step Two: Turn this file into a swap file: [email protected]:Mkswap/swapfile Step three: Enable this swap file: [email protected]:Swapon/swapfile Fourth: Edit the/etc/fstab file to automatically load swap files on each boot:/swapfile Swap swap default 0 011. destroying disk data [email protected]: DD If=/dev/urandom of=/dev/hda1 Note: Using random data to populate the hard disk, in some necessary occasions can be used to destroy data. 12. Test drive read/write speed [email protected]:d D if=/dev/zero bs=1024 count=1000000 of=/root/1gb.file[email protected]: DD If=/root/1gb.file bs=64k | DD Of=/dev/null The output of the above two command execution time, you can calculate the read and write speed of the hard disk. 13. Determine the optimal block size for the hard drive: [email protected]:d D if=/dev/zero bs=1024 count=1000000 of=/root/1gb.file[email protected] :d d if=/dev/zero bs=2048 count=500000 of=/root/1gb.file[email protected]:d d if=/dev/zero bs=4096 count=250000 of= /root/1gb.file[email protected]:d d if=/dev/zero bs=8192 count=125000 of=/root/ 1gb.file determines the optimal block size for the system by comparing the execution time of the command shown in the output of the above command. 14. Repair the hard drive: [email protected]:d D if=/dev/sda OF=/DEV/SDA or DD If=/dev/hda Of=/dev/hda when the hard drive is not used for a longer period of time (more than one year) Magnetic flux point is generated on the disk, which can cause difficulties when the heads read to these areas, and may result in 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. 15. Usenetcat remote Backup [email protected]:d d If=/dev/hda bs=16065b | netcat < targethost-IP > 1234 Perform this command backup on the source host/dev/hda[ Email protected]:netcat-l-P 1234 | DD OF=/DEV/HDC bs=16065b executes this command on the destination host to receive data and write/dev/hdc[email protected]:netcat-l-P 1234 | bzip2 > Partition.img[email protected]:netcat-l-P 1234 | gzip > partition.img  

Linux command-dd {copy and replace}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.