Using Nano Server in Azure

As you may have already realized, I am pretty excited about Nano Server and what it means for the future of Microsoft.  Along with the launch of Server 2016 Technical Preview 4 is a new version of Nano Server with a ton of new features and improvements.  If you don't want to roll your own, no worries Microsoft now offers a Nano VM in Azure to play around with.  One problem.  Nano server doesn't use RDP, so how do you get connected?  And how do you add packages once you are logged in?

To spin up your Nano Server VM, log into the Azure portal and search for Nano in the Marketplace.  The first hit should be "Windows Server 2016 Nano Technical Preview 4".  Go ahead and deploy it as you would any VM.  Once the deployment is complete, it will have a public IP address.  Before you can do anything, you will need to open up the WinRM ports to the server.  Remember that Nano doesn't use RDP, and has no GUI, so the only way to manage it is with WinRM.  I used the Resource Manager mode to deploy the VM, so in order to open the ports I had to go to the Resource Group and access the Network Security Group for the VM.  I added two inbound rules:
Now I should be able to connect to my Nano Server remotely.  In an Administrative PowerShell store the public IP address in a variable, add that IP address to the Trusted Hosts list, and then create a session to the server.
$ip = <NanoServerPublicIPAddress>
Set-Item wsman:\localhost\Client\TrustedHosts -Value $ip
$s = New-PSSession -ComputerName $ip -Credential $ip\Administrator
Enter-PSSession $s

Now you should be connected to your Nano Server.  By default Microsoft has only included the basic Nano Server packages for Azure, Guest Drivers, CoreSystem, and Windows Foundation.  What if you wanted to install the IIS package?  Exploring the file system, I discovered that Microsoft has placed all the packages in the C:\Packages directory.  Included are IIS, DNS, Computer, and more!  Basically all the packages included in the Server 2016 TP4 ISO.  In order to install a package to an online Nano server, you will need to use an unattend file.  In this example I am going to install IIS, per the documentation here.

First is to create the unattend.xml file on the remote server.  There's probably a way to copy the file over, but instead of doing that, I just used the Add-Content cmdlet to create the file.

Add-Content -Path .\unattendIIS.xml -Value '<?xml version="1.0" encoding="utf-8"?>'
Add-Content -Path .\unattendIIS.xml -Value '<unattend xmlns="urn:schemas-microsoft-com:unattend">'
Add-Content -Path .\unattendIIS.xml -Value '    <servicing>'
Add-Content -Path .\unattendIIS.xml -Value '        <package action="install">'
Add-Content -Path .\unattendIIS.xml -Value '            <assemblyIdentity name="Microsoft-NanoServer-IIS-Package" version="10.0.10586.0" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" />'
Add-Content -Path .\unattendIIS.xml -Value '            <source location="c:\packages\Microsoft-NanoServer-IIS-Package.cab" />'
Add-Content -Path .\unattendIIS.xml -Value '        </package>'
Add-Content -Path .\unattendIIS.xml -Value '        <package action="install">'
Add-Content -Path .\unattendIIS.xml -Value '            <assemblyIdentity name="Microsoft-NanoServer-IIS-Package" version="10.0.10586.0" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="en-US" />'
Add-Content -Path .\unattendIIS.xml -Value '            <source location="c:\packages\en-us\Microsoft-NanoServer-IIS-Package.cab" />'
Add-Content -Path .\unattendIIS.xml -Value '        </package>'
Add-Content -Path .\unattendIIS.xml -Value '    </servicing>'
Add-Content -Path .\unattendIIS.xml -Value '    <cpi:offlineImage cpi:source="" xmlns:cpi="urn:schemas-microsoft-com:cpi" />'
Add-Content -Path .\unattendIIS.xml -Value '</unattend>'
Once the file is populated, you can simply run the following:
dism /online /apply-unattend:.\unattend.xml
The process may require a restart of Nano Server, at least it did in my case.  Once the server was back up, which doesn't take very long, I created a new index.html file:
Add-Content -Path C:\inetpub\wwwroot\index.html -Value "<HTML><BODY><H1>Hello World</H1></BODY></HTML>"
Now if I go to the public IP address of my Nano Server, I should see the webpage.  And I do!  That gives us a basis for working through other scenarios like configuring the Nano Server as a container host.  In fact... that will be my next post.

Labels: , , ,