Open main menu

OpenVZ Virtuozzo Containers Wiki β

Changes

Bind mounts

80 bytes added, 09:28, 11 July 2011
use source tag
=== 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">#!/bin/bash source /etc/vz/vz.conf source ${VE_CONFFILE} mount -n --bind /mnt/disk ${VE_ROOT}/mnt/disk</source>
After creating script please make it executable by issuing "chmod +x CTID.mount" at command line otherwise vm fails to start
For unmounting a filesystem, <code>/etc/vz/conf/vps.umount</code> or <code>/etc/vz/conf/''CTID''.umount</code> script can be used in the same way:
<source lang="bash">#!/bin/bash source /etc/vz/vz.conf source ${VE_CONFFILE} umount ${VE_ROOT}/mnt/disk</source>
{{Note|<code>''CTID''.umount</code> script is not strictly required, since vzctl tries to unmount everything on CT stop. But you'd better have it anyway.}}
Since Linux kernel 2.6.26, bind mounts can be made read-only. The trick is to first mount as usual, and then remount it read-only:
<source lang="bash">mount -n --bind /home $VZDIR/root/777/home mount -n --bind -oremount,ro $VZDIR/root/777/home</source>
With some kernels you need to add the sourcedirectory also: mount -n --bind -oremount,ro '''/home''' $VZDIR/root/777/home