Search code examples
linuxdebianvirtualizationchroot

Is it possible let chroot jails share directories(read-only) outside the jail?


I have muliple chroot jails, I want them to share some directories, currently I have to copy these directories into jails which I think is not elegant. The directories are read-only, like '/usr/bin'.


Solution

  • You can use the new bind mounts support to make identical directory structures available through multiple paths.

    mount --bind /usr/bin /path/to/chroot/jail/usr/bin
    mount -o remount,ro /path/to/chroot/jail/usr/bin
    

    For more details, see mount(8).

    You can get really clever with mounting on Linux systems these days; for more details, see the Linux kernel source file Documentation/filesystems/sharedsubtree.txt.