I always thought that ZFS was the most exciting addition to FreeBSD during the last ten years that I am involved.
Generally speaking the process of cloning a live system has been the cause of many headaches in the past. You can find many tools, commercial and open source, that try to ghost the full file systems. But there are always limitations that rise because of the way file systems are laid. Raid controllers, software raid and disk geometry are some of the things you have to consider only. Till today…
We are going to clone a live raid1 system over ssh to a new system with a single disk and with smaller capacity. On top of that during this operation, our host system will be online and we will shut it down after the clone has been completed.
Imagine having to do this a few years ago.
First of all we will use Martin Matuška ISO images to boot our target system. Download your platform ISO and boot. Your target system will load in a fully workable FreeBSD image loaded into memory. Much better than the FIXIT environment. Assuming that you have a DCHP server around your system will already have an IP address:
Now on the new system we have to initialize our disk and create our pool. We will use a gpt partition scheme.
mfsbsd#gpart create -s gpt ad0 mfsbsd#gpart add -b 34 -s 64k -t freebsd-boot ad0 mfsbsd#gpart add -t freebsd-zfs -l disk0 ad0 mfsbsd#gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ad0 mfsbsd#zpool create zroot /dev/gpt/disk0 mfsbsd#zpool set bootfs=zroot zroot
In this scenario swap is assumed to reside within the zfs pool. If we were using swap space on a different partition we would have to create it also. Now it is time to prepare our original system for cloning. First create a full snapshot of the filesystem
zfs snapshot -r zroot@bck
Now send the snapshot to out new system. The password for the root user is mfsroot
zfs send -R zroot@bck | ssh firstname.lastname@example.org zfs recv -Fdv zroot
That should take a while. After that the last steps, on the target machine.
mfsbsd#zfs destroy -r zroot@bck mfsbsd#zfs set mountpoint=/zroot zroot mfsbsd#zpool export -f zroot mfsbsd#zpool import -f zroot mfsbsd#cp /boot/zfs/zpool.cache /zroot/boot/zfs/zpool.cache mfsbsd#zfs umount -a mfsbsd#zfs set mountpoint=legacy zroot mfsbsd#zfs set mountpoint=/tmp zroot/tmp mfsbsd#zfs set mountpoint=/usr zroot/usr mfsbsd#zfs set mountpoint=/var zroot/var mfsbsd#reboot
That’s it. Make sure that you power off your first system so that you don’t get an IP conflict.
This will work regardless of the source – destination zpool types. They could be simple, mirror or RAIDz1. Also, disk capacity is irrelevant. Meaning that you can transfer a 240G system to a 80G system as long as the second has enough room to hold the data.
Here you can see a bare metal FreeBSD9 being cloned to a Linux KVM server