Cloning Systems

From docwiki
Revision as of 13:37, 29 October 2020 by Mond (talk | contribs)
Jump to: navigation, search


Motivation

Once you have setup a system you might want to have a copy of that same system without the need to configure it the same. Of course: When you install the same lists of packets you have a similar system. If you maintain a larger number of systems you will also want to use a configuration management system to configure them all alike. But still you might find situations where it is convenient to be able to create a clone of an existing system.

Cloning with dd

When your system is not running you can make a 1:1 copy of your disk. You should not do this when the system is running since you will not get a consistent state of filesystem. One way to do this is by booting your system from a Live-CD of a Live-USB drive. Those live systems run off CD or USB and you can safely access the data on the hard drive.

E.g. If your harddrive is /dev/sda and you have connected an external USB drive and you want to store a .gz compressed image of your complete harddrive you could run:

dd if=/dev/sda bs=1M | gzip > /media/mydrive/img.gz

If you then boot your target system from a live CD you can overwrite the harddrive with

#ATTENTION: this overwrites your harddrive
zcat /media/mydrive/img.gz | dd of=/dev/sdX bs=1M

where /dev/sdX should be replaced with the disk you want to overwrite.

E.g. The images for installing a raspberry pi often come in this way and you can use dd to write them to an SD-card.

The new system of course needs a disk of the same size or bigger. If the disk is bigger you can later add the remaining free space at the end to be used by your system.

Cloning