squashfs is a read only file system. You can do something similar using aufs.
If you are impatient and just want the answer.
Code: Select all
mount -t aufs -o br=/mnt/sda8/writable=rw:/mnt/readonly=ro -o udba=reval none /tmp/aufs-work/
Your module is mounted in /mnt/readonly (it is read only) and you created /mnt/sda8/writable (real file system) and your target working folder is /tmp/aufs-work
Let me explain so you get a better understanding of what modules are and what a union file system does.
You will need a location out of the current aufs. For this example:
/mnt/sda8/writable
## Create a directory with some files in it.
Code: Select all
modprobe aufs ## Just for fun
mkdir -p /tmp/mymodule/{one,two}
touch /tmp/mymodule/file0.txt
## Make a module from it
Code: Select all
mksquashfs /tmp/mymodule /tmp/readonly.xzm
rm -r /tmp/mymodule
## Make a folder to mount your module as read only
Code: Select all
mkdir /mnt/readonly && mount -o loop /tmp/readonly.xzm /mnt/readonly
## Check that you files are in there and read only
Code: Select all
ls /mnt/readonly
touch /mnt/readonly/this.txt
Let's summarize. You have essentially mounted a module (squashfs read only) into the folder: /mnt/readonly
## Now create your writable folder outside of aufs (on a real file system)
## Lastly create a folder where you merged file systems will be. You can work in here.
## Now overlay the two folders together using aufs.
Code: Select all
mount -t aufs -o br=/mnt/sda8/writable=rw:/mnt/readonly=ro -o udba=reval none /tmp/aufs-work/
## If you look in /tmp/aufs you will see the files from your module!
## And it is now writeable (kind of)
Code: Select all
touch /tmp/aufs-work/file2.txt
ls /tmp/aufs-work
Explanation:
mount -t aufs --> mount as a union file system
-o --> arguments that will be passed to the mount command
br= --> the branches you will create
br=/mnt/sda8/writable=rw:/mnt/readonly=ro --> mount the first path as a writable branch and the second path (your module) as a readonly branch.
udba=reval --> this means if a file is added outside of aufs it will re-evaluate
none --> no special device are connected to this
/tmp/aufs-work --> your destination
In fact what you have is two branches mounted overlaying each other.
Think of the /tmp/aufs-work as the tree trunk, and the other two folders as branches connected to the tree.
Because /mnt/readonly is exactly that (read only), any files that you create are sent to the /mnt/sda8/writable branch. If you add a file to this directory it will also appear in your tree.
Code: Select all
touch /mnt/sda8/writable/lookmum-nohands.txt
ls /tmp/aufs-work
Last thing to do is make a module from your additions to your module in /tmp/aufs-work.
If you are still reading then you just learnt something. Perhaps it was how a union file system works. Perhaps it was that bogomips solution is way easier.