`lxd init` error message when zfs storage pool cannot be created could be more descriptive

What happened

When purging and reinstalling lxd today through:

snap remove --purge lxd
snap install lxd
lxd init
# (accept all defaults from init)

I encountered the error message:

Error: Failed to create storage pool "default": Provided ZFS pool (or dataset) isn't empty

Looking through zfs list, I see:

rpool/lxd                                                                                               1.03G   495G      240K  legacy
rpool/lxd/buckets                                                                                        240K   495G      240K  legacy
rpool/lxd/containers                                                                                     240K   495G      240K  legacy
rpool/lxd/custom                                                                                         240K   495G      240K  legacy
rpool/lxd/deleted                                                                                       1.41M   495G      240K  legacy
rpool/lxd/deleted/buckets                                                                                240K   495G      240K  legacy
rpool/lxd/deleted/containers                                                                             240K   495G      240K  legacy
rpool/lxd/deleted/custom                                                                                 240K   495G      240K  legacy
rpool/lxd/deleted/images                                                                                 240K   495G      240K  legacy
rpool/lxd/deleted/virtual-machines                                                                       240K   495G      240K  legacy
rpool/lxd/images                                                                                        1.03G   495G      240K  legacy
rpool/lxd/images/672583a05778fdd42770408068c5f932d8383539b4cdf20f11b92a0bf3b24d45                       1.03G   495G     1.03G  legacy
rpool/lxd/virtual-machines                                                                               240K   495G      240K  legacy

Left over from the previous lxd install. If I do zfs destroy rpool/lxd -r and then try to lxd init again, everything works

What did you expect

Not being well versed in zfs, it took a while to go Failed to create storage pool "default" to zfs destroy rpool/lxd. Some hints would be helpful - maybe something in the error messaging saying the name of the ZFS pool that isn’t empty or linking some troubleshooting info for zfs? Or if there are any simple guides on “how do I purge and reinstall lxd” that might cover this. I mistakenly dug looking for something called default to remove, before realising I needed to purge the entire rpool/lxd. After another iteration I realised my mistake when again reading the Would you like to create a new zfs dataset under rpool/lxd? question from init.

Maybe error checking closer to the question Would you like to create a new zfs dataset under rpool/lxd? might help here. I’d guess once I’ve said yes to this question, it is detectable that init will fail due to a conflicting pool.

Hi, thanks for posting.

The lxd init command itself is just a REST client to the lxd server process, so it doesn’t know there is a problem until it gathers the answers to all the questions and submits the initialization request. So refactoring that process into a multi-step dialogue between client and server in order to provide the errors sooner would be quite involved.

But I agree the error Provided ZFS pool (or dataset) isn't empty could be improved by adding the specific pool/dataset that isn’t empty. That would certainly help diagnosing the issue. Perhaps along with a suggestion to run sudo zfs list <dataset> to see the offending volumes.

Yeah those sound like great suggestions!