Re: How to create overlay file system on FreeBSD?

From: Olivier Certner <olce_at_freebsd.org>
Date: Mon, 29 Apr 2024 11:52:21 UTC
Hello,

What you describe is exactly the point of unionfs(5).  I'll suggest that you 
have a look at mount_unionfs(8).  Note however that, with the current 
implementation, it is not directly possible to have a separate mount point for 
the union itself: It will either shadow the lower layer (default behavior) or 
the upper layer (with mount option 'below').  You can workaround that using a 
nullfs(5) mount before mounting the union.

The main caveat is that unionfs(5) is notoriously hard to implement right, is 
very much dependent on lots of VFS internals and was almost unmaintained for a 
very long time.  In the past few years, there has been some significant effort 
to at least stabilize it (avoid crashes, deadlocks and other locking problems, 
etc.), so you may want to give it a shot and see if that is enough for your  
use case.

I've been contracted by the FreeBSD Foundation to work, among others, on a 
full revamp of unionfs, aimed at stability, consistency and well-defined 
behavior in contorted cases, so at least the situation is bound to change, 
although it is not going to happen overnight but will rather take a year or 
more after the kick-off.

Thanks and regards.

-- 
Olivier Certner