site  contact  subhomenews

Finally got overlay filesystem to work

September 02, 2025 — BarryK
There has been a long history of reporting failure with overlayfs, for example:

"Overlay filesystem is still a disaster"
https://bkhome.org/news/202402/overlay-filesystem-is-still-a-disaster.html

Today there has been a breakthrough.

In a partition with ext4 filesystem, I have created these folders, and file 'easy.sfs' placed ready to be mounted:

img1

...this sets the scene for overlayfs experiments. Folder 'dir-ro' will be the bottom read-only layer, so mount easy.sfs on it:

# busybox mount -t squashfs -o loop,ro easy.sfs dir-ro

OK, now create the overlayfs:

# busybox mount -t overlay -o lowerdir=dir-ro,upperdir=dir-rw,workdir=dir-wkg overlay dir-top

I then perform various operation indside 'dir-top', like delete a file, rename a folder, and examine inside 'dir-rw' and yes, everything as expected.

Now getting onto trouble; setting up like it is in EasyOS, with 'dir-rw' a "zram" with ext2 filesystem. In experiments sometime ago, I found that overlayfs doesn't like ext2; although it has extended attributes enabled in the kernel configuration, something is lacking.

But, I will try ext2 again. Now, if a ext2 zram is to be mounted on 'dir-rw', then a requirement of overlayfs is that folder 'dir-wkg' must be in the same filesystem. OK:

# busybox umount dir-top
# mke2fs -L "TESTZRAM" -m 0 -b 4096 -t ext2 /dev/zram2
# busybox mount -t ext2 /dev/zram2 dir-rw
# mkdir dir-rw/dir-wkg
# mkdir dir-rw/dir-rw
# busybox mount -t overlay -o lowerdir=dir-ro,upperdir=dir-rw/dir-rw,workdir=dir-rw/dir-wkg overlay dir-top

...success.

Alright, what about ext2, is it good enough? In dir-rw/dir-top, trying to rename a directory:

# cd dir-rw/dir-top/root/my-documents
# mv -f clipart clipart-renamed
mv: cannot move 'clipart' to a subdirectory of itself, 'clipart-renamed'

Yep, that's the previous discovery I made. The problem is ext2, it needs to be ext4. So, unmount overlayfs and zram and start from scratch:

# mke2fs -L "TESTZRAM" -m 0 -b 4096 -t ext4 -O ^64bit,^has_journal /dev/zram2
# busybox mount -t ext4 /dev/zram2 dir-rw
# mkdir -p dir-rw/dir-rw
# mkdir -p dir-rw/dir-wkg
# busybox mount -t overlay -o lowerdir=dir-ro,upperdir=dir-rw/dir-rw,workdir=dir-rw/dir-wkg overlay dir-top

Now try that same folder rename:

# mv -f clipart clipart-renamed
#

...success! Looking in dir-rw/dir-rw/root/my-documents:

img2

...the renamed folder, and 'clipart' is a character file, with 0/0 major/minor device numbering; this is the equivalent to aufs's .wh.* whiteout files.

It will seem that now I can get EasyOS to use overlayfs, but it is going to require a major rewrite of the 'init' script in the initrd. Which will probably be a good thing anyway, as the 'init' script has a very long history, since 2017, and has accumulated code that can be refined or even removed.

For anyone interested, here is the kernel documentation for overlayfs:

https://docs.kernel.org/filesystems/overlayfs.html

Oh, there is one more thing that I should mention. In the previous tests of overlayfs that were dismal failures, there is one change between then and today's test; I enabled squashfs support for extended attributes in the kernel. I discounted this a relevant, as that is the read-only layer, but perhaps overlayfs needs to read the xattr status of the folders and files in easy.sfs

So, yeah, perhaps that is a factor, a vital factor, that has fixed overlayfs.    

Tags: easy