OpenVZ – Share a Folder Between Containers

openvz

I want to share a directory from an OpenVZ container to another container, how I could do that?

  1. do a symlink from /vz/private/109/common-stuff to /vz/private/108/common-stuff ?
  2. bind mount /vz/private/109/common-stuff to /vz/root/108/common-stuff ?
  3. Share the directory with samba from the container, mount on the host, then bind mount to /vz/root/108/common-stuff ?

Best Answer

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

Related Topic