I am designing a Linux distro and was toying with the idea of creating pre-packaged compressed bits of the filesystem that are merged with a read-only file system, and from there stacked under a ramdisk via a UnionFS mount point. The bits would be like packages in a sense, except instead of being installed, they would be mounted as part of the filesystem in RAM and are read directly from the read-only disk (vs. copied into memory).

I was wondering how this might be done without creating a ton of mount points, copying more than is necessary into RAM, or creating a lot of overhead by stacking a whole bunch of tiny filesystems.

...or if it's even possible.

I'm using UnionFS-FUSE and Cloop.


You should definitely try aufs, which is described as "An entirely re-designed and re-implemented Unionfs". From what I've seen, many "live" distros use it for multi-part in-memory filesystems just as you seem to be aiming.

  • Do I have to patch the kernel, or can I compile a .ko? – amphetamachine Aug 15 '11 at 13:26
  • It depends on the version and the base kernel sources you use. For example, the zen kernel provides a source tree already patched for aufs. Various scenarios are also covered on the aufs homepage - see point 2. Download. – rozcietrzewiacz Aug 15 '11 at 13:58
  • Also, distribution-specific packages can do some work for you here. For example on Gentoo, I can just use USE=kernel-patch emerge aufs2 and the kernel will get patched and the module built. – rozcietrzewiacz Aug 15 '11 at 14:04

As suggested, you might use a combination of squashfs (for compression) and AUFS (to stack and merge filesystem layers together). Where AUFS stands for yet Another Union File System. But how is that implemented? I offer here a simple example script to implement squashfs/aufs...

But first, I find that aufs is supported for the Debian kernel, but not for Ubuntu :-( So provided that your distro is proper Debian-based, we can proceed to install some basic tools, thusly

apt-get install squashfs-tools aufs-tools

And now to the commands. The mksquashfs command is used to compress directory(s) into compressed modules. Two squashfs modules are created here, and mounted to make their files accessible. We then create an aufs, with one writable branch, and two readonly branch (ie. the squashfs). The options provided to the mount command specify the branches (see man aufs). Finally, we create a file, to test that file changes do indeed get written to the writable layer.

So I hope this is helpful.


# apt-get install squashfs-tools aufs-tools

# The aim:- to create an aufs/squashfs that merges the file contents of /etc and /sbin 

mkdir -p temp/{ro1,ro2,changes-dir,aufs-dir}  &&  cd temp

# compress the files of etc and sbin into squashfs modules
# using /etc and /sbin only becos they are handy
mksquashfs /etc  etc.sqsh -b 65536
mksquashfs /sbin  sbin.sqsh -b 65536

# now mount the squashfs modules to make their files accessible
mount -o ro,loop etc.sqsh ro1
mount -o ro,loop sbin.sqsh ro2

# AUFS is the acronym for Another Union FileSystem
# mount aufs with 3 branches -  a writable branch, and two readonly branchs
mount -t aufs -o br:$PWD/changes-dir=rw,br:$PWD/ro1=ro,br:$PWD/ro2=ro none $PWD/aufs-dir

cd aufs-dir
echo " make some file changes here, to prove the aufs filesystem is writable"
touch rofl
cd -

umount aufs-dir
umount ro1
umount ro2

# and finally we look into changes-dir, to see the stored file changes 
ls changes-dir

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.