NFS

Powershell script to setup NFS share on Server 2012 R2


The following script sets up NFS share on Server 2012 R2:

NFS1

# Script to setup NFS share on Server 2012 R2
# Sam Boutros – 7/7/2014
# References: http://technet.microsoft.com/en-us/library/jj603081.aspx,
# http://technet.microsoft.com/en-us/library/jj574143.aspx#BKMK_deploy
#
$NFSFolder = “d:\shares\NFS1” # Tye in the path to the folder to be shared via NFS
$NFSShare = “nfs1” # Type in the share name you wish to use
# End Data entry section
#
Import-Module ServerManager
Add-WindowsFeature FS-NFS-Service
Import-Module NFS
if (!(Test-Path $NFSFolder)) {New-Item -ItemType directory -Path $NFSFolder}
New-NfsShare -name $NFSShare -Path $NFSFolder
$ShareName = $env:COMPUTERNAME + “:/” + $NFSShare
Write-Output “NFS share has been created: $ShareName”

You can see the new share in Server Manager under File and Storage Services:

NFS7

The default NFS share properties are:

NFS2

NFS3

Under Share Permissions, I clicked Add, entered the IP address (or name) of the Linux host that needs to connect to this 2012 R2 NFS share, and selected the desired access (read/write):

NFS4

No changes to NTFS permissions:

NFS5

Finally, I enabled the following firewall rule to allow me to ping this server:NFS8

Next, I setup a Red Hat 6.5 VM to test with.  I picked v6.5 because

  1. It comes with the Hyper-V integration built in – no need for manual RTM installation,
  2. The Hyper-V integration server for 6.5 kernel allows for Host-based VSS backup – no need for guest agent inside the Linux machine. We get crash consistent backup (not application consistent backup), but that’s a big improvement from Hyper-V integration service for kernel version 6.4 and older,
  3. The Hyper-V integration service supports dynamic RAM. Again, with kernel versions 6.4 and older, we can only use static RAM with Linux guests

I downloaded the media ISO Boot and DVD files from Red Hat,

created VM with 2 DVDs so that I can mount both media during setup, followed the simple installation steps, rebooted

Next, I used the console (and later on Putty to SSH) to the new Red Hat machine, logged in as root,

NFS9

I ran the following commands:

ifconfig -a => show interfaces
ifconfig eth0 10.5.19.36 netmask 255.255.255.0 => to setup IP address and mask
ping 10.5.19.38 => confirm connection to NFS server (enabled ping rule in Windows firewall)
mount -t ext4 => to show partitions formatted with ext4 file system
mkdir /pub => to create local mount point directory /pub
mount 10.5.19.38:/nfs1 /pub (must have added 10.5.19.36/RW permission on NFS share on Server 2012)
cd /pub => to change directory to /pub
ls => to see files on remote NFS share
echo hello >test1.txt => to test creating a text file named test1

You might want to edit /etc/fstab and modify the following line to match your configuration. For example:

10.5.19.38:/nfs1 /pub nfs defaults 0 0

The files were visible also on the 2012 R2 server.

 

Advertisements