<?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=Chernomor</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=Chernomor"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/Chernomor"/>
	<updated>2026-06-13T16:32:40Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Bind_mounts&amp;diff=8470</id>
		<title>Bind mounts</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Bind_mounts&amp;diff=8470"/>
		<updated>2010-04-13T10:05:24Z</updated>

		<summary type="html">&lt;p&gt;Chernomor: set Category:HOWTO&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 --bind /mnt/disk ${VE_ROOT}/mnt/disk&lt;br /&gt;
&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;
== 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 --bind /home $VZDIR/root/777/home&lt;br /&gt;
 mount --bind -oremount,ro $VZDIR/root/777/home&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>Chernomor</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=NFS_server_inside_container&amp;diff=7255</id>
		<title>NFS server inside container</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=NFS_server_inside_container&amp;diff=7255"/>
		<updated>2009-04-24T08:18:38Z</updated>

		<summary type="html">&lt;p&gt;Chernomor: Notes about nfs-user-server and busybox.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There are two ways to setup NFS server on common [[HN]]:&lt;br /&gt;
use a user-space NFS server daemon or use an in-kernel implementation&lt;br /&gt;
of NFS server. Some peculiarities appear if you intend to run NFS server&lt;br /&gt;
in [[container]].&lt;br /&gt;
&lt;br /&gt;
{{Note|for information about NFS client inside container, see [[NFS]].}}&lt;br /&gt;
&lt;br /&gt;
== Kernel NFS server ==&lt;br /&gt;
Binary RPMs that are provided by OpenVZ community contain kernels compiled&lt;br /&gt;
without NFS server support. Thus you have to&lt;br /&gt;
[[Kernel build|recompile the kernel]] with &amp;lt;code&amp;gt;CONFIG_NFSD=m&amp;lt;/code&amp;gt;. After booting in this kernel you'll be able&lt;br /&gt;
to use NFS server on [[HN]].&lt;br /&gt;
In-kernel NFS server runs kernel threads to service requests of clients.&lt;br /&gt;
But for security reasons kernel threads are prohibited in [[container]]s! So you won't&lt;br /&gt;
be able to run NFS server inside [[container]] without patching the kernel.&lt;br /&gt;
&lt;br /&gt;
== User-space NFS server ==&lt;br /&gt;
Advantage of user-space NFS server is that it does not require kernel support.&lt;br /&gt;
Also if it crashes — there is no crash of the system: just one process dies, not the kernel!&lt;br /&gt;
The disadvantage of user-space NFS server is its productivity: no one can be faster than in-kernel implementation.&lt;br /&gt;
&lt;br /&gt;
One well-known implementation of NFS server is &amp;quot;The LINUX User-Space NFS Server&amp;quot; by Olaf Kirch.&lt;br /&gt;
Some Linux distributions contain this package: Debian Sarge (&amp;lt;code&amp;gt;nfs-user-server&amp;lt;/code&amp;gt;), OpenSUSE 10.0 (&amp;lt;code&amp;gt;nfs-server&amp;lt;/code&amp;gt;).&lt;br /&gt;
For other distributions you can download sources (for example from Debian repository) and compile it.&lt;br /&gt;
There is a small trick you have to know about running &amp;lt;code&amp;gt;mountd&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;nfsd&amp;lt;/code&amp;gt; (these two daemons and &amp;lt;code&amp;gt;portmap&amp;lt;/code&amp;gt; constitute a user-space server).  You should run them with the &amp;lt;code&amp;gt;-r&amp;lt;/code&amp;gt; option:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# portmap&lt;br /&gt;
# rpc.mountd -r&lt;br /&gt;
# rpc.nfsd -r&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The reason is that these daemons check the major number of the device where the directory to export resides.&lt;br /&gt;
If major equals 0 then daemons assume that it is NFS and don't want to re-export it. Symptoms are&lt;br /&gt;
that clients will always get a &amp;quot;permission denied&amp;quot; error. Simfs (the file system on which container is located)&lt;br /&gt;
is associated with so called unnamed device, in which major equals 0. So, to prevent daemons from checking for&lt;br /&gt;
re-exporting — just use this &amp;lt;code&amp;gt;-r&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
“The LINUX User-Space NFS Server” by Olaf Kirch implements NFSv2. It means that only files with sizes less&lt;br /&gt;
than 2GB are processed. If you intend to use such big files then you should use another user-space NFS server&lt;br /&gt;
implementation: [http://unfs3.sourceforge.net/ unfs3]. It implements v3 of NFS protocol standard.&lt;br /&gt;
&lt;br /&gt;
Please note that the user-space NFS server does not provide locking, or at least I couldn't get locking to work - [[User:Elronxenu|Elronxenu]] 19:49, 15 November 2007 (EST)&lt;br /&gt;
&lt;br /&gt;
=== On Debian Lenny ===&lt;br /&gt;
&lt;br /&gt;
The current stable debian version 5.0 (lenny) provides two packages for user space nfs support: &amp;lt;code&amp;gt;nfs-user-server&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;unfs3&amp;lt;/code&amp;gt;. Here i describe my experiences with them --[[User:Strimo|Strimo]] 17:47, 16 February 2009 (UTC)&lt;br /&gt;
&lt;br /&gt;
==== nfs-user-server ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aptitude install nfs-user-server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First i used nfs-user-server package since i didn't know unfs3. After installing i always got the '''permission denied''' error when i tried to mount any exported path until i found this article. So i patched the /etc/init.d/nfs-user-server file to include the &amp;lt;code&amp;gt;-r&amp;lt;/code&amp;gt; parameter by adding &amp;lt;code&amp;gt;-- -r&amp;lt;/code&amp;gt; to the &amp;lt;code&amp;gt;start-stop-daemon&amp;lt;/code&amp;gt; line responsible for starting &amp;lt;code&amp;gt;rpc.mountd&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;rpc.nfsd&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        start-stop-daemon --start --oknodo --quiet --exec /usr/sbin/rpc.nfsd -- -r&lt;br /&gt;
        start-stop-daemon --start --oknodo --quiet --exec /usr/sbin/rpc.mountd -- -r&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the modification and a nfs server restart (&amp;lt;code&amp;gt;/etc/init.d/nfs-user-server restart&amp;lt;/code&amp;gt;) i was able to mount a nfs share. At first the nfs server seems to work fine but anytime i want to edit any text file (using nano or mcedit) i got strange errors on writing to the file and i never solved the problem nor detected why this happens. So i switched to unfs3 ...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note&amp;lt;/b&amp;gt;: nfsmount from busybox not works with nfs-user-server in Debian Lenny, it write message &amp;quot;rpc failed: 2&amp;quot; when I try boot from nfs server. unfs3 works fine.&lt;br /&gt;
Such problem into Ubuntu: https://bugs.launchpad.net/ubuntu/+source/nfs-user-server/+bug/189593&lt;br /&gt;
&lt;br /&gt;
==== unfs3 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aptitude install unfs3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Works fine until now. Note that both unfs3 and nfs-user-server do not support file locking!&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [http://nfs.sourceforge.net/ Linux NFS Overview, FAQ and HOWTO Documents]&lt;br /&gt;
* [http://www.tldp.org/LDP/nag/nag.html The Network Administrators' Guide by Olaf Kirch]&lt;br /&gt;
* [http://unfs3.sourceforge.net/ unfs3 homepage]&lt;br /&gt;
* [http://packages.qa.debian.org/n/nfs-user-server.html Overview of nfs-user-server  source package]&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Networking]]&lt;/div&gt;</summary>
		<author><name>Chernomor</name></author>
		
	</entry>
</feed>