Bind mounts
Bind mounts can be used to make directories on the hardware node visible to the container.
Contents
Filesystem layout
OpenVZ uses two directories. Assuming our container is numbered 777, these directories are:
VE_PRIVATE
: $VZDIR/private/777VE_ROOT
: $VZDIR/root/777
Note: $VZDIR is usually /vz , on Debian systems however this is /var/lib/vz . In this document this is further referred to as $VZDIR -- substitute it with what you have.
|
VE_PRIVATE
is a place for all the container files. VE_ROOT
is the mount point to which VE_PRIVATE
is mounted during container start (or when you run vzctl mount
Warning: If you want to do a bind mount for container, you need to use VE_ROOT (not VE_PRIVATE !) and make sure that container is mounted (this can be checked using vzctl status ).
|
Mounting
Put a script in OpenVZ configuration directory (/etc/vz/conf/
) with the name CTID.mount
(where CTID
is container ID, like 777). This script will be executed every time you run vzctl mount
or vzctl start
for a particular container. If you need to the same for all containers, use the global mount script named vps.mount
.
From any mount script you can use the following environment variables:
${VEID}
-- container ID (like777
).${VE_CONFFILE}
-- container configuration file (like/etc/vz/conf/777.conf
)
Now, in order to get the value of VE_ROOT
you need to source both the global OpenVZ configuration file, and then the container configuration file, in that particular order. This is the same way vzctl uses to determine VE_ROOT
.
Mount script example
Here is an example of such a mount script (it can either be /etc/vz/conf/vps.mount
or /etc/vz/conf/CTID.mount
)
<source lang="bash">
CTID=777
cat << EOF > /etc/vz/conf/${CTID}.mount
- !/bin/bash
source /etc/vz/vz.conf source ${VE_CONFFILE} mount -n -t simfs /mnt/disk ${VE_ROOT}/mnt/disk -o /mnt/disk EOF chmod +x /etc/vz/conf/${CTID}.mount