HOWTO Clone a Linux disk and install on a similar machine.¶
Before you start.¶
- Disks should be of the same make and model (incl. size) to ensure identical geometry.
- Disks should be in the same machine.
- You should know in advance whether the disk is a 4k sector-size or 512b.
Clone the disk.¶
/dev/sdX as the source, and
/dev/sdY as the destination, and with a blocksize n:
dd if=/dev/sdX of=/dev/sdY bs=n conv=noerror,sync
Check progress with
kill -HUP <dd-pid> from another terminal window (information will appear in the original window).
Change the Volume ID to be unique.¶
This is taken practically verbatim from a Stack Exchange answer at http://serverfault.com/questions/195345/generate-a-new-volume-id-in-linux.
Save the MBR to disk.¶
dd if=/dev/sdY of=mbr.dat bs=512 count=1
Read the new partition table for the disk:¶
- Download the attached sigchange.pl and make it executable:
chmod +x sigchange.pl
- Execute it:
Copy the changed MBR back into place.¶
dd if=newmbr.dat of=/dev/sdY bs=512 count=1
Change the UUIDs of the linux partitions.¶
tune2fs /dev/sdYn -U random
Configure the root partition for the system into which it will be installed:¶
- Mount the root partition on /mnt/tmp:
mount /dev/sdYn /mnt/tmp
- Change the hostname in
- Clear SSH server keys:
rm -f /mnt/tmp/etc/ssh/*key*
- Remove identifying information such as
/mnt/tmp/etc/sysconfig/network-scripts/ifcfg-*, and fix any
IPADDlines to be appropriate for the new machine.
- Unmount the root partition:
Transfer the disk to the new machine.¶
- Shut down both machines.
- Remove the old system disk from the destination machine.
- Transfer the new system disk to the destination machine.
- Boot into single user mode (hit tab on crash cart when you see "Booting ... in 5 seconds ..." and hit "a" to add "single" on to the end of the boot options. If you have IPMI configured, the single user prompt will appear there. Enter the root password.
- Using the output of
ip, put new
- If networking does not come back as expected, rearrange the hardware addresses or ethernet cables to match the expected configuration.