Zfs rename/move root filesystem into child

filesystemsrenamezfs

Similar question exists but the solution (using mv) is awful because in this case it works as "copy, then remove" rather than pure "move".

So, I created a pool:

zpool create tank /dev/loop0

and rsynced my data from another storage in there directly so that my data is now in /tank.

zfs list
NAME      USED  AVAIL  REFER  MOUNTPOINT
tank      591G  2.10T   591G  /tank

Now I've realized that I need my data to be in a child filesystem, not in /tank filesystem directly.

So how do I move or rename the existing root filesystem so that it becomes a child within the pool?

Simple rename won't work:

zfs rename tank tank/mydata
cannot rename to 'tank/mydata': datasets must be within same pool

(Btw, why does it complain the datasets are not within same pool when if fact I only have one pool?)

I know there are solutions that involve copying all the data (mv, or sending the whole dataset to another device and back), but shouldn't there be a simple elegant way?

Just noting that I do not care of snapshots at this stage (there are none yet to care of).

Best Answer

Given the problem documented by @USDMatt, ZFS send/receive is probably the best way to go.

zfs snapshot tank@snap
zfs send tank@snap | zfs receive tank/anotherfs
zfs set mountpoint=/beep/boop tank/anotherfs
rm -rf /tank/*
zfs destroy tank@snap

Watch out when running the rm -rf if you don't change the mount point of if you have other filesystems in your tank zpool. You don't want to recursively remove the contents of the new filesystem (/tank/newname) or any other child filesystems (/tank/*) accidentally.

Related Topic