Project

General

Profile

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.

Designating /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:

  1. Download the attached sigchange.pl and make it executable:
    chmod +x sigchange.pl
  2. Execute it:
    ./sigchange.pl

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.

For each ext[234] partition:

tune2fs /dev/sdYn -U random

Configure the root partition for the system into which it will be installed:

  1. Mount the root partition on /mnt/tmp:
    mount /dev/sdYn /mnt/tmp
  2. Change the hostname in /mnt/tmp/etc/sysconfig/network.
  3. Clear SSH server keys:
    rm -f /mnt/tmp/etc/ssh/*key*
  4. Remove identifying information such as HWADDR and UUID from /mnt/tmp/etc/sysconfig/network-scripts/ifcfg-*, and fix any IPADD lines to be appropriate for the new machine.
  5. Unmount the root partition:
    umount /mnt/tmp

Transfer the disk to the new machine.

  1. Shut down both machines.
  2. Remove the old system disk from the destination machine.
  3. Transfer the new system disk to the destination machine.

Final configuration

  1. 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.
  2. Using the output of ifconfig -a and/or ip, put new HWADDR lines in /etc/sysconfig/network-scripts/ifcfg-*.
  3. Reboot.
  4. If networking does not come back as expected, rearrange the hardware addresses or ethernet cables to match the expected configuration.