Advertisement: Linux VPS from $4/month - contact support for custom offer.
+ Post New Thread
Results 1 to 1 of 1

Thread: Cloning a ZFS bootable system

  1. #1
    Administrator
    Join Date
    Mar 2013
    Posts
    2,817

    Cloning a ZFS bootable system

    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.

    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.

    ZFS send would not work if you are transferring to a system with a lower ZFS version. It should be implied that the destination has >= ZFS version that the source.

    First, there are some disclaimers provided by a ChatGPT:
    Yes, you can indeed create a ZFS snapshot of your operating system and all other data on a virtual private server and then restore this snapshot on a different KVM VPS with a ZFS filesystem used on its primary operating system partition.

    However, there are a few considerations to keep in mind:

    1. Make sure the ZFS versions on both the source and destination systems are compatible. It's recommended to use the same versions of ZFS on both systems to ensure compatibility.
    2. You will need to properly configure the disk layout and partitions on the destination system to match the source system before restoring the snapshot.
    3. It is not recommended to perform this restoration during runtime of the operating system that will be replaced. It's best to boot into a live environment or another operating system to perform the restoration safely.
    4. Keep backups of important data before performing any snapshots and restorations to avoid data loss.
    Prepare our original system for cloning. First create a full snapshot of the filesystem

    zfs snapshot -r zroot@bck
    (create a recursive snapshot named "bck" for the "zroot" dataset in the ZFS pool.)

    Now send the snapshot to out new system.

    zfs send -R zroot@bck | ssh [email protected] zfs recv -Fdv zroot
    (The -R flag recursively sends all snapshots and dependent filesystems.
    The -F flag forces rollback of the file system to the most recent snapshot before the receive stream.
    The -d flag creates any necessary parent datasets.
    The -v flag enables verbose mode.
    The zroot is the name of the dataset where the snapshot will be received.)

    That should take a while. After that the last steps, on the target machine.

    zfs destroy -r zroot@bck # recursively destroy snapshot/s and dependent dataset/s
    zfs set mountpoint=/zroot zroot # sets the mountpoint property of the ZFS dataset zroot to /zroot. This means that the dataset will be mounted at the specified location when the system is booted or the dataset is manually mounted
    zpool export -f zroot
    zpool import -f zroot
    cp /boot/zfs/zpool.cache /zroot/boot/zfs/zpool.cache
    zfs umount -a
    zfs set mountpoint=legacy zroot
    zfs set mountpoint=/tmp zroot/tmp
    zfs set mountpoint=/usr zroot/usr
    zfs set mountpoint=/var zroot/var
    reboot
    That’s it. Make sure that you power off your first system so that you don’t get an IP conflict.

    Btw. Someone comments that the above mentioned cp command not worked and instead they have used "zfs set org.freebsd:swap=on zroot/swap".

    To automate the replication, one may use tool like Zrep ( https://github.com/bolthole/zrep ; http://www.bolthole.com/zrep/zrep.documentation.html ).

    Source of this is an archived 2011 article https://web.archive.org/web/20160117000049/http://www.aisecure.net/2011/03/26/cloning-a-zfs-bootable-system/
    Last edited by Fli; 07-14-2024 at 05:37 AM.

+ Post New Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
 Protected by : ZB BLOCK  &  StopForumSpam