[Unionfs] How to synchronized some filesystems merged with unionfs

Erez Zadok ezk at cs.sunysb.edu
Tue Oct 16 10:47:40 EDT 2007


In message <47137867.3060804 at polytechnique.edu>, Sylvain Ferrand writes:
> Hi,
> 
> I'm  designing an embedded system with a read-only root(/) file
> system (a compact flash) combined to a writable tmpfs branch.
> It works very well, but from time to time, I would like to be able to 
> sync the tmpfs branch with the compact flash partition (to save changes 
> made to the system).
> Do you have simples procedures to do that? I'm thinking about to create 
> a special partition and to copy the content of the tmpfs branch on it 
> and later to synchronize during the reboot.
> I'm interested about any ideas or links to articles to do that.
> Thanks,
> 
> Sylvain

Sylvain,

I assume what you mean is that you copyup to the tmpfs branch.  So what you
want to do is sync changes that were made to the tmpfs branch, back to the
original compact flash branch, right?  Well, presumably both of these
branches exist somewhere you can access them, and have unique namespaces.  I
assume you may have done something like this:

1. mount the root in /n/root
2. mount the tmpfs in /n/tmpfs
3. mount unionfs with dirs=/n/tmpfs:/n/root=ro on /mnt/unionfs
4. pivot_root onto /mnt/unionfs

Most people set things up so that even after the pivot_root, you can still
access the "raw" branches in /n/root and /n/tmpfs.  So if you want to sync
them up, you can use any tool to copy changes from /n/tmpfs to /n/root.

My personal favorite is rsync because it's efficient and incremental.
However, rsync can consume a lot of memory initially when it generates a
recursive list of all files and dirs on the client and server, to compare
them for changes.  So if your system is short on memory, and has a lot of
files to consider syncing, then you want to consider something that works
directory-by-directory (I use rdist, but it hasn't been maintained very well
in recent years).  I'm sure there are other tools that can help, including a
simple "cp -au".

Once you copy files over from /n/tmpfs back onto /n/root, unionfs will
detect those changes in [acm]time and will properly flush its caches if and
as needed.  But if you want to be safe, then your tool/script which does the
rsync, should also issue a "mount -o remount,incgen /mnt/unionfs": this
'incgen' option will tell unionfs to force a flush.

Cheers,
Erez.


More information about the unionfs mailing list