Search code examples
linuxubuntudebianmount

How provide nested mount of overlayfs


I try mount layer of overlayfs as lower layer next overlayfs, but after two layer it's crash

mount -t overlayfs -o rw,lowerdir=/tmp/test/layers/centos5.6-layer0-lower,upperdir=/tmp/test/layers/centos5.6-layer0-upper overlayfs /tmp/mount/centos5.6-layer0-mount
# remove deleted files into overlayfs
find /tmp/mount/centos5.6-layer0-mount -lname '(overlay-whiteout)' -exec rm -rf {} \;

mount -t overlayfs -o rw,lowerdir=/tmp/mount/centos5.6-layer0-mount,upperdir=/tmp/test/layers/centos5.6-layer1-upper overlayfs /tmp/mount/centos5.6-layer1-mount
# remove deleted files into overlayfs
find /tmp/mount/centos5.6-layer1-mount -lname '(overlay-whiteout)' -exec rm -rf {} \;

mount -t overlayfs -o rw,lowerdir=/tmp/mount/centos5.6-layer1-mount,upperdir=/tmp/test/layers/centos5.6-layer2-upper overlayfs /tmp/mount/centos5.6-layer2-mount
mount: wrong fs type, bad option, bad superblock on overlayfs,
       missing codepage or helper program, or other error
       (for several filesystems (e.g. nfs, cifs) you might
       need a /sbin/mount.<type> helper program)
       In some cases useful info is found in syslog - try
       dmesg | tail  or so
# remove deleted files into overlayfs
find /tmp/mount/centos5.6-layer2-mount -lname '(overlay-whiteout)' -exec rm -rf {} \;

mount -t overlayfs -o rw,lowerdir=/tmp/mount/centos5.6-layer2-mount,upperdir=/tmp/test/layers/centos5.6-layer3-upper overlayfs /tmp/mount/centos5.6-layer3-mount
find /tmp/mount/centos5.6-layer3-mount -lname '(overlay-whiteout)' -exec rm -rf {} \;

How can I provide more then 2 layer?


Solution

  • If you check dmesg output, you will see the kernel stating an attempt to exceed the max stacking depth:

    overlayfs: maximum fs stacking depth exceeded
    

    Indeed, the stacking depth is limited to 2, see the overlayfs dev branch:

    If you want to go beyond this depth, you could try changing the constant and building your own kernel. However, bear in mind the risk of overflowing the stack (per the comments).