is it possible to convert dataset to sparse volume (thin provisioning)?

Solution 1:

As far as I know it's not possible to convert an existing zvol to sparse; they must be created sparse to begin with.

However, you can create a new sparse zvol, and zfs send from the old one and zfs recv to the new one, and then swap their names.

Solution 2:

I don't think the accepted answer is correct in fact, but I don't have enough rep to comment.

Assuming when the OP says "datasets" they mean "ZFS volume" (or ZVOL).

The only difference between a thin-provisioned (a.k.a sparse) ZVOL and a regular one is whether the full size is reserved via the refreservation property e.g.

# zfs create -V 10G tank/test_full
# zfs create -s -V 10G tank/test_sparse
# zfs list -o name,used,usedbydataset,usedbyrefreservation,logicalused,logicalreferenced,refreservation tank/test_sparse tank/test_full
NAME               USED  USEDDS  USEDREFRESERV  LUSED  LREFER  REFRESERV
tank/test_full    10.3G    136K          10.3G    30K     30K      10.3G
tank/test_sparse   136K    136K              0    30K     30K       none

So you can convert an existing ZVOL to sparse by changing refreservation for an existing ZVOL e.g.

# zfs set refreservation=none tank/test_full
# zfs list -o name,used,usedbydataset,usedbyrefreservation,logicalused,logicalreferenced,refreservation tank/test_sparse tank/test_full
NAME               USED  USEDDS  USEDREFRESERV  LUSED  LREFER  REFRESERV
tank/test_full     136K    136K              0    30K     30K       none
tank/test_sparse   136K    136K              0    30K     30K       none