Mounting Filesystem over existing directory
Laurent Bercot
ska-dietlibc at skarnet.org
Wed May 30 06:24:10 UTC 2012
> Consider that i have a readonly filesystem mounted at / and that the
> /etc folder consists of some files. Is is possible to mount a ramfs
> filesystem at /etc such that the existing files in the /etc partition
> are still accessible and any new files written to the /etc partition
> are saved in the ramfs (which will be lost upon reboot).
It *might* be possible with some funky Linux mount option I can't
remember. But you don't actually *need* that, since what you want can
be achieved in a portable way with just a tiny bit of scripting.
* Have /img/etc (or whatever directory you want in your root
filesystem) contain your original /etc files.
* Have your original /etc be a set of symlinks to /img/etc. For instance,
/etc/fstab is a symlink to /img/etc/fstab.
* When you create your tmpfs, also copy all of /img/etc to your new tmpfs.
mount -t tmpfs -o mode=0755 tmpfs /etc
cp -a /img/etc/* /etc/
Of course, that operation must be done atomically, i.e. no other
process should be running when you're performing the mount+cp.
* That's it.
You'll probably want a writable filesystem for more than /etc though,
so if you want to avoid multiplicating tmpfs mounts, adjust and adapt
so that your new /etc is a subdirectory of your tmpfs.
--
Laurent
More information about the busybox
mailing list