Run the following commands on linux (4.4.59 and 4.9.8 are tested) and it will fail:
mkdir -p /tmp/proc
mount -t overlay overlay -o lowerdir=/proc:/tmp/proc /tmp/proc
and there is a error message in dmesg:
overlayfs: maximum fs stacking depth exceeded
Why 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.
/proc"adds another level of indirection"? Is there any tool to show the current stacking depth of a file system? – Duan Yao Jun 19 '17 at 07:51". I don't see any obvious reason why it can't stack deeper" - kernel stacks are very small fixed-size allocations, unlike user-space. https://lwn.net/Articles/692953/
– sourcejedi Jun 19 '17 at 18:35