<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Richard</id>
	<title>OpenVZ Virtuozzo Containers Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Richard"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/Richard"/>
	<updated>2026-05-15T12:33:41Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Bind_mounts&amp;diff=9141</id>
		<title>Bind mounts</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Bind_mounts&amp;diff=9141"/>
		<updated>2010-09-20T10:10:25Z</updated>

		<summary type="html">&lt;p&gt;Richard: /* Read-only bind mounts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Recent Linux kernels support an operation called 'bind mounting' which makes part of a mounted filesystem visible at some other mount point. See 'man mount' for more information.&lt;br /&gt;
&lt;br /&gt;
Bind mounts can be used to make directories on the hardware node visible to the container.&lt;br /&gt;
&lt;br /&gt;
== Filesystem layout ==&lt;br /&gt;
OpenVZ uses two directories. Assuming our container is numbered 777, these directories are:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;VE_PRIVATE&amp;lt;/code&amp;gt;: $VZDIR/private/777&lt;br /&gt;
* &amp;lt;code&amp;gt;VE_ROOT&amp;lt;/code&amp;gt;: $VZDIR/root/777&lt;br /&gt;
&lt;br /&gt;
{{Note|&amp;lt;code&amp;gt;$VZDIR&amp;lt;/code&amp;gt; is usually &amp;lt;code&amp;gt;/vz&amp;lt;/code&amp;gt;, on Debian systems however this is &amp;lt;code&amp;gt;/var/lib/vz&amp;lt;/code&amp;gt;. In this document this is further referred to as &amp;lt;code&amp;gt;$VZDIR&amp;lt;/code&amp;gt; -- substitute it with what you have.}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;VE_PRIVATE&amp;lt;/code&amp;gt; is a place for all the container files. &amp;lt;code&amp;gt;VE_ROOT&amp;lt;/code&amp;gt; is the mount point to which &amp;lt;code&amp;gt;VE_PRIVATE&amp;lt;/code&amp;gt; is mounted during container start (or when you run &amp;lt;code&amp;gt;vzctl mount&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Warning|If you want to do a bind mount for container, you need to '''use &amp;lt;code&amp;gt;VE_ROOT&amp;lt;/code&amp;gt;''' (not &amp;lt;code&amp;gt;VE_PRIVATE&amp;lt;/code&amp;gt;!) and '''make sure that container is mounted''' (this can be checked using &amp;lt;code&amp;gt;vzctl status&amp;lt;/code&amp;gt;).}}&lt;br /&gt;
&lt;br /&gt;
== Manual mount example ==&lt;br /&gt;
&lt;br /&gt;
On the HN we have a directory &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; which we wish to make available (shared) to container 777.&lt;br /&gt;
&lt;br /&gt;
The correct command to issue on the HN is:&lt;br /&gt;
&lt;br /&gt;
  mount --bind /home $VZDIR/root/777/home&lt;br /&gt;
&lt;br /&gt;
The container must be started (or at least mounted) and the destination directory must exist. The container will see this directory mounted like this:&lt;br /&gt;
&lt;br /&gt;
 # df&lt;br /&gt;
 Filesystem           1K-blocks      Used Available Use% Mounted on&lt;br /&gt;
 simfs                 10485760    298728  10187032   3% /&lt;br /&gt;
 ext3                 117662052 104510764   7174408  94% /home&lt;br /&gt;
&lt;br /&gt;
During the container stop vzctl unmounts that bind mount, so you have to mount it again when you start the container for the next time. Luckily there is a way to automate it.&lt;br /&gt;
&lt;br /&gt;
== Make the mount persistent ==&lt;br /&gt;
&lt;br /&gt;
Put a mount script in OpenVZ configuration directory (&amp;lt;code&amp;gt;/etc/vz/conf/&amp;lt;/code&amp;gt;) with the name &amp;lt;code&amp;gt;''CTID''.mount&amp;lt;/code&amp;gt; (where &amp;lt;code&amp;gt;''CTID''&amp;lt;/code&amp;gt; is container ID, like 777). This script will be executed every time you run &amp;lt;code&amp;gt;vzctl mount&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;vzctl start&amp;lt;/code&amp;gt; for a particular container. If you need to the same for all containers, use the global mount script named &amp;lt;code&amp;gt;vps.mount&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
From any mount script you can use the following environment variables:&lt;br /&gt;
* &amp;lt;code&amp;gt;${VEID}&amp;lt;/code&amp;gt; -- container ID (like &amp;lt;code&amp;gt;777&amp;lt;/code&amp;gt;).&lt;br /&gt;
* &amp;lt;code&amp;gt;${VE_CONFFILE}&amp;lt;/code&amp;gt; -- container configuration file (like &amp;lt;code&amp;gt;/etc/vz/conf/777.conf&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
Now, in order to get the value of &amp;lt;code&amp;gt;VE_ROOT&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;VE_ROOT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Mount script example ===&lt;br /&gt;
Here is an example of such a mount script (it can either be &amp;lt;code&amp;gt;/etc/vz/conf/vps.mount&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/vz/conf/''CTID''.mount&amp;lt;/code&amp;gt;)&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 source /etc/vz/vz.conf&lt;br /&gt;
 source ${VE_CONFFILE}&lt;br /&gt;
 mount -n --bind /mnt/disk ${VE_ROOT}/mnt/disk&lt;br /&gt;
&lt;br /&gt;
After creating script please make it executable by issuing &amp;quot;chmod +x CTID.mount&amp;quot; at command line otherwise vm fails to start&lt;br /&gt;
&lt;br /&gt;
=== Unmount script example ===&lt;br /&gt;
For unmounting a filesystem, &amp;lt;code&amp;gt;/etc/vz/conf/vps.umount&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/vz/conf/''CTID''.umount&amp;lt;/code&amp;gt; script can be used in the same way:&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 source /etc/vz/vz.conf&lt;br /&gt;
 source ${VE_CONFFILE}&lt;br /&gt;
 umount ${VE_ROOT}/mnt/disk&lt;br /&gt;
&lt;br /&gt;
{{Note|&amp;lt;code&amp;gt;''CTID''.umount&amp;lt;/code&amp;gt; script is not strictly required, since vzctl tries to unmount everything on CT stop. But you'd better have it anyway.}}&lt;br /&gt;
&lt;br /&gt;
umount scripts could cause trouble and errors on VM start and might not be required if using the -n option on mount. [http://forum.openvz.org/index.php?t=msg&amp;amp;goto=37800&amp;amp;&amp;amp;srch=using+-n+and+no+umount+script#msg_37800 read forum post]&lt;br /&gt;
&lt;br /&gt;
== Read-only bind mounts ==&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 mount -n --bind /home $VZDIR/root/777/home&lt;br /&gt;
 mount -n --bind -oremount,ro $VZDIR/root/777/home&lt;br /&gt;
&lt;br /&gt;
With some kernels you need to add the sourcedirectory also: mount -n --bind -oremount,ro '''/home''' $VZDIR/root/777/home&lt;br /&gt;
&lt;br /&gt;
Sometimes it is usefull to have a folder read-only mounted in a VPS, but also be able to put files in that directory. If you want that, just create an other directory and simlink the read only files into that folder:&lt;br /&gt;
&lt;br /&gt;
 vzctl exec2 777 mkdir /addfileshere &amp;amp;&amp;amp; vzctl exec2 777 ln -s /home/* /addfileshere/&lt;br /&gt;
&lt;br /&gt;
Now the /addfileshere folder is fully writable and it even feels like it is possible to delete files (but that are only the simlinks).&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[NFS]]&lt;br /&gt;
* [[FUSE]]&lt;br /&gt;
* [[Mounting filesystems]]&lt;br /&gt;
&lt;br /&gt;
[[Category:HOWTO]]&lt;/div&gt;</summary>
		<author><name>Richard</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Bind_mounts&amp;diff=9140</id>
		<title>Bind mounts</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Bind_mounts&amp;diff=9140"/>
		<updated>2010-09-20T10:08:48Z</updated>

		<summary type="html">&lt;p&gt;Richard: /* Read-only bind mounts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Recent Linux kernels support an operation called 'bind mounting' which makes part of a mounted filesystem visible at some other mount point. See 'man mount' for more information.&lt;br /&gt;
&lt;br /&gt;
Bind mounts can be used to make directories on the hardware node visible to the container.&lt;br /&gt;
&lt;br /&gt;
== Filesystem layout ==&lt;br /&gt;
OpenVZ uses two directories. Assuming our container is numbered 777, these directories are:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;VE_PRIVATE&amp;lt;/code&amp;gt;: $VZDIR/private/777&lt;br /&gt;
* &amp;lt;code&amp;gt;VE_ROOT&amp;lt;/code&amp;gt;: $VZDIR/root/777&lt;br /&gt;
&lt;br /&gt;
{{Note|&amp;lt;code&amp;gt;$VZDIR&amp;lt;/code&amp;gt; is usually &amp;lt;code&amp;gt;/vz&amp;lt;/code&amp;gt;, on Debian systems however this is &amp;lt;code&amp;gt;/var/lib/vz&amp;lt;/code&amp;gt;. In this document this is further referred to as &amp;lt;code&amp;gt;$VZDIR&amp;lt;/code&amp;gt; -- substitute it with what you have.}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;VE_PRIVATE&amp;lt;/code&amp;gt; is a place for all the container files. &amp;lt;code&amp;gt;VE_ROOT&amp;lt;/code&amp;gt; is the mount point to which &amp;lt;code&amp;gt;VE_PRIVATE&amp;lt;/code&amp;gt; is mounted during container start (or when you run &amp;lt;code&amp;gt;vzctl mount&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Warning|If you want to do a bind mount for container, you need to '''use &amp;lt;code&amp;gt;VE_ROOT&amp;lt;/code&amp;gt;''' (not &amp;lt;code&amp;gt;VE_PRIVATE&amp;lt;/code&amp;gt;!) and '''make sure that container is mounted''' (this can be checked using &amp;lt;code&amp;gt;vzctl status&amp;lt;/code&amp;gt;).}}&lt;br /&gt;
&lt;br /&gt;
== Manual mount example ==&lt;br /&gt;
&lt;br /&gt;
On the HN we have a directory &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; which we wish to make available (shared) to container 777.&lt;br /&gt;
&lt;br /&gt;
The correct command to issue on the HN is:&lt;br /&gt;
&lt;br /&gt;
  mount --bind /home $VZDIR/root/777/home&lt;br /&gt;
&lt;br /&gt;
The container must be started (or at least mounted) and the destination directory must exist. The container will see this directory mounted like this:&lt;br /&gt;
&lt;br /&gt;
 # df&lt;br /&gt;
 Filesystem           1K-blocks      Used Available Use% Mounted on&lt;br /&gt;
 simfs                 10485760    298728  10187032   3% /&lt;br /&gt;
 ext3                 117662052 104510764   7174408  94% /home&lt;br /&gt;
&lt;br /&gt;
During the container stop vzctl unmounts that bind mount, so you have to mount it again when you start the container for the next time. Luckily there is a way to automate it.&lt;br /&gt;
&lt;br /&gt;
== Make the mount persistent ==&lt;br /&gt;
&lt;br /&gt;
Put a mount script in OpenVZ configuration directory (&amp;lt;code&amp;gt;/etc/vz/conf/&amp;lt;/code&amp;gt;) with the name &amp;lt;code&amp;gt;''CTID''.mount&amp;lt;/code&amp;gt; (where &amp;lt;code&amp;gt;''CTID''&amp;lt;/code&amp;gt; is container ID, like 777). This script will be executed every time you run &amp;lt;code&amp;gt;vzctl mount&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;vzctl start&amp;lt;/code&amp;gt; for a particular container. If you need to the same for all containers, use the global mount script named &amp;lt;code&amp;gt;vps.mount&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
From any mount script you can use the following environment variables:&lt;br /&gt;
* &amp;lt;code&amp;gt;${VEID}&amp;lt;/code&amp;gt; -- container ID (like &amp;lt;code&amp;gt;777&amp;lt;/code&amp;gt;).&lt;br /&gt;
* &amp;lt;code&amp;gt;${VE_CONFFILE}&amp;lt;/code&amp;gt; -- container configuration file (like &amp;lt;code&amp;gt;/etc/vz/conf/777.conf&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
Now, in order to get the value of &amp;lt;code&amp;gt;VE_ROOT&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;VE_ROOT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Mount script example ===&lt;br /&gt;
Here is an example of such a mount script (it can either be &amp;lt;code&amp;gt;/etc/vz/conf/vps.mount&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/vz/conf/''CTID''.mount&amp;lt;/code&amp;gt;)&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 source /etc/vz/vz.conf&lt;br /&gt;
 source ${VE_CONFFILE}&lt;br /&gt;
 mount -n --bind /mnt/disk ${VE_ROOT}/mnt/disk&lt;br /&gt;
&lt;br /&gt;
After creating script please make it executable by issuing &amp;quot;chmod +x CTID.mount&amp;quot; at command line otherwise vm fails to start&lt;br /&gt;
&lt;br /&gt;
=== Unmount script example ===&lt;br /&gt;
For unmounting a filesystem, &amp;lt;code&amp;gt;/etc/vz/conf/vps.umount&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/vz/conf/''CTID''.umount&amp;lt;/code&amp;gt; script can be used in the same way:&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 source /etc/vz/vz.conf&lt;br /&gt;
 source ${VE_CONFFILE}&lt;br /&gt;
 umount ${VE_ROOT}/mnt/disk&lt;br /&gt;
&lt;br /&gt;
{{Note|&amp;lt;code&amp;gt;''CTID''.umount&amp;lt;/code&amp;gt; script is not strictly required, since vzctl tries to unmount everything on CT stop. But you'd better have it anyway.}}&lt;br /&gt;
&lt;br /&gt;
umount scripts could cause trouble and errors on VM start and might not be required if using the -n option on mount. [http://forum.openvz.org/index.php?t=msg&amp;amp;goto=37800&amp;amp;&amp;amp;srch=using+-n+and+no+umount+script#msg_37800 read forum post]&lt;br /&gt;
&lt;br /&gt;
== Read-only bind mounts ==&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 mount -n --bind /home $VZDIR/root/777/home&lt;br /&gt;
 mount -n --bind -oremount,ro $VZDIR/root/777/home&lt;br /&gt;
&lt;br /&gt;
With some kernels you need to add the sourcedirectory also: mount -n --bind -oremount,ro '''/home''' $VZDIR/root/777/home&lt;br /&gt;
&lt;br /&gt;
Sometimes it is usefull to have a folder read-only mounted in a VPS, but also be able to put files in that directory. If you want that, just create an other directory and simlink the read only files into that folder:&lt;br /&gt;
&lt;br /&gt;
 vzctl exec2 777 mkdir /addfileshere &lt;br /&gt;
 ln -s /home/* /addfileshere/&lt;br /&gt;
&lt;br /&gt;
Now the /addfileshere folder is fully writable and it even feels like it is possible to delete files (but that are only the simlinks).&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[NFS]]&lt;br /&gt;
* [[FUSE]]&lt;br /&gt;
* [[Mounting filesystems]]&lt;br /&gt;
&lt;br /&gt;
[[Category:HOWTO]]&lt;/div&gt;</summary>
		<author><name>Richard</name></author>
		
	</entry>
</feed>