Changes

Jump to: navigation, search

Bind mounts

1,041 bytes removed, 13:17, 20 November 2017
m
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.
This is how you can make host system's <code>/mnt/disk</code> directory available to a container 777:<source lang="bash">CTID= Filesystem layout ==OpenVZ uses two directories. Assuming our container is numbered 777, these directories are:
* <code>VE_PRIVATE<echo '#!/bin/bash. /etc/vz/code>: vz.conf. $VZDIR{VE_CONFFILE}SRC=/mnt/diskDST=/privatemnt/777diskif [ ! -e ${VE_ROOT}${DST} ]; then mkdir -p ${VE_ROOT}${DST}; fi* <codemount -n -t simfs ${SRC} ${VE_ROOT}${DST} -o ${SRC}' >VE_ROOT</code>: $VZDIRetc/vz/rootconf/777${CTID}.mount
{{Note|<code>$VZDIR<chmod +x /code> is usually <code>etc/vz</code>, on Debian systems however this is <code>conf/var/lib/vz</code>${CTID}. In this document this is further referred to as <code>$VZDIRmount</codesource> -- substitute it with what you have.}}
If you want read-only mount, add <code>VE_PRIVATE</code> is a place for all the container files. <code>VE_ROOT-r</code> is the mount point option to which <code>VE_PRIVATE</code> is mounted during container start (or when you run <code>vzctl mount</code>command.
{{WarningNote|If you want to do a bind mount for containerWhen specifying destination directory, you need to '''always use <code>/vz/root/ or ${VE_ROOT} env. variable </codenowiki>''' (not <code>VE_PRIVATEavoid using /vz/private)</codenowiki>!) and '''}}{{Note|When binding directories from one container to another, make sure that container is mounted''' you have proper boot order (this can be checked using <code>See [[Man/vzctl status</code>.8|BOOTORDER]] param.).}}
== Mounting ==
Put a script in OpenVZ configuration directory (<code>/etc/vz/conf/</code>) with the name <code>''CTID''.mount</code> (where <code>''CTID''</code> is container ID, like 777). This script Instruction above will be executed every time not work on OpenVZ 7 until you run <code>vzctl mount</code> or <code>vzctl start</code> for a particular container. If you need to the same for all containers, use the global mount script named <code>vps.mount</code>.below to enable Bind mounts:'''
From any mount script you can use the following environment variables:
* <code>${VEID}</code> -- container ID (like <code>777</code>).
* <code>${VE_CONFFILE}</code> -- container configuration file (like <code>/etc/vz/conf/777.conf</code>)
 
Now, in order to get the value of <code>VE_ROOT</code> 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 <code>VE_ROOT</code>.
 
=== Mount script example ===
 
Here is an example of such a mount script (it can either be <code>/etc/vz/conf/vps.mount</code> or <code>/etc/vz/conf/''CTID''.mount</code>)
<source lang="bash">
CTID=777cat << 'EOF ' > /etc/vz/conf/${CTID}vps.mount
#!/bin/bash
source /etc/vz/vz.confsource ${VE_CONFFILE}mount -n -t simfs /mnt/disk VE_MOUNT=$(echo ${VE_ROOTVE_CONFFILE}| sed 's/mnt\.conf$/disk .mount/')[ -o /mnt/diskx ${VE_MOUNT} ] && . ${VE_MOUNT}exit 0
EOF
 chmod +x /etc/vz/conf/${CTID}vps.mount</source>
== See also ==
* {{Man|vzctl|8}} (ACTION SCRIPTS section)
* [[NFS]]
* [[FUSE]]
1
edit

Navigation menu