Difference between revisions of "NFS"

From OpenVZ Virtuozzo Containers Wiki
Jump to: navigation, search
(NFS server)
(Prepare the HN)
 
(15 intermediate revisions by 9 users not shown)
Line 1: Line 1:
This page describes how to mount NFS partition inside a container.
+
This page describes how to use '''NFS client''' inside a container.
  
== NFS server ==
+
{{Note|see [[NFS server inside container]] for info about nfsd.
Currently OpenVZ kernel doesn't include kernel NFS server support. However you are still able to use user space [[NFS server inside container]].
 
If your OpenVZ-patched kernel has NFS kernel support compiled in (this is the case with Debian's 2.6.26 kernel, for example), you can export filesystems on the HN by usual means, just keep in mind that exporting a container's `root` will most probably not work (it can hang at mount attempt and produce symptoms as described below) - export `private` instead.
 
  
== NFS client ==
+
Mounting filesystems from the '''hardware node''' can be performed more elegantly using [[Bind mounts]].}}
=== Preparations ===
+
 
==== Prerequisites ====
+
== Preparations ==
 +
=== Prerequisites ===
 
You will need the following software:
 
You will need the following software:
  
Line 21: Line 20:
 
This can be done by adding the above lines into /etc/sysctl.conf on the hardware node, and then running <code>sysctl -p</code>.
 
This can be done by adding the above lines into /etc/sysctl.conf on the hardware node, and then running <code>sysctl -p</code>.
  
===== Debian Notes =====
+
=== Prepare the HN ===
  
Debian Etch still uses vzctl version 3.0.11 and so NFS client support is not yet available. Lenny presently has version 3.0.18.
+
For NFS mounts to work in the containers with the RHEL5-based kernels you must enable kernel threads in the container by setting <code>kernel.ve_allow_kthreads=1</code> in <code>/etc/sysctl.conf</code>.
  
==== Prepare the HN ====
+
RHEL7-based kernels support [https://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-nfs.html three different NFS protocol versions]:
 +
{{Quote|
 +
NFS version 2 (NFSv2) is older and is widely supported.
 +
NFS version 3 (NFSv3) has more features, including 64bit file handles, Safe Async writes and more robust error handling.
 +
NFS version 4 (NFSv4) works through firewalls and on the Internet, no longer requires portmapper, supports ACLs, and utilizes stateful operations.
 +
Red Hat Enterprise Linux supports NFSv2, NFSv3, and NFSv4 clients, and when mounting a file system via NFS, Red Hat Enterprise Linux uses NFSv3 by default, if the server supports it.
 +
}}
  
For NFS mounts to work in the containers with the RHEL5-based kernels you must enable kernel threads in the container by setting <code>kernel.ve_allow_kthreads=1</code> in <code>/etc/sysctl.conf</code>.
+
Accordingly, there are three kernel modules: <code>nfs</code> (for NFSv2), <code>nfsv3</code>, and <code>nfsv4</code>. As [[NFS server inside container]] currently only supports NFSv3, it's very likely that you'll need to load <code>nfsv3</code> module for clients.
  
 
  # modprobe nfs
 
  # modprobe nfs
Line 35: Line 40:
 
   modprobe nfs
 
   modprobe nfs
  
==== Prepare the container ====
+
Alternatively, you can add a new line with <code>nfs</code> to your /etc/modules or /etc/modules.conf file.
 +
 
 +
=== Prepare the container ===
 
To allow a container to use NFS filesystem, you will need to start it with "nfs" feature enabled. If the container is running while you set the <code>--features nfs:on</code>, you will need to reboot it.
 
To allow a container to use NFS filesystem, you will need to start it with "nfs" feature enabled. If the container is running while you set the <code>--features nfs:on</code>, you will need to reboot it.
  
Line 54: Line 61:
 
</pre>
 
</pre>
  
=== Mounting NFS ===
+
== Mounting NFS ==
Make sure that packages <code>nfs-utils</code> and <code>nfs-utils-lib</code> or similar are installed in a container.
+
Make sure that packages <code>nfs-utils</code> and <code>nfs-utils-lib</code> or similar are installed in a container.  Also make sure that the <code>portmap</code> (or <code>rpcbind</code>) service is started, otherwise the mount with default options will fail and require the <code>-nolock</code> option.  See the [[NFS#Known issues|known issues]] for more information.
  
 
Assuming that you already have NFS server set up at <code>192.168.0.1:/nfs_pub</code>, mounting will be simple
 
Assuming that you already have NFS server set up at <code>192.168.0.1:/nfs_pub</code>, mounting will be simple
Line 72: Line 79:
 
For more details on how to setup NFS mount, see [http://nfs.sourceforge.net/nfs-howto/ar01s04.html NFS-client HOWTO]
 
For more details on how to setup NFS mount, see [http://nfs.sourceforge.net/nfs-howto/ar01s04.html NFS-client HOWTO]
  
=== Known issues ===
+
== Known issues ==
* There are quite a few parameters in NFS, so sometimes it doesn't work due to misconfiguration. We've created a separate
+
* There are quite a few parameters in NFS, so sometimes it doesn't work due to misconfiguration. We've created a separate page describing such situations: [[NFS doesn't work]].
page describing such situations: [[NFS doesn't work]].
+
* Package nfs-common can not be installed. Make sure you start <code>portmap</code> before trying to install nfs-common.
* Suspend and migrate operations fail if the VE has NFS partitions mounted [http://bugzilla.openvz.org/show_bug.cgi?id=616]
+
** For Ubuntu/Debian OpenVZ containers, the <code>portmap/rpcbind</code> service may not start automatically. However, you can enable it by editing the <code>/etc/default/nfs-common</code> configuration file.
 
 
== ISSUE: can't install nfs-common on ubuntu VE ==
 
 
 
Host machine is ubuntu server 8.0.4 , VE container is ubuntu from openvz template repo.
 
 
 
Despite following all of the above directives, I am unable to get nfs-common to install on the VE (installs fine on the host machine).
 
 
 
Here is output ''(from inside VE)'' when I try to install nfs-common
 
 
 
<pre>
 
root@clinton:/# apt-get install nfs-common
 
Reading package lists... Done
 
Building dependency tree     
 
Reading state information... Done
 
nfs-common is already the newest version.
 
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
 
1 not fully installed or removed.
 
After this operation, 0B of additional disk space will be used.
 
Setting up nfs-common (1:1.1.2-2ubuntu2.2) ...
 
* Starting NFS common utilities                                                                                                                        [fail]
 
invoke-rc.d: initscript nfs-common, action "start" failed.
 
dpkg: error processing nfs-common (--configure):
 
subprocess post-installation script returned error exit status 1
 
Errors were encountered while processing:
 
nfs-common
 
E: Sub-process /usr/bin/dpkg returned an error code (1)
 
</pre>
 
 
 
The cause of this problem is that portmap is not running. Portmat must be running before installing nfs-common.
 
 
 
Just run portmap:
 
 
 
# /etc/init.d/portmap start
 
 
 
Then, install nfs-common:
 
 
 
# apt-get install nfs-common
 
  
 
== See also ==
 
== See also ==
 
* [http://nfs.sourceforge.net/nfs-howto/ar01s04.html NFS-client HOWTO]
 
* [http://nfs.sourceforge.net/nfs-howto/ar01s04.html NFS-client HOWTO]
 +
 
[[Category: HOWTO]]
 
[[Category: HOWTO]]

Latest revision as of 19:34, 17 June 2016

This page describes how to use NFS client inside a container.

Yellowpin.svg Note: see NFS server inside container for info about nfsd.

Mounting filesystems from the hardware node can be performed more elegantly using Bind mounts.

Preparations[edit]

Prerequisites[edit]

You will need the following software:

  1. vzctl version 3.0.13 or higher (do vzctl --version)
  2. kernel version 2.6.18-028test006 or higher (2.6.18-028stab* will do), or any recent RHEL5-based or 2.6.20-based kernel.

Note: In all the kernels earlier than 028stab038, kernel NFS support can be given to a container by setting:

     sunrpc.ve_allow_rpc = 1
     fs.nfs.ve_allow_nfs = 1
     kernel.ve_allow_kthreads = 1

This can be done by adding the above lines into /etc/sysctl.conf on the hardware node, and then running sysctl -p.

Prepare the HN[edit]

For NFS mounts to work in the containers with the RHEL5-based kernels you must enable kernel threads in the container by setting kernel.ve_allow_kthreads=1 in /etc/sysctl.conf.

RHEL7-based kernels support three different NFS protocol versions:

NFS version 2 (NFSv2) is older and is widely supported. NFS version 3 (NFSv3) has more features, including 64bit file handles, Safe Async writes and more robust error handling. NFS version 4 (NFSv4) works through firewalls and on the Internet, no longer requires portmapper, supports ACLs, and utilizes stateful operations. Red Hat Enterprise Linux supports NFSv2, NFSv3, and NFSv4 clients, and when mounting a file system via NFS, Red Hat Enterprise Linux uses NFSv3 by default, if the server supports it.

Accordingly, there are three kernel modules: nfs (for NFSv2), nfsv3, and nfsv4. As NFS server inside container currently only supports NFSv3, it's very likely that you'll need to load nfsv3 module for clients.

# modprobe nfs

You will probably want the nfs module to load automatically on reboots. One way to do this is to put the modprobe command in your /etc/rc.d/rc.local file:

 modprobe nfs

Alternatively, you can add a new line with nfs to your /etc/modules or /etc/modules.conf file.

Prepare the container[edit]

To allow a container to use NFS filesystem, you will need to start it with "nfs" feature enabled. If the container is running while you set the --features nfs:on, you will need to reboot it.

# vzctl set 101 --features "nfs:on" --save
# vzctl start 101

After this you may see nfs in /proc/filesystems

# vzctl exec 101 cat /proc/filesystems
        ext3
        ext2
nodev   rpc_pipefs
nodev   proc
nodev   nfs
nodev   sysfs
nodev   tmpfs
nodev   devpts

Mounting NFS[edit]

Make sure that packages nfs-utils and nfs-utils-lib or similar are installed in a container. Also make sure that the portmap (or rpcbind) service is started, otherwise the mount with default options will fail and require the -nolock option. See the known issues for more information.

Assuming that you already have NFS server set up at 192.168.0.1:/nfs_pub, mounting will be simple

# vzctl enter 100
# mkdir /nfs
# mount -t nfs 192.168.0.1:/nfs_pub /nfs
# cat /proc/mounts 
simfs / simfs rw 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
devpts /dev/pts devpts rw 0 0
nfs /nfs nfs rw,vers=3,rsize=32768,wsize=32768,hard,proto=tcp,timeo=600,retrans=2,sec=sys,addr=192.168.0.1 0 0

For more details on how to setup NFS mount, see NFS-client HOWTO

Known issues[edit]

  • There are quite a few parameters in NFS, so sometimes it doesn't work due to misconfiguration. We've created a separate page describing such situations: NFS doesn't work.
  • Package nfs-common can not be installed. Make sure you start portmap before trying to install nfs-common.
    • For Ubuntu/Debian OpenVZ containers, the portmap/rpcbind service may not start automatically. However, you can enable it by editing the /etc/default/nfs-common configuration file.

See also[edit]