I have multiple chroots with different sets of software version as a light-weight alternative to VMs.

How can I share a directory across the VMs? Naturally, symlinks do not allow to escape a chroot. Sure, I could mount a network share (via nfs or so) in each chroot, but that would impose a significant overhead and security considerations, wouldn't it?


On Linux – bind mounts.

mount --bind /orig /vm/one
mount --bind /orig /vm/two
mount --rbind /media /vm/one/media

Sharing /proc and /dev is the most common use for this (but make sure you use --rbind for /dev). You can even add -o ro for read-only.

To make the mounts persistent, update /etc/fstab:

/orig   /vm/one     none    bind
/orig   /vm/two     none    bind,ro

Once you start with using bind mounts for VMs, you will soon find yourself deep in namespaces and containers. (For example, you can have a chroot with isolated network, with just a single command...) Take a look at lxc, which uses native Linux features to create virtual systems.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.