Clone Debian Linux hosts

Get two bootable USB drives with Debian Live.

Boot both, ensure both are online.

Setup the power management settings on both so they do not turn off when lid is closed or on other energy related events.

Open a terminal and install necessary tools on them:
sudo bash
apt update
apt install ethtool gparted netcat net-tools pv

Target:
Open gparted and resize the partitions so you have space for the Linux partitions.

Source:
Check partition sizes - note the sector values for each partition to clone:
fdisk -l /dev/sdX
Or
sfdisk -d /dev/sdX 

Target:
Re-create the Linux partition structure - for example an extended partition with the partitions from the step above.

Use cfdisk to make new partitions, then use the <sector number>S in the size field to make the sizes exact the same.

Connect both hosts with a network cable from RJ45 port to RJ45 port.

Find the network interface and set an IP on it:
ifconfig -a
ifconfig <interface name> 192.168.20.2

Source:

Find the network interface and set an IP on it:
ifconfig -a
ifconfig <interface name> 192.168.20.1

Ping the target:
ping 192.168.20.2

Check that the interface is running at gigabit speed:
ethtool <interface>|grep Speed

Check partitions to share:
fdisk -l /dev/sdX

Share them one by one - repeat this for each partition when the previous has completed:
cat /dev/sdXY | pv | nc -l -p 5555

Press Ctrl+C when they have reached 100% and the speed has gone down to 0.00B/s.

Target:

Check partitions to fill:
fdisk -l /dev/sdX

Read from the source one by one - repeat this for each partition when the previous has completed:
nc <source-host> 5555 | pv > /dev/sdXY


Source/target:
Check each partition with md5sum and compare results so they are the same:
md5sum /dev/sdX

Target:
partprobe

mount /dev/sdaXY /mnt

Now mount partitions according to source /etc/fstab, for example:
mount /dev/sdaXY /mnt/home
mount /dev/sdXX /mnt/boot

if UEFI:
mkdir -p /mnt/boot/efi
mount /dev/sdNN /mnt/boot/efi

mkdir -p /mnt/run/udev

Mount necessary parts:
for i in /dev /dev/pts /proc /sys /sys/firmware/efi/efivars /run/udev; do mount -B $i /mnt/$i ; done

OR:

mount -t proc proc /mnt/proc
mount -o bind /dev /mnt/dev
mount -o bind /dev/pts /mnt/dev/pts
mount -o bind /sys /mnt/sys
mount -o bind /sys/firmware/efi/efivars /mnt/sys/firmware/efi/efivars
mount --bind /run/udev /mnt/run/udev

Go into the root partition:
chroot /mnt

Install GRUB:
grub-install /dev/sdX
update-grub

exit

reboot

This is a personal note. Last updated: 2023-04-08 18:32:29.



GitHub

My

GitLab

My

LinkedIn

My

Klebe.se

Don't forget to pay my friend a visit too. Joakim