« Montage SSHFS

Clone a Debian system

10.11.09

Permalink 05:19:48 pm, by mazet Email , 301 words   English (US) latin1
Categories: Systeme, Debian

Clone a Debian system

This is my own recipe to clone a Debian system on two hard disks. It can also be done via network connection (ssh) if the two disks are not in the same computer; it only need to setup the network connections by ifconfig Boot on RescueCD
rescuecd docache
If it can't find media (too long anwser), after the liveCD get up to a secure shell, try again using
exec /linuxrc
Choose the French language by entering the value 16 or fr Find origanal device Find original device and list partition table
fdisk -l /dev/sda
Mount it
mkdir /mnt/orig
mount /dev/sda1 /mnt/orig
Find clone device and partition it
echo "n p 1 1 100G n p 2  4G t 2 83 w" | \
    sed 's/ /\n/g' | \
    fdisk /dev/sdb
Format clone partitions
mkfs -t ext3 /dev/sdb1
mkswap /dev/sdb2
Mount clone
mkdir /mnt/clone
mount /dev/sdb1 /mnt/clone
Clone disk
rsync -va /mnt/orig/ mnt/clone
Check that clone coresponds to original
ls /mnt/orig /mnt/clone
Install grub
  • for grub 1
    grub-install --root-directory=/mnt/clone --recheck /dev/sdb
  • for grub 2
    grub2-install --root-directory=/mnt/clone --recheck /dev/sdb
    Remove UUID reference in /boot/grub/grub.cfg by replacing root=UUID=... by root=/dev/sda1. After first boot, you will need to update grub2 configuration with update-grub2
Configure network interfaces
orig=1
clone=2
sed -i 's/\(172\.16\.0\.)'$orig'/\1'$clone'/' \
    /mnt/clone/etc/network/interfaces \
    /mnt/clone/etc/hosts
sed -i 's/\(blade-\)'$orig'/\1'$clone'/' \
    /mnt/clone/etc/hostname \
    /mnt/clone/etc/hosts
rm /mnt/clone/etc/udev/rules.d/70-persistent-net.rules
Rebuild ssh keys
ssh-keygen -t dsa -f /mnt/clone/etc/ssh/ssh_host_dsa_key
ssh-keygen -t rsa -f /mnt/clone/etc/ssh/ssh_host_rsa_key
Unmount disks
umount /mnt/orig
umount /mnt/clone
Reboot clone blade