Mounting Filesystem over existing directory

Michael Conrad mconrad at intellitree.com
Wed May 30 17:42:37 UTC 2012


On 5/30/2012 3:08 AM, Sameer Naik wrote:
> Thanks for the quick response. I will check out the links Bartos provided.
> Certainly, my query is not related to busybox, but where else can i
> find a better community for my query :)
>
> Regards
> ~Sameer

Indeed, you're posting your question to a lot of people who have done 
this exact thing :-)

I found aufs to be more experimental with lots of fancy features... but 
wasn't stable enough for me.  (this changes over time and by kernel 
version, of course, but when I tested it 3 years ago I got some strange 
results)  Unionfs has worked flawlessly for me on multiple kernels.

Unionfs has one problem though: the only way to get correct behavior is 
to merge path A and B onto mountpoint C.  (C can't be the same as A or B).

What I came up with was to use the rootfs that Linux creates for the 
initramfs, and have the following symlink pattern:

/etc -> /union/etc
/bin -> /union/bin
...
/union/etc -> /initrd/etc
/union/bin -> /initrd/bin
...
All of that lives in the initramfs and is loaded immediately.

Then, I mount the system image at /sysimage, and then

mount -t unionfs -o dirs=/initrd=rw:/sysimage/fhs=ro none /union || die 
"Failed to set up unionfs";

This hides the second level of symlinks and uses the unionfs 
*atomically*, and since I'm using the rootfs, I don't have to mount my 
own tmpfs or switchroot or anything like that.  Also, my system uses the 
one busybox binary that it loaded out of initramfs for the entire life 
of the system, so no need to worry about freeing up the resources used 
by the initramfs.

Also, the entire system becomes writable, and if I want to know what I 
changed I can just rsync /initrd to my development machine and see what 
new files exist, and integrate them into my next system image.  I can 
also selective revert things to default while the system is running by 
deleting files out of /initrd.

-Mike


More information about the busybox mailing list