TrueNAS Fix: Cannot mount 'directory': failed to create mountpoint

TrueNAS Fix: Cannot mount 'directory': failed to create mountpoint

I've you've at any point used TrueNAS' replication functionality to move or copy data from one dataset to another, you may have run into an issue later on where you're suddenly no longer able to create additional datasets in the root of the destination pool.

This was a bit of a head scratcher for me as as there was no apparent setting or flag that would be causing this. But here is one way that this might be happening, and fortunately the fix is quite easy.

The issue is related to the default settings of replication tasks wanting to make the destination dataset read-only. Not only does this mark the destination dataset as read-only, it too seems to set the immutable file attribute on the pool's root dataset. The former is easy to fix, as TrueNAS has the ZFS read-only option exposed through its GUI, but the latter is not.

💡
This guide was written with TrueNAS Scale in mind. I am not sure if the same exact steps apply with TrueNAS Core too.

To check if this is the issue you are facing, SSH into your TrueNAS Scale machine (Or use the System Settings > Shell option through its Web UI), and run the following command:

❯ lsattr /mnt

If any of the pools show an i in the results, their immutable flag has indeed been set. Here's an example of what that might look like:

❯ lsattr /mnt
---------------------- /mnt/Acacia
---------------------- /mnt/Willow
----i----------------- /mnt/Cottonwood

Removing this flag is as easy as running the following command, substituting the mount path to your own pool of course:

❯ sudo chattr -i /mnt/Cottonwood

And that's it! You should now be able to create additional datasets in this pool, just like before. If you still have the dataset that threw this error listed and throwing errors when you try to select it, be sure to delete it first, then re-create it.