Linux System Management and Maintenance - dd Command

  

Function Description: Convert or copy files, and backup the device at the same time.

Use format: dd if="input_file" of="output_file" bs="block_size" count="number" Option Description: if: is the input file, can be a device, such as a disk A partition or the entire disk. Of: is the output file, but also the output device, such as disk, tape, and so on. Bs: Specifies the size of a block. If not specified, the default is 512 bytes. Count: is the number of <;bs“. Example: 1. Back up the /etc/inittab file to /opt/inittab.bak and use the following command: [root@mylinux ~]# dd if=/etc/inittab of=/opt/inittab.bak3+1 records in3+1 records out [root@mylinux ~]#ls –al /etc/inittab /opt/inittab.bak-rw-r--r-- 1 root root 1666 Jul 22 17:37 /etc/inittab-rw-r--r -- 1 root root 1666 Jul 23 08:09 /opt/inittab.bak# Note that the above two files, the size does not have any similarities and differences, are 1666 bytes, because the size is not specified, "bs", so the default is 512 bytes A unit block, just above the above "3+1", that is: 3 means that there are 3 complete blocks of 512 bytes, and "1"" means that block of less than 512 bytes. 2. Back up the entire partition of /dev/sda2 and save the backup file to the /opt directory. Use the following command: [root@mylinux ~]# dd if=/dev/sda2 of=/opt/sda2.back#here is the disk The data of all partitions is backed up, and the dd command can also back up the data of the entire disk. The backup output path here must not be the partition of “/dev/sda2“ otherwise, it can't be backed up. 3. Restore the backup package /opt/sda2.back in the above example to the appropriate partition, using the following command: [root@mylinux ~]#dd if=/opt/sda2.back of=/dev/sda2#Special attention, in When restoring the target partition, be sure to uninstall the target partition first. After the recovery is complete, mount it. # Also note that the backup partition is best aligned with the restored partition. For example, in this example, the /opt/sda6.back” file is a backup of the partition of "/dev/sda2", so the most recovery Restore the "/opt/sda6.back” file to the &devquo;/dev/sda2” partition, or restore to a partition that is the same size as “/dev/sda2”. Because the restored target partition is larger than the partition at the time of backup, space will be wasted; on the contrary, the recovery target partition is smaller than the backup partition, and the space will be insufficient when the recovery is performed.

Copyright © Windows knowledge All Rights Reserved