1
edit
Changes
m
Recent Linux kernels support an operation called 'bind mounting' which makes part of a mounted filesystem visible at some other mount point. See 'man bind' for more information.
OpenVZ uses two directories. Assuming our container This is numbered 777, these directories are: $VZROOT/private/777 $VZROOT/root/777 {{Note|how you can make host system's <code>$VZROOT</code> is usually <code>mnt/vzdisk</code>, on Debian systems however this is <code>/var/lib/vz</code>. In this document this is further referred directory available to as <code>$VZROOT</code> -- substitute it with what you have.}} The $VZROOT/private directory contains root directory contents. This directory or subdirectory may be symlinked onto a different file system, for examplecontainer 777: $VZROOT/private -<source lang="bash"> /mnt/openvz CTID== Requirement == '''On the HN we have a directory <code>/home</code> which we wish to make available (shared) to all containers.'''777
You would think that you could bind mount this directory, as in: <code>mount --bind echo '#!/bin/bash. /etc/vz/home vz.conf. $VZROOT{VE_CONFFILE}SRC=/privatemnt/777diskDST=/home<mnt/code> but this does not work — the contents of <codediskif [ ! -e ${VE_ROOT}${DST} ]; then mkdir -p ${VE_ROOT}${DST}; fimount -n -t simfs ${SRC} ${VE_ROOT}${DST} -o ${SRC}' >/home<etc/vz/conf/code> cannot be seen within the container${CTID}.mount
This is where the second directory listed above (<code>$VZROOTchmod +x /etc/vz/rootconf/777${CTID}.mount</codesource>) is used. If a container is not started, this directory is empty. But after starting a container, this directory contains what the container sees as its mounted file systems.
The correct If you want read-only mount, add <code>-r</code> option to mount command to issue on the HN is:.
mount --bind {{Note|When specifying destination directory, always use /home vz/root/ or $VZROOT{VE_ROOT} env. variable <nowiki>(avoid using /rootvz/private)</777nowiki>}}{{Note|When binding directories from one container to another, make sure you have proper boot order (See [[Man/homevzctl.8|BOOTORDER]] param.)}}
The container must be started and the destination directory must exist. The container will see this directory mounted like this:
# df Filesystem 1K-blocks Used Available Use% Mounted '''Instruction above will not work on simfs 10485760 298728 10187032 3% / tmpfs 484712 0 484712 0% /lib/init/rw tmpfs 484712 0 484712 0% /dev/shm ext3 117662052 104510764 7174408 94% /homeOpenVZ 7 until you run the script below to enable Bind mounts:'''
Since Linux kernel 2.6.26, bind mounts can be made read-only. The trick is to first mount as usual, and then do remount (i.echmod +x /etc/vz/conf/vps. mount with <code>-o remount,ro</codesource> flags).
Better wording to clarify that the additional script is not a replacement for the one above, but rather needs to be run first.
Bind mounts can be used to make directories on the hardware node visible to the container.
<source lang="bash">cat <<'EOF' > /etc/vz/conf/vps.mount#!/bin/bash. ${VE_CONFFILE}VE_MOUNT= Read$(echo ${VE_CONFFILE} | sed 's/\.conf$/.mount/')[ -only bind mounts ==x ${VE_MOUNT} ] && . ${VE_MOUNT}exit 0EOF
== See also ==
* {{Man|vzctl|8}} (ACTION SCRIPTS section)
* [[NFS]]
* [[FUSE]]
* [[Mounting filesystems]]
[[Category:HOWTO]]