Mounting Filesystem over existing directory

Sameer Naik sameer.subscriptions at damagehead.com
Fri Jun 1 07:24:53 UTC 2012


Hello Conrad,

First of, I was able to successfully test (very basic testing) unionfs
for my case. I used the latest version of unionfs (2.5.11).

On Wed, May 30, 2012 at 11:12 PM, Michael Conrad
<mconrad at intellitree.com> wrote:
> 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.

I was able to get UnionFS configured into the system rather quickly. I
will stick to unionfs, cause i don't think i need to do too many
"fancy" things.

>
> 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).

With UnionFS-2.5.11 i could merge /var/cache/etc=rw and /etc=ro at
/etc. But evidently i have no real world testing going on here. Is
there any specific test case i should try to confirm this?

>
> 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";
>

Great! this is very ingenious.

> 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.

Out of curiosity, Is is possible to free up the resources used by
initramfs. I would be very interested in knowing how this can be done.

>
> Also, the entire system becomes writable, and if I want to know what I

Just one word. WOW

> 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

It appears like you have done mostly what i am trying to do.
I am guessing that maybe most of your work has been for a LiveCD filesystem.

In my case, i am developing a system for an embedded system with NAND
storage. Due to NAND corruption issues that mostly arise right now is
when system is powered off while NAND writes are being performed (i.e.
when files are being flushed out to the filesystem). This corruption
makes the system un-bootable. Due to this issue i want to make the
NAND filesystem readonly. Only at the time of system updates the
filesystem will be remounted in rw mode. This still leaves room for
the corruption to occur during system updates.

Right now i am thinking of having a initramfs filesystem with a
recovery system that starts a device recovery process if the system
partition cannot be mounted. So the intention is:

1. Load Kernel with initramfs filesystem
2. Try to mount system partition (NAND)
3. If mount successful continue boot process from the mounted system
partition (i think i would have to use switchroot or chroot or
something here, not sure how this will work)
4. If mount fails, continue boot process from the initramfs and launch
into recovery system.

Problem with this system is, I may not be able to release the
resources used by the initramfs after switching the root (at least i
am not aware how it should be done). Your technique to reusing the
initramfs may work well here if i cannot release the initramfs after
the sysimage is mounted.

Any ideas?

Regards
~Sameer


More information about the busybox mailing list