Using the DD command to implement Ghost function on Linux

Source: Internet
Author: User

Transferred from: http://blog.jobbole.com/90978/

Ghost and g4l.

Install the operating system, too slow, the whole process is too tedious.

During the installation process, several questions need to be answered, and the system needs to install countless software to create and write countless files. Because it involves a lot of file location and read and write, the speed must be not fast up.

We often use ghost systems to back up and burn the operating system under Windows. Ghost can clone the image of the entire system and then restore it on the new computer, quite simply. It is much quicker to install the operating system with the ghost system than to install the system using the installation CD, and there is no need to answer any questions.

So, can we use Ghost to back up and restore the Linux system?

The answer is no. Because ghost can only recognize very few old Linux file systems, nor does it recognize boot loaders such as grub and Lilo.

In fact, there are ghost tools under Linux, the most famous of which are g4l-ghostforlinux.

Used a ghostforlinux. It's easy to copy and restore the entire disk. However, I tried for a long while, there is no way to achieve the recovery of one or several partitions.

G4L, still too weak, can not meet my requirements!

The Magic fdisk and DD commands

Deep distress, the epiphany: what is the principle of magical ghost? Is it data replication? The DD command under Linux is not the most powerful data replication tool!

So why should I use a complex tool like g4l? A DD command can help me achieve any complex image replication and recovery requirements? Whether he is grub, or ext4,btrfs,fat32,ntfs...dd before the equality of all sentient beings.

To enter the Linux operating system, open the command line and execute the following command:

1 sudo fdisk -u -l

You can view the size and layout of all partitions on all disks.

-U, the unit of the number in start and end is 512 bytes, which is the size of a sector sector.

Suppose I have a/DEV/SDA disk that has a 100GB size. I have installed an Ubuntu operating system. The following partitions are used:

/DEV/SDA1 5GB

/dev/sda2 1GB Extended Partition

/DEV/SDA5 1GB Extended Partition

/DEV/SDA2 is all extended partitions, its size and/dev/sda5 coincident.

/DEV/SDA1 is a file system in EXT4 format. Used to install the Ubuntu operating system.

/dev/sda5 is a swap-formatted file system that acts as a swap partition.

If I use the mentally g4l tool to make a mirror of the system, I need to back up the entire disk 100GB instead of the 6GB I need.

G4L can also back up partitions separately, but when recovering, it is necessary to install grub on the target computer and partition it appropriately. Very troublesome!

I can use a DD command to generate a 6GB image. The complete system can then be recovered on any hard drive larger than 6GB, including the MBR and 3 partition Sda1,sda2,sda5.

Specific steps

Find a USB flash drive and install the Ubuntulive CD system. "Specifically how to make a USB flash drive boot ubuntulive CD, you can refer to the official Ubuntu website Help." 】

Ubuntulive CD and windowsPE system similar, is the CD/u disk boot Ubuntu operating system, do not need to install can be used directly.

The USB stick starts, enters the Ubuntu system on the disk, opens the command line, executes:

1 sudo fdisk -u -l /dev/SDA

View the partitioning of the hardware.

Then execute:

1 < Span class= "Crayon-r" >dd   bs=< Span class= "CRAYON-CN" >512 count=[fdisk command the largest end number +1] if =/dev/ SDA of=/ghost.img

In this way, you can copy all the partition data I need into the ghost.img file. The image production is complete!

Then, we can plug the USB stick to other systems, start with a USB stick, enter UBUNTULIVECD, open the command line, execute the following command:

1 DD If=/ghost. IMG of =/dev/SDA

When you're done, unplug the USB drive and start the computer, and you'll see that our Linux system is installed!

Attention:

Do not use the local disk directly on the computer to start the system after you execute the DD command to generate a mirror image of the local disk. Instead, you should use LIVECD to start the computer.

Therefore, the computer runs with a large amount of write operations to the system disk. Images generated directly from a running system disk are likely to fail to boot when restored to another hard drive!

The same applies to non-Linux operating systems

Is it easy to use the DD command on Linux for system image backup and recovery?

For Windows system, even Mac and so on any system, can actually use the DD command to achieve system image backup and recovery.

Because, the FDISK command of Linux can recognize the partition format under any system. Fdisk does not relate to file systems on partitions, and even file systems do not care. Fdisk can always report which sectors the partition occupies.

The DD command also does not care about the disk's file system format, it simply copies as many bytes of data as required from the specified location.

The DD command enables mirrored backup and recovery, which is much simpler and more powerful than ghost software. With Ghost Software, users still need to perform complex and dangerous disk partitioning operations.

And with the two commands of Fdisk and DD, everything is FREE!

Compression and decompression

It is possible that the partition we need to back up is large, and the image file generated with the DD command is very large.  It is not convenient to store and transfer these images. We can also compress the resulting image file using the compression program. Here, I choose to use the GZIP program to work with the DD command.

Gzip Parameters:

-C means output to stdout
-D means decompression
-1 indicates the fastest compression
-9 means best compression
The 6 compression level is used by default.

To generate a compressed image file using DD and gzip, you can execute the command:

1 DdBs=512 count=[fdisk command in the largest end number +1] if= /dev/sda | gzip -6 > /< Span class= "crayon-v" >ghost.img.gz

When you restore, you can execute the following commands:

1 Gzip -DC /ghost. img. GZ. GZ | DD of =/dev/SDA

Remind:

If you restore the image to another computer, you may find that your network card is eth1, not eth0. This is because the/etc/udev/rules.d/70-persistent-net.rules file registers the network card of your mirrored computer as eth0.

If your network script handles eth0 and does not process the eth1, you may not be able to surf the web without modifying the network scripts.

You might want to delete the/etc/udev/rules.d/70-persistent-net.rules file before you make the image.   So when you restore the mirror, the name of the NIC is eth0. It won't cause you to be unable to surf the internet on your restored computer.

Attention:

It is best to umount the partitions of all if and of devices before DD generates the image. This ensures that the file system is not changed during DD.

After the DD (Generate mirror and restore image) is completed, sudo sync is executed to ensure that the data is actually written to the hard disk.

Also, if you want to back up and restore the entire hard drive instead of just backing up and recovering some of the partitions, remove the maximum number of end +1 in the count=[fdisk command in the DD command. BS=512 can also be removed.

Transferred from: http://blog.jobbole.com/90978/

Using the DD command to implement Ghost function on Linux

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.