Run the following commands on linux (4.4.59 and 4.9.8 are tested) and it will fail:mkdir -p /tmp/procmount -t overlay overlay -o lowerdir=/proc:/tmp/proc /tmp/procand there is a error message in dmesg:overlayfs: maximum fs stacking depth exceededWhy can't /proc be a layer of a overlay file system?If I replace /proc with /dev or /sys, it mounts without issue, so it seems there is something special with /proc.P.S. The use case is creating a safer chroot environment, I want to make /dev, /sys and /proc read-only in chroot. There are 2 known workarounds: read-only bind mount. The limitation is two commnads instead one required. read-only special mount: mount -t proc -o ro none /tmp/proc. The limitation is sub-mount not mapped automatically.Anyway, I'm still curious about why /dev and /sys play well with overlay but /proc doesn't.The question is migrated from stackoverflow.
Why can't /proc be a layer of a overlay file system (overlayfs) on linux?
linux;mount;proc;overlayfs
https://github.com/torvalds/linux/commit/e54ad7f1ee263ffa5a2de9c609d58dfa27b21cd9    /*     * procfs isn't actually a stacking filesystem; however, there is     * too much magic going on inside it to permit stacking things on     * top of it     */s->s_stack_depth = FILESYSTEM_MAX_STACK_DEPTH;This might not be a very informative answer, but the kernel developers specifically don't support it.