OpenVZ: share a folder between containers

Solution 1:

OpenVZ is great at letting you share directories without the need for Samba or NFS overhead.

To see how it works do a bind mount to root (not private) when the container is running:

mount --bind /vz/private/109/common-stuff /vz/root/108/common-stuff

To make the share persistent over container reboots:

  1. Put Script A into /etc/vz/conf/108.mount
  2. Run chmod +x /etc/vz/conf/108.mount

Script A

#!/bin/bash
source /etc/vz/vz.conf
source ${VE_CONFFILE}
mount -n --bind /vz/private/109/common-stuff /vz/root/108/common-stuff

Reference: http://wiki.openvz.org/Bind_mounts

Solution 2:

the page give by Aleksandr Levchuk give the following script

CTID=777
echo '#!/bin/bash
. /etc/vz/vz.conf
. ${VE_CONFFILE}
SRC=/mnt/disk
DST=/mnt/disk
if [ ! -e ${VE_ROOT}${DST} ]; then mkdir -p ${VE_ROOT}${DST}; fi
mount -n -t simfs ${SRC} ${VE_ROOT}${DST} -o ${SRC}
' > /etc/vz/conf/${CTID}.mount

chmod +x /etc/vz/conf/${CTID}.mount

(http://wiki.openvz.org/Bind_mounts)

so it's different from the mount --bind in his solution. I've tested the above script, and it works perfecly.

from what I've seen, "SIMFS is like a separate drive space set aside for virtual containers. It's set up for machine use, and prevents one containers virtual server from crashing any of the others."

So it should be better for security reason (plus the fact that it's in the official openvz documentation). However It could be interesting to assess the performance cost of this isolation.