Linux Backup:hard Disk Clone with "DD"

Source: Internet
Author: User

Most of the Windows users may know "Norton Ghost". Norton Ghost is a backup software for hard disks. It can backup a whole hard disk or a partition to an image file. Also, Norton Ghost can copy all of the contents from a hard disk to another exactly. However, Norton Ghost is a Windows software, users on other operating system (such as Linux) can does enjoy its powerful FU Nction. Fortunately, most of the Unix/linux operating system provides a command line whose function are similar to Norton Ghost, it's Called "DD".

In fact, the "DD" is much powerful than Norton Ghost. You can use many arguments to control it. In this short article, we are concern on how to backup a whole hard disk or a partition.

Hard Disk Clone

Suppose you has a 40GB hard disk and a removable hard disk whose capacity are 60GB, and you want to backup all the files F Rom the hard disk to the removable disk. With "DD", it's a very easy task. Again, suppose your hard disk ' s Unix device name IS/DEV/SDA and the removable disk is/dev/sdb. The following command can copy all the content FROM/DEV/SDA To/dev/sdb:

DD IF=/DEV/SDA OF=/DEV/SDB

Here, if= ... sets the source and of= ... sets the destination. "dd" doesn ' t care for the contents of the hard disk. It just reads bytes From/dev/sda and writes them into/dev/sdb. It doesn ' t know what is files. So, the hard disk file system and how many partitions it have is not important. For example, IF/DEV/SDA are splitted into three partitions, THE/DEV/SDB would have the same partitions. i.e. "destination" is completely same with "source".

Notice:to Execute "DD" you should login as "root" or switch to "root" using "su" command. And you must is careful, a small mistake may cause a serious problem!

Making a hard Disk Image File

Most of the time you don ' t want the complete duplication of the your hard disk. Prefer to creating a image file of the hard disk and save it in other storage devices. The following command would create an image of file "Disk1.img" in your user ' s directory FROM/DEV/SDA:

DD IF=/DEV/SDA of=~/disk1.img

Since you are created an image file, you can compress it with "gzip" or "bzip2":

gzip disk1.img #generates disk1.img.gz or

bzip2 disk1.img #generates disk1.img.bz2

You can save much storage space with compression. But it'll take very long time.

Partition Clone

Backing up a hard disk partition are much similar to backing up a whole hard disk. The reason is that Unix/linux uses device name, such as/dev/sda1,/dev/sda5 ... to indicate the partitions. For example, if you want to create a image file from the first partition OF/DEV/SDA, use "dd" like this:

DD if=/dev/sda1 of=~/disk2.img

Also, you can compress the image file:

Gzip disk2.img

By the the-the-partition to another partition completely, just set "of" to the partition ' s device name. For example:

DD if=/dev/sda1 OF=/DEV/SDB5

This command would copy all the contents from/dev/sda1 TO/DEV/SDB5. You must being sure that the capacity of/dev/sdb5 is larger than/dev/sda1.

Restoring from an Image File

To restore a partition or a hard disk from an image file, just exchange the arguments "if" and "of". For example, restore the whole hard disk from the image file "disk1.img":

DD If=disk1.img OF=/DEV/SDA

Restore the first partition OF/DEV/SDA from the image file "disk2.img":

DD If=disk2.img OF=/DEV/SDA1

Linux Backup:hard Disk Clone with "DD"

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.