{{announcement.body}}
{{announcement.title}}

Running Linux on Windows

DZone 's Guide to

Running Linux on Windows

We brought Nanos unikernels to Microsoft Azure, so you can run Linux applications faster and safer. Plus, you can run them on your Windows desktop and Hyper-V!

· Open Source Zone ·
Free Resource

If Steve Ballmer were dead he'd be rolling in his grave right now. That's right - we brought Nanos unikernels to Microsoft Azure which means that you can now run Linux applications faster and safer than Linux itself on Azure of all things! Oh yeh - side benefit is that you can now run Linux applications on your Windows desktop as well through Hyper-V.

Ready to run your first application? Great!

Azure is not so straight-forward as other cloud platforms to deploy to mainly because there are so many other environment variables that need to be set and the deploys can take a lot longer than something like Google Cloud, but once you get going it's super fast. In my tests (from Oakland) my latency is insanely good in comparison to other providers. I might disagree with some of the complexity of the Azure environment but the documentation has maintained its reputation from when I was in school (so many decades ago). Azure also has little niceties like being able to pop ports without taking down an instance.

If you're new to unikernels and using OPS you might want to check out an earlier tutorial first.

Getting Started

If you don't have the az cli tools they are worth downloading first - for this example you kinda need to. You'll want to create a new resource group and storage account, which we'll use as a cloud bucket. Inside the storage account, don't forget to set up a container to store your vhdx blobs in.

Next, let's create a quickstart authorization account:

Shell
 




x


 
1
az ad sp create-for-rbac --sdk-auth > quickstart.auth



This dumps a ton of authentication env vars into a JSON payload. We'll be using these for almost all of our operations so in the examples below just cut/paste them.

Create an Image

Now we'll create an image. Out of all the clouds, Google Cloud might be the quickest to deploy to while Azure is the longest. However, as you'll soon see Azure is fairly fast one your instance is booted.

Shell
 




x


 
1
#!/bin/sh
2
 
          
3
export AZURE_STORAGE_ACCOUNT="nanostest"
4
export AZURE_STORAGE_ACCESS_KEY=""
5
 
          
6
export AZURE_SUBSCRIPTION_ID=""
7
export AZURE_LOCATION_DEFAULT=""
8
export AZURE_TENANT_ID=""
9
export AZURE_CLIENT_ID=""
10
export AZURE_CLIENT_SECRET=""
11
 
          
12
export AZURE_BASE_GROUP_NAME="bob"
13
 
          
14
GOOS=linux go build -o gtest2
15
 
          
16
ops image create -c config.json -t azure -a gtest2



What this command does is take the disk image you created, convert it to a vhdx, which should be sized correctly, and has a minimum of ~20mb, then uploads it to your cloud storage container.

Deploying an Image

Next, let's deploy the image you just created. As of right now this command never really finishes as Azure is expecting to install a user account with a password or ssh key but unikernels don't have user accounts nor do they have ssh and passwords just don't exist. The reason is that it's just running one application. If anyone from Microsoft/Azure is reading - we're hoping this might be tweaked in the future. Azure isn't the only platform that expects this, Alibaba Cloud has the same expectation, but neither AWS nor Google Cloud seems to care. It's a minor annoyance but not insurmountable as you'll see:

Shell
 




x


 
1
#!/bin/sh
2
 
          
3
export AZURE_STORAGE_ACCOUNT=""
4
 
          
5
export AZURE_SUBSCRIPTION_ID=""
6
export AZURE_LOCATION_DEFAULT="westus2"
7
export AZURE_TENANT_ID=""
8
export AZURE_CLIENT_ID=""
9
export AZURE_CLIENT_SECRET=""
10
 
          
11
export AZURE_BASE_GROUP_NAME="bob"
12
 
          
13
ops instance create -z westus2 -t azure -i mytest-image



After a few minutes you'll see your instance will appear by running the instances list command:

Shell
 




x


1
#!/bin/sh
2
 
          
3
export AZURE_SUBSCRIPTION_ID=""
4
export AZURE_LOCATION_DEFAULT="westus2"
5
export AZURE_TENANT_ID=""
6
export AZURE_CLIENT_ID=""
7
export AZURE_CLIENT_SECRET=""
8
 
          
9
export AZURE_BASE_GROUP_NAME="bob"
10
 
          
11
ops instance list -t azure -z us-west-2



Yanking Logs

Just like in ESX we attach a serial adapter to the instance and the logs are automatically routed to text files for you. This is actually a fairly nice feature of Azure as they give you the textual logs and also take graphical snapshots for you. I was pleasantly surprised to see this just work out of the box:

Shell
 




xxxxxxxxxx
1
12


 
1
#!/bin/sh
2
 
          
3
export AZURE_STORAGE_ACCOUNT=""
4
export AZURE_STORAGE_ACCESS_KEY=""
5
 
          
6
export AZURE_SUBSCRIPTION_ID=""
7
export AZURE_LOCATION_DEFAULT=""
8
export AZURE_TENANT_ID=""
9
export AZURE_CLIENT_ID=""
10
export AZURE_CLIENT_SECRET=""
11
 
          
12
export AZURE_BASE_GROUP_NAME=""
13
 
          
14
ops instance logs -t azure gtest2-image -z us-west-2



For production applications, you'll obviously want to route these logs to Splunk or elastic search or whatever log solution you are using.

After you are done playing around you can delete the image like so:

Shell
 




x


 
1
#!/bin/sh
2
 
          
3
export AZURE_SUBSCRIPTION_ID=""
4
export AZURE_LOCATION_DEFAULT="westus2"
5
export AZURE_TENANT_ID=""
6
export AZURE_CLIENT_ID=""
7
export AZURE_CLIENT_SECRET=""
8
 
          
9
ops image delete -t azure gtest2


There is plenty of more integration work that we can do for Azure so if you are a big Azure user definitely check out the OPS repo -- we also accept pull requests!


It just might finally be the year of Linux on the desktop - well at least on the windows desktop!

Topics:
azure, devops, hyper-v, linux, unikernel

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}