18

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).

Anton
  • 181

4 Answers4

9

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.

notpeter
  • 3,535
5

(see notes in comments, this works, but you'll never be able to delete initial the snapshot, so it's not a good solution)

With ZFS this is surprisingly straightforward: just snapshot, clone and then rm. No extra space or copy time required.

zfs snapshot tank@mydata
zfs clone tank@mydata tank/newname
zfs set mountpoint=/beep/boop tank/newname
rm -rf /tank/*

Watch out when running the rm -rf if you don't change the mount point of if you have other filesystems in your zpool. You don't want to recursively remove the contents of the new filesystem (/tank/newname) or any other child filesystems (tank/*) accidentally. Once you've confirmed your files are not in the root fs (/tank/) and only in your new filesystem, you can also delete that initial snapshot.

zfs delete tank@mydata
notpeter
  • 3,535
2

I don't think there's a simple elegant way... although you could just change your mountpoint...

mkdir /tank
zfs set mountpoint=/tank/mydata <possibly renamed tank set>

Or maybe rename tank and then mount it where you need it...

Either that, or create a filesystem in the right place and cp, mv, or zfs send/receive...

ewwhite
  • 201,205
1

was copying whole disk to a new dataset, then found out it was a root folder:/

zfs clone tank tank/mynewdataset && rm -rf /mnt/tank/ && zfs promote tank/mynewdataset

this made my root data appear in the 'child' dataset, and fixed 2 issues with other solutions: sizes are correct, copy didn't execute.