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?

link|improve this question
feedback

1 Answer

up vote 2 down vote accepted

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.

link|improve this answer
Exactly what I was looking for. Thanks! – phihag Nov 1 '11 at 21:49
feedback

Your Answer

 
or
required, but never shown

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