VMs and ZFS replication

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
Hi I just want to make sure my logic here is correct since by no means am I a ZFS expert.
I'm using FreeNAS 11.3 (not sure if this matters).

Initially I've created a Linux VM with a ZVOL which was placed within a ZFS dataset. My understanding is a ZVOL is a block level device. I went ahead and installed the OS and configured the VM installing various packages, etc. I basically set the VM up to be a good "base VM" installing my usual packages - (ifconfig, zsh, etc).

Once done with the configuration, I took a snapshot of the ZVOL manually and then continued to make modifications of the VM. Auto snapshots were taken with FreeNAS along the way. For purposes of this discussion I'm going to call this first manual snapshot the "base snapshot".

What I'd like to do is actually replicate the "base ZVOL" and use this replicated ZVOL for a completely different VM. I dont want the ZVOLs linked or tied to each other in any way. I understand if the original ZVOL was allocated 20GB the new ZVOL should be allocated an additional 20GB.

My question is how to replicate the "base ZVOL" or is there not such a thing?? Am I totally incorrect in thinking that if I replicate the "base snapshot" via a zfs send/receive command that this will recreate the "base ZVOL"?
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
So replication is really the process of copying ZFS data from one place to another. While you could probably get this to work, it is an unnecessary train wreck, I think. Replication carries with it a notion that you're going to be keeping the replicated data up to date with the original.

What you are doing is no better than creating a new ZVOL and copying over the data (dd or whatever). Which is fine.

You can also look into ZFS clones. I don't know what the current state of this is in FreeNAS and I don't have time to look.

Clones actually SHARE the disk space of the original source and only occupy disk space for changed blocks, so this can be a powerful thing.
 

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
Ok I concede it may not be exactly what I want to do however taking your spin on the matter, what about then recreating a new zvol and then dd'ing the contents of the old ZVOL. I'm ok with that. (Why start from scratch if I don't have to??).

How exactly would I do this however is the question?

I really don't want to work with clones since its highly likely the datasets would become very divergent in time. As I understand (maybe mistakenly), is the clones are actually linked so I couldn't actually destroy the parent ZVOL since its linked to the child clone.
 

MarkusT

Cadet
Joined
Mar 30, 2020
Messages
3
I think you could use the beautiful features of ZFS for your problem.
1. Snapshot your ZVOL
2. Clone your ZVOL snapshot
3. Promote your cloned ZVOL
See "Example 10" of the zfs manpage https://www.freebsd.org/cgi/man.cgi?zfs(8)
To my understanding this should give you fully independent ZVOLs which you may use for new VMs. When creating a new VM with the GUI you will only have to choose the new ZVOL for your new VM.
Good luck.
 

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
Honestly I'm not sure I want to use the clone command:

The clone parent-child dependency relationship can be reversed by using
the promote subcommand. This causes the "origin" file system to become a
clone of the specified file system, which makes it possible to destroy
the file system that the clone was created from.

The two file systems are still linked, just in a different way. Sure now its possible to destroy the parent filesystem and keep the child, but what if I want to delete the child file-system?? I can't since the parent is linked to the child. Thats why I want two independent file systems with the ability to delete either the 1st or the 2nd without it affecting the other.
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Essentially what @jgreco said, but why use dd? zfs send | zfs receive will only actively copy the blocks your guest OS really touched and give you a complete independent read-write clone (in the sense of identical copy) of your virtual disk.

HTH,
Patrick
 

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
@Patrick M. Hausen Honestly that what I thought zfs send receive would do the trick however I received a comment from someone that this isn't exactly zfs send/receive is meant to do. They said its meant to create a remote volume and keep it in sync with the local source. No further explanation was given I don't know if that means I still cant abuse the zfs send receive command for what I want to do.

Another poster told me to do the following
Code:
root@box:~# zfs create -V tank/newzvol 100G
root@box:~# zfs clone tank/oldvol@goldsnapshot tank/tmp
root@box:~# pv < tank/tmp > tank/newzvol
root@box:~# zfs destroy tank/tmp


I don't know a lot the pv command however this seems similar to dd in theory. I'm just wondering what the people that do this more for a living actually use.
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Code:
zfs send tank/oldvol@goldsnapshot | zfs receive tank/newzvol


zfs send sends a ZFS dataset or volume (precisely a snapshot thereof) as a binary datastream. This can be compressed (or not), saved to a file, sent to another machine ... whatever.
zfs receive reads a ZFS binary datastream and creates a dataset or volume (precisely a snapshot thereof) from it.
If the dataset does not exist, the entire dataset is created - plus the snapshot. Obviously ;)

That's the basic and probably most common use.

Additionally both commands can work on a differential datastream based on a particular common snapshot. So you can repeatedly call send | receive and only transfer what changed since the last snapshot(s) transferred. But that's an advanced use case.

HTH,
Patrick
 
Top