Linux DD command

Source: Internet
Author: User

DD is A very useful command under Linux/UNIX, which is to copy a file with a block of the specified size and make the specified conversion at the same time as the copy.

Engrave the image of Arch Linux into a USB flash drive /dev/sdc :

lgl@pArch ~/Downloads $ sudo dd if=archlinux-2016.04.01-dual.iso of=/dev/sdc bs=512k

At this point, in another shell, we enter:

lgl@pArch ~ $ sudo watch -n 5 pkill -USR1 ^dd$

Or:

-n 5 pkill -USR1 -x dd

The current terminal will then display:

5.0s: pkill -USR1 -x dd

At this point, the terminal using the DD command will show the progress:

Other application ExamplesEdit 1. Back up the local/dev/hdb full disk to the/DEV/HDD DD if=/dev/hdb OF=/DEV/HDD 2. Back up the/DEV/HDB full data to the image file of the specified path DD if=/dev/hdb of=/root/image 3. Restore the backup file to the specified disk DD If=/root/image of=/dev/hdb 4. Back up the/DEV/HDB full data and compress it with the Gzip tool to 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 of=/dev/hdb 6. Backup disk starts with 512 byte-sized MBR information to the specified file DD If=/dev/hda of=/root/image count=1 bs=512 count=1 refers to copying only one block; bs=512 refers to a block size of 512 bytes. Recovery: DD If=/root/image Of=/dev/hda 7. Backup floppy Disk DD if=/dev/fd0 of=disk.img count=1 bs=1440k (that is, block size is 1.44M) 8. Copy the memory contents to the hard disk DD If=/dev/mem of=/root/mem.bin bs=1024 (Specify a block size of 1k) 9. Copy the contents of the disc to the specified folder and save it as a Cd.iso file DD If=/dev/cdrom (HDC) Of=/root/cd.iso 10. Increase the size of the swap partition file The first step: Create a file of size 256M: DD If=/dev/zero of=/swapfile bs=1024 count=262144 Step Two: Turn this file into a swap file: Mkswap/swapfile Step three: Enable this swap file: Swapon/swapfile Fourth Step: Edit the/etc/fstab file to automatically load swap files at each boot: /swapfile Swap swap defaults 0 0 11. Destroying disk data DD If=/dev/urandom of=/dev/hda1 Note: Populating the hard disk with random data can be used to destroy the data in some necessary situations. 12. Test the read/write speed of the hard drive DD If=/dev/zero bs=1024 count=1000000 of=/root/1gb.file DD if=/root/1gb.file bs=64k | DD of=/dev/null with the command execution time of the above two commands output, the read and write speed of the hard disk can be calculated. 13. Determine the optimal block size for your hard drive: 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 execution time of the command shown in the above command output, you can determine the optimal block size for the system. 14. Repairing the hard drive DD IF=/DEV/SDA OF=/DEV/SDA When the hard disk is not used for a long time (for example, 1, 2 years), magnetic fluxpoint will be generated on the disk. When the heads read these areas, they encounter difficulties and can cause 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.dd command to make USB boot disk DD If=xxx.iso of=/dev/sdb bs=1m root user or sudo, with the above command must be uninstalled u disk, SDB is your u disk, bs=1m is the size of the block, behind the value of large, write speed relative to a bit, but also not unlimited, I generally choose 2M, note, the execution of the command after a block of completion, but the U disk is still flashing, and so does not flash, Safely removed.

Linux DD command

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.