According this document it should be possible to use multiple lower layers with overlayfs, but I can't get it to work on kernel 3.18.13. Am I using it wrong, or do I need a later kernel, and if so which one?
this works:
>>>mkdir lower1 lower2 upper workdir merged >>>echo hello > lower1/myfile >>>sudo mount -t overlay overlay -olowerdir=lower1,upperdir=upper,workdir=workdir/ merged >>>cat merged/myfile hello
example very similar to document:
>>>sudo mount -t overlay overlay -olowerdir=lower1:lower2 merged mount: wrong fs type, bad option, bad superblock on overlay, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so. >>>dmesg | tail -n1 [42131.327203] overlayfs: missing upperdir or lowerdir or workdir
ok, lets add them:
>>>sudo mount -t overlay overlay -olowerdir=lower1:lower2,upperdir=upper,workdir=workdir/ merged mount: wrong fs type, bad option, bad superblock on overlay, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so. >>>dmesg | tail -n1 [42155.052961] overlayfs: failed to resolve 'lower1:lower2': -2
It may be tempting to use multiple overlayfs mounts to achieve "stacking" of multiple lower directories, however, this has proven not achievable beyond two mounts with later kernel versions. That is, if you mount one set of upper/lower directories to a mountpoint then use the same mountpoint as another overlayfs mount's lower directory, the third mount attempt would fail and you would see this in dmesg: "overlayfs: maximum fs stacking depth exceeded". I see why a limiting stacking depth is needed, but it is unclear to me why this is currently set to 2.
So if you are stuck with 3.18 and can't yet move to 3.19 (as toto38 suggests) then you are looking for a way to use multiple "lower" directories without recompiling your kernel? If you're using RHEL/Centos/Fedora then funionfs is probably your best bet (yum install funionfs). You can specify multiple read-only lower directories in a single mount command:
funionfs -o dirs=<FIRST_LOWER_RO_DIR_PATH>=RO:<SECOND_LOWER_RO_DIR_PATH>=RO:<UPPER_RW_DIR_PATH> NONE <MOUNT_POINT_DIR_PATH>
I've never compared the performance between overlayfs and funionfs, though overlayfs is working in kernel space and funionfs is in userspace (via fuse) so I'd suppose that funionfs is probably has a bit more overhead than overlayfs.
You can use one existing overlay over another one mounting it many times. Just set the lowerdir of one overlay as the mount point of an existing overlay (and so on...).