Posts Tagged ‘NFS’

Set NetApp NFS Export Permissions for vSphere NFS Mounts

October 3, 2011 Leave a comment

One of the things missing from the NetApp VSC is the ability to set permissions on NFS exports when you add a host to an existing cluster.  If you have a lot of NFS datastores and don’t feel like setting permissions across NetApp arrays when you add a new host this should ease the pain.  Here are a few other use cases.

  1. You change a VMkernel IP for NFS traffic on a host
  2. You add a VMkernel IP for NFS traffic on a host
  3. You add a new host to a cluster
  4. You remove a host from a cluster
You’ll see removing host is a reason to run this script.  This is an important thing to note.  Running this script will replace existing NFS export permissions with those associated to the vCenter you run it against.  If you have any additional IP addresses assigned to the export they will get blown away by this script!  I also thought it would be cool to turn this into a form so I used PrimalForms to design a very simple front-end you can see below.
The DataONTAP PowerShell Toolkit 1.2 has support for networking, but we don’t have any systems running 7.3.3 or greater so I wasn’t able to make use of those cmdlets in this script.  Because of that I hard code the NetApp VIFs.  Additionally the way I parse the data is related to the length of the VIF used, and I have no support for VIFs of different lengths.  The VMkernel ports for NFS are found using a wildcard search for “NFS” in the port group name.
Don’t be intimidated by all this code, 99% of it was generated by PrimalForms in order to build the GUI.  Modify the 5 variables up front to add your NetApp VIFs and controller names.  You can make a simple batch file to call the script and run it with just a desktop icon to get a nice easy way to modify your NFS permissions on vSphere.  Thanks to @jasemccarty and @glnsize for help with finding the NFS mount in vSphere!


$array1VIF = "", "", "", ""
$array2VIF = "", "", "", ""

$array1Name = "netapp1"
$array2Name = "netapp2"

$vCenters = "server1", "server2"

$vifLength = $array1VIF[0].Length
$volStart = $vifLength + 9

#Generated Form Function
function GenerateForm {
# Code Generated By: SAPIEN Technologies PrimalForms
#(Community Edition) v1.0.8.0
# Generated On: 10/24/2010 9:34 PM
# Generated By:

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null

#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$cancelButton = New-Object System.Windows.Forms.Button
$okButton = New-Object System.Windows.Forms.Button
$groupBox1 = New-Object System.Windows.Forms.GroupBox
$vcenter = New-Object System.Windows.Forms.ComboBox
$groupBox2 = New-Object System.Windows.Forms.GroupBox
$nfsDatastores = New-Object System.Windows.Forms.ListBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#Generated Event Script Blocks
#Provide Custom Code for events specified in PrimalForms.

Connect-VIServer $vcenter.SelectedItem

$nfsDS = get-datastore | where {$_.Type -eq "NFS"} | get-view | select Name,@{n="url";e={$_.summary.url}}
$nfsDS | % {$nfsDatastores.Items.Add($_.URL.substring($volStart)) | Out-Null }



$nfsDS | % {$nfsDatastores.Items.Remove($_.url.substring($volStart)) | Out-Null }
$nfsDatastores.Items.Remove("Select a Virtual Center to gather NFS mounts.")|Out-Null



$esxNFSIP = Get-VMHostNetworkAdapter -VMKernel | where {$_.PortGroupName -like "*NFS*"} | select IP -Unique
$esxNFSIP = $esxNFSIP | % {$_.IP}

Foreach ($ds in $nfsDS) {

 $nfsVIF = $ds.url.substring(8,$vifLength)
 $nfsMount = $ds.url.substring($volStart)
 $nfsName = $

 #//// Set permissions on source NFS exports

 $array1VIF | % { If ($_ -eq $nfsVIF) { $storageArray = $array1Name } }
 $array2VIF | % { If ($_ -eq $nfsVIF) { $storageArray = $array2Name } }

 Connect-NaController $storageArray

 Set-NaNfsExport $nfsMount -Persistent -ReadWrite $esxNFSIP -Root $esxNFSIP






{#Correct the initial state of the form to prevent the .Net maximized form issue
 $form1.WindowState = $InitialFormWindowState

#region Generated Form Code
$form1.Text = "Set VMware NFS Permissions"
$form1.Name = "form1"
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 344
$System_Drawing_Size.Height = 379
$form1.ClientSize = $System_Drawing_Size

$cancelButton.TabIndex = 5
$cancelButton.Name = "cancelButton"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 103
$System_Drawing_Size.Height = 23
$cancelButton.Size = $System_Drawing_Size
$cancelButton.UseVisualStyleBackColor = $True

$cancelButton.Text = "Cancel"

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 204
$System_Drawing_Point.Y = 328
$cancelButton.Location = $System_Drawing_Point
$cancelButton.DataBindings.DefaultDataSourceUpdateMode = 0


$okButton.TabIndex = 4
$okButton.Name = "okButton"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 103
$System_Drawing_Size.Height = 23
$okButton.Size = $System_Drawing_Size
$okButton.UseVisualStyleBackColor = $True

$okButton.Text = "Set Permissions"

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 45
$System_Drawing_Point.Y = 328
$okButton.Location = $System_Drawing_Point
$okButton.DataBindings.DefaultDataSourceUpdateMode = 0


$groupBox1.Name = "groupBox1"

$groupBox1.Text = "Virtual Center"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 265
$System_Drawing_Size.Height = 94
$groupBox1.Size = $System_Drawing_Size
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 42
$System_Drawing_Point.Y = 26
$groupBox1.Location = $System_Drawing_Point
$groupBox1.TabStop = $False
$groupBox1.TabIndex = 2
$groupBox1.DataBindings.DefaultDataSourceUpdateMode = 0

$vcenter.FormattingEnabled = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 226
$System_Drawing_Size.Height = 21
$vcenter.Size = $System_Drawing_Size
$vcenter.DataBindings.DefaultDataSourceUpdateMode = 0
$vcenter.Name = "vcenter"
$vCenters | % {$vcenter.Items.Add($_) | out-null}
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 19
$System_Drawing_Point.Y = 35
$vcenter.Location = $System_Drawing_Point
$vcenter.TabIndex = 0


$groupBox2.Name = "groupBox2"

$groupBox2.Text = "NFS Mounts"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 262
$System_Drawing_Size.Height = 167
$groupBox2.Size = $System_Drawing_Size
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 45
$System_Drawing_Point.Y = 141
$groupBox2.Location = $System_Drawing_Point
$groupBox2.TabStop = $False
$groupBox2.TabIndex = 3
$groupBox2.DataBindings.DefaultDataSourceUpdateMode = 0

$nfsDatastores.FormattingEnabled = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 226
$System_Drawing_Size.Height = 134
$nfsDatastores.Size = $System_Drawing_Size
$nfsDatastores.DataBindings.DefaultDataSourceUpdateMode = 0
$nfsDatastores.Items.Add("Select a Virtual Center to gather NFS mounts.")|Out-Null
$nfsDatastores.HorizontalScrollbar = $True
$nfsDatastores.Name = "nfsDatastores"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 16
$System_Drawing_Point.Y = 24
$nfsDatastores.Location = $System_Drawing_Point
$nfsDatastores.TabIndex = 0


#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
#Show the Form
$form1.ShowDialog()| Out-Null

} #End Function

#Call the Function
Categories: netapp, VMware Tags: , ,

NFS – Cannot see snapshots under .snapshot directory for NetApp

May 6, 2011 Leave a comment
When using NFS the snapshots under the .snapshot directory cannot be seen.

Running snap list on the filer will show the snapshots for the volume.  However, when you cd to the .snapshot directory and run lsl from an NFS client, none of the snapshots are listed.


This is because the option nfs.hide_snapshot was set to ON.  If this option is turned on, the .snapshot directory itself is visible, but the actual snapshots are hidden.  Although, the snapshots are hidden a user who has permissions can still access the snapshots.


Set the nfs.hide_snapshot option to OFF.

options nfs.hide_snapshot off

You will then need to unmount and then remount the export.

Categories: netapp Tags: , ,

Tips and tricks for unmounting an Network File System (NFS) mount on a UNIX or Linux client?

May 3, 2011 Leave a comment

If your UNIX or Linux clients cannot unmount an NFS mount from a filer……

One of the following errors occur:

nfs umount:variable: is busy
umount: warning: /variable not in mnttab
unmounting NFS filesystems: Cannot MOUNTPROG RPC: RPC: Program not registered
umount: Permission denied
umount: Device busy

Level 1 Options:

    • /etc/init.d/nscd stop

NSCD caches name service lookups. If the NFS mount in question is mounted via name this can help. The specific command will stop the nscd daemon. Just like the nfsd daemon, once it is stopped, you will want to restart it using nscd start when ready to resume normal operations.

    • /etc/init.d/autofs stop

Autofs invokes the automounter which is used with applications like NIS. This script (with the stop option) will stop the automounter. As always you would want to restart the automounter using autofs start when ready to resume normal operations.

Level 2 Options:

    • umount /share or umount -f /share

This command unmounts the specified file system. The use of the -f flag attempts to forcibly unmount the file system.

Make sure you are not in the directory when trying to unmount it.

    • fuser -mk /share

This command will displays the PIDs of processes using the specified NFS mount. The -mk flags kills all processes accessing the file system /share in any way.

This functionality is not available under SunOS. SunOS supports fuser -ck /mount_point which should kill all processes accessing the files under /mount_point.

Some times, even though fuser does not report any processes, the file system still cannot be unmounted. One way to find out if there are still open files under /mount_point is to use lsof command.

If lsof is installed, use lsof /mount_point to find out which processes have open files under /mount_point, then kill these processes.

Level 3 Options:

    • /etc/init.d/nfs.client stop — Solaris 5.X, most UNIX and Linux variants.

This command runs the start and stop script that controls the nfsd daemon. The nfs.client script has at least two options, stop and start. Once you have stopped the daemon, you will want to restart it using nfs.client start when ready to resume normal operations.

    • svcadm restart nfs/client — Solaris 10 specific.

In Solaris 10 the init.d scripts have been replaced with a more robust Service Management Facility (SMF). This command performs the same function as starting and stopping the init.d/nfs.client daemon.

Level 4 Options:

When none of the previous options have succeeded, it may be necessary to perform some globally intrusive actions on the client. The command options below will do significantly more than terminate a specific NFS mount point.

    • umountall -k -h

This command will attempt to unmount all mounted file systems except the basic root file system. The use of -k -h will send the SIGKILL signal through the file system to all remote mounted file systems as seen in the/etc/mnttab.

    • killall -HUP rpc.mountd

This command will kill the mountd daemon services which are responsible for mounting and unmounting filesystems.

    • /usr/sbin/shutdown -g0 -y -i6

Rebooting; the last resort of the desperate. For most UNIX and Linux problems this is NOT required

Categories: netapp Tags: , , , ,