Enabling NFS-Client on Windows at Instance Launch Time

Oracle Cloud

Cloud Providers / Oracle Cloud 1877 Views 0

One benefit of cloud offerings comes from the ability to spin up new resources on-demand, with minimal effort. Automation tools play a pivotal role in harnessing the power of cloud infrastructure. As announced in July 2018, Oracle Cloud Infrastructure Windows instances can also be configured using cloudbase-init through user data provided at launch time. Check out the& Windows Custom Startup Scripts and Cloud-Init on Oracle Cloud Infrastructure post by Andy Corran that also covers Windows Remote Management (WinRM).

Here, we have another example of how you can use a PowerShell script to configure a new instance at launch time.

In January 2018, Oracle Cloud Infrastructure announced the launch of the File Storage service. You can use File Storage to share unstructured files between Windows and Linux-based hosts. The Oracle Cloud Infrastructure File Storage service is an NFSv3 file storage service that can scale to exabytes in size.& I use File Storage as the provider of shared files accessed via NFS in the following example. If you would like to know more about our File Storage service, check out the Introducing Oracle Cloud Infrastructure File Storage Service blog post by my colleague Ed Beauvais or the official documentation. The commands required to enable the Windows NFS-Client come from the official documentation. Since Windows registry keys need to be created, including the required PowerShell commands as user data is a great option.

In this example, I am going to be using the Oracle Cloud Infrastructure CLI to create my Windows Server 2016 Standard Edition instance and include PowerShell commands from my local machine. Read about setting up the CLI in the official documentation.

Prepare the input files
  1. Create the PowerShell script. Be sure to include the #ps1_sysnative header so that cloudbase-init interprets the commands correctly. In my example, I named the file enable_nfs.ps1.

    #ps1_sysnative & ## Timestamp function for logging. function Get-TimeStamp { & & & & return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date) & } & ## Create a log file. $path = $env:SystemRoot + "\Temp\" $logFile = $path + "CloudInit_$(get-date -f yyyy-MM-dd).log" New-Item $logFile -ItemType file Write-Output "$(Get-TimeStamp) Logfile created..." | Out-File -FilePath $logFile -Append & ## Install NFS-Client. Install-WindowsFeature -Name NFS-Client Write-Output "$(Get-TimeStamp) Installed NFS-Client." | Out-File -FilePath $logFile -Append & ## Configure NFS user mapping registry values. New-ItemProperty -Path "HKLM:\Software\Microsoft\ClientForNFS\CurrentVersion\Default" -Name "AnonymousGid" -Value 0 -PropertyType DWord New-ItemProperty -Path "HKLM:\Software\Microsoft\ClientForNFS\CurrentVersion\Default" -Name "AnonymousUid" -Value 0 -PropertyType DWord Write-Output "$(Get-TimeStamp) Created registry keys for NFS root user mapping." | Out-File -FilePath $logFile -Append & ## Restart NFS-Client. nfsadmin client stop nfsadmin client start Write-Output "$(Get-TimeStamp) Restarted NFS Cleint." | Out-File -FilePath $logFile -Append
  2. Create the instance JSON file. In my example, I named the file c01-win2016std.json. My JSON file only contains the required values. The values for ad, compartmentId, and subnetId are unique to an individual tenancy.

    { & "ad": "<AVAILABILITY_DOMAIN>", & "compartmentId": "<COMPARTMENT_OCID>", & "subnetId": "<SUBNET_OCID>", & "bootVolumeSizeInGbs": 256, & "displayName": "c01-win01", & "hostnameLabel": "c01-win01", & "imageId": "ocid1.image.oc1.phx.aaaaaaaaq3o6o4lwhrna3dlomvo6rgkyqzzcvtkuw7j3u4pf42ucpfmyzfia", & "shape": "VM.Standard2.1", & "skipSourceDestCheck": true }
Launch the instance
  1. Use Oracle Cloud Infrastructure CLI to launch the instance using the two files created previously as input. Note the OCID of the new instance in the return JSON object. The next two steps require the OCID of the new instance.

    $ oci compute instance launch --from-json file://c01-win2016std.json --user-data-file enable_nfs.ps1
  2. Use the CLI to find the IP address assigned to the primary VNIC.

    $ oci compute instance list-vnics --query "data [0].{IP:\"private-ip\"} --instance-id <OCID_FROM_PREVIOUS_JSON_RESPONSE>
  3. Use the CLI to find the initial password for the opc user.

    $ oci compute instance get-windows-initial-creds --query "data.{Password:password}" --instance-id <OCID_FROM_PREVIOUS_JSON_RESPONSE>
Verify the Windows NFS-Client
  1. In my tenancy, I tunnel Windows RDP sessions through SSH to a Linux bastion hosts. The white paper on Protected Access for Virtual Cloud Networks& describes this process in detail.&

    $ ssh -L 33389<IP_ADDRESS_OF_NEW_INSTANCE>:3389 opc@<IP_ADDRESS_OF_BASTION>
  2. After logging in to the new Windows instance and changing the initial opc user password, mount the NFS share as you would map any network drive in Windows.

  3. Success!

This blog post gives you another example of how cloudbase-init userdata can be used to configure a Windows host at launch time. If you do not have an Oracle Cloud Infrastructure account, you can sign up for a free trial and evaluate the File Storage service for yourself. The Oracle Cloud Infrastructure Solution Architect team is working on a few other Windows-related publications. Keep an eye out for more blog posts and white papers from the team.

Comments