How to copy a Linux installation
Using dd to make a 1:1 copy
When dd is used to create the copy, it is copied at a sector by sector level. This means that in many circumstances, the new version will have it's boot sector set up and everthing. In situations where you are making a complete copy of the disk, even things like the IBM tools and your windows partition will be saved.
Because dd copies sector by sector it copies everything, including sectors that aren't allocated. This makes it a longer process. To update the backup copy, it must perform the whole process again, rather than simply updating the things that have changed.
Case 1: The Linux installation is on a separate Harddisk
This method works if you can put wo drives in your laptop. Best to boot from a boot disk, so that the contents of the disks are not changed during the cloning.
dd if=/dev/hd[a,b,c,..] of=/dev/hd[a,b,c,..] bs=2M
Part of Sourcedrive : if=/dev/hd[a,b,c,..] the Letter "a" for the first Harddrive, b for the second, ....
Part of Destinationdrive : of=/dev/hd[a,b,c,..] the Letter "a" for the first Harddrive, b for the second, ....
Case 2: The Linux installation is on a Partition
(e.g. hda1 is the Partition with the Linux installation and hdb1 is the Destinationdrive)
dd if=/dev/hda1 of=/dev/hdb1 bs=2M
Case 3: Copying whole disk
Case 1 assumes you can put two drives in your laptop. The method here can be used when you have access to a networked computer with a lot of space. Or, when you have an external 3.5 HD. (If you have a 2.5 external USB drive you can use Harddrive_Upgrade)
1) Boot from a CD, such as R.I.P.
2a) dd if=/dev/hda bs=65536 conv=noerror,sync |gzip -c| ssh somewhere-with-disk
Or, with external drive, mount it on /mnt/usb
2b) dd if=/dev/hda bs=65536 conv=noerror,sync |gzip -c > /mnt/usb/big_file
The gzip will cause a compression of the image file, hope for about 2:1 compression, but prepare for worse!
3)Replace your old drive with new drive, and boot again from the CD. Restore with:
4a) ssh somewhere-with-disk cat rawdisk.img|gzip -dc|dd of=/dev/hda bs=65536
Or, for the external drive
4b) cat /mnt/usb/big_file |gzip -dc|dd of=/dev/hda bs=65536
You can change the partition information after the restore with tools such as parted. Note, on very old drives this method might fail when the drives are not fully identical, as the geometries needed to be equal. However, there is no risk of data loss, just re-insert the old drive and try another method.
Using tar to make a copy of the filesystem
- point your console to the place you would like to copy (copying from a running system root might cause problems), like:
or do it saver like: #cd /path/to/mountpoint
- do this to clone the current partition to another:
#tar cf - . | (cd /path/to/mountpoint; tar xf -)
to get some information about the progress add the "v" for verbose mode #tar cfv - . | (cd /path/to/mountpoint; tar xf -)
in case your getting an error, that files/directories can't be created or read try this: #sudo tar cfv - . | (cd /path/to/mountpoint; sudo tar xf -)
- able to restore it to another filesystem
- incremental backups
- burn splitted backups on dvd
- compression (if you save it to a file)