Adding CentOS 7 to Azure Stack TP1

By default Azure Stack TP1 comes with a Windows 2012 R2 image available for the tenants.
I wanted to expand my testing capabilities with a Linux deployment as well and I choose CentOS as my distribution.
In this blog post I’m going to guide you through the creation of the image vhd on the Azure Stack box and making it available for the tenants.

Note: I got some feedback that if you run your Azure Stack host from vhd, the driveletters could be different from what is described in this post.
This post is based on a host with Windows installed on the disk directly.

Creating a VM on the Azure Stack Hyper-V machine

I’m not near to my test environment and my internet connection has a limited upload speed so I decided to prep my image on the Azure Stack Hyper-V box itself.
Create the VM using the following PowerShell code:

The script will download the CentOS iso and create and configure a VM. Then it will set the Isolation settings inline with the ADVM VM.
Finally it imports a function used by the fabric installer to assign the port profile associated with the Azure Stack VMs. Without it, there will be no network connectivity for the VM.
The VM is started.

Installing CentOS

Now the VM is ready to be installed and prepped.  Run the following to open the console to it.

Select “Install CentOS 7” from the menu.

BG_AS_CentOS_01

Select Continue in the language menu

BG_AS_CentOS_02

Select Installation Destination

BG_AS_CentOS_03

Select I will configure partitioning and select done

BG_AS_CentOS_04

Select from the drop down list “Standard Partition” (best practice for Azure Linux VMs) and hit “Click here to create them automatically”

BG_AS_CentOS_05

Now select Done

BG_AS_CentOS_06

Select “Accept changes”

BG_AS_CentOS_07

Hit begin installation

While waiting for installation to finish, assign a temporary Root password

BG_AS_CentOS_08

Once installation is finished, select Reboot.

Preparing the image

Once CentOS is booted, login with root and the password assigned during setup.

BG_AS_CentOS_10

Now we will enable networking so we can update the image and install all requirements.
First open /etc/sysconfig/network by typing vi /etc/sysconfig/network
In vi hit “i” to enable insert mode and add the following lines:
NETWORKING=yes
GATEWAY=192.168.100.1
Next hit “ESC” and type “:wq” which stands for write and quit.
Run cat /etc/sysconfig/network. The output should look like:
BG_AS_CentOS_11

Now that you know how to edit files, from now on I only tell what to adjust 🙂

Modify /etc/sysconfig/network-scripts/ifcfg-eth0. It should contain only the following:

TYPE=Ethernet
BOOTPROTO=static
DEVICE=eth0
ONBOOT=yes
USERCTL=no
PEERDNS=yes
IPV6INIT=no
IPADDR=192.168.100.15
NETMASK=255.255.255.0

I checked for free IP addresses and 15 was the first one free for me.

Modify /etc/resolv.conf. It should contain only the following:

nameserver 192.168.100.2

Now the network config files have been set, let’s restart the network service to enable the interface.

Now we will update the CentOS packages and install some prereqs. Once it is done, we’ll restart the OS.

Once CentOS is booted again, login with root and run the following:

This will download the latest Windows Azure Linux Agent from GitHub (release notes). This is a pre-release containing fixes specifically for Azure Stack.
Normally you would not take this route but you would install the package from a package repository using yum (this pre-release version however is not yet available through this route).

Once the WALinuxAgent tar file is downloaded, it is extracted. The daemon is installed and enabled and leftovers will be cleaned up.

Now edit/etc/default/grub. Change the line GRUB_CMDLINE_LINUX so it only has these values: “rootdelay=300 console=ttyS0 earlyprintk=ttyS0”
Next generate a new grub config.

Edit /etc/waagent.conf and modify ResourceDisk.Format=y to ResourceDisk.Format=n as Azure Stack does not have the temporary drive (yet).

Now edit /etc/sysconfig/network-scripts/ifcfg-eth0 again.
Change BOOTPROTO=dhcp and remove the lines IPADDR and NETMASK.

Edit /etc/sysconfig/network and remove the line GATEWAY.

Finally edit /etc/resolv.conf and remove the line nameserver.

Now it’s time to deprovision the OS (sysprep for Linux), clear the captured history and logout.

Now shutdown the VM through Hyper-V VM Controls.

Add Image to CRP

Now the image is properly prepped, we can add it to the PlatformImages Directory of the Compute Resource Provider.
Microsoft shipped a PowerShell script to help with the procedure and generate the json manifest for you.
Run the following:

The image now is available.

BG_AS_CentOS_12

Happy deploying!

Spread the word. Share this post!

  • Abinaya

    Thanks for adding the instructions for deploying a CentOS VM.

    I am using a proxy server so I had ‘Failed to connect’ Error during yum installs. It was missing proxy setting in /etc/yum.conf. So I added ‘proxy=http://:portnumber’ to yum.conf.

    Also while adding image to CRP I noticed that the initial VHD created was called ‘CentOS2.vhd’ and not ‘CentOS.vhd’. This gave out an error as well.

    • Thanks for sharing the proxy settings and discovering a bug in my VM creation code 🙂 Fixed now.

  • Abinaya

    I created a VM successfully from the tenant portal and its is running. However, ‘Connect’ option is grayed out. I can access it from the Hyper-V host. Is there a way to connect to it from the portal?

    • This is expected and consistent with Azure.
      Both Azure and Azure Stack do not offer you a way to connect to the console of the VM.
      For Windows VMs however, RDP is enabled and the connect button downloads an RDP file for you allowing you to Remote in.
      Linux does not support RDP connections. If you want to connect with your Linux VM, find the public IP and use a tool like Putty to setup an SSH session.

  • Stanislas Quastana Pro

    Congratulations it’s a really great content. I followed your guide this morning on my Azure Stack POC. It works perfectly 🙂

  • Kharcoff

    This got to be the best Azure Stack post so far…. Thanks a lot!.

  • Ashish Ambavane

    Thanks for the post. Very helpful.
    I followed the steps and centos7 image is added to PIR but still I cant see it in the portal. I increased memory of xRPVM from 4 to 8 gb and number of processor to 8 but no image shows up in the portal.
    Do you have any idea how to debug this? It would be of great help.
    Thanks,

    Ashish

    • Hi Ashish,
      from what I have come to know, this behavior could happen if the manifest isn’t created as expected.
      Could you copy / paste the resulting manifest into this discussion so we can take a look at it?
      Thanks, Ben

      • Ashish Ambavane

        Hi ben ,
        Yes that was related to manifest file creation, i changed the value of SKU to “centos7” and re-ran the script which wroked smooth!!. But when i deploy the VM it fails at stage “Microsoft.Compute/virtualMachines”. An internal execution error occurred. Status Conflict.
        to be specific –
        {“status”:”Failed”,”error”:{“code”:”ResourceDeploymentFailure”,”message”:”The resource operation completed with terminal provisioning state ‘Failed’.”,”details”:[{“code”:”InternalExecutionError”,”message”:”An internal execution error occurred.”}]}}

        I checked xRPVM and all services are up and running so is it because i screwed something up while prepping the image? can you provide some suggestions about debugging this error?

        Thank you , Ashish

        • Hi Ashish,
          That is a pretty vague error 🙂
          I would take this route:
          * Look at Hyper-V level to see if VM is actually created (check the notes field for correlation info)
          * If the VM was created, connect to the console and see if Linux is booted. (if some boot error is showing I would delete the image from the PIR and recreate it)
          * If Linux is booted, check if you can login using the credentials specified during deployment. (If you cannot, the waagent probably was not started during boot, I would recreate the image)
          * If you can login, check the waagent.log file at /var/log to see if something went wrong with coordination between CRP and waagent during deployment
          HTH, Ben

  • Pingback: Azure Stack TP1 Review - Hybrid Cloud – Azure and Hosters - Site Home - TechNet Blogs()

  • Charles Windom

    CentOS not showing up the Azure Stack portal. When you run the final bit of PowerShell code, is tghis run from the ClientVM or from the Azure Stack POC machine?

    Thanks,
    Charles

  • Christof

    Thanks for the Great Blog. Very Helpful.
    I followed all your Steps and ran the last powershell script without any error. Unfortunately the Image is not shown in the Azure Stack Portal. I tried it with some other vhd’s, without succes. The manifest looks correct:
    {
    “Publisher”:”Suse”,
    “Offer”:”Linux Server”,
    “Sku”:”SUSE-Linux-ENT-12-SP1″,
    “Version”:”12.0.0″,

    “PlatformImage” :{
    “OsDisk” : {
    “OsType”:”Linux”,
    “FileName”:”SLE-12-SP1-Server-Azure-Stack-x86_64.vhd”
    }
    }
    }

    Do you have any Idea, why the image is not shown in the Portal?

    Thanks,
    Christof

    • Christof

      Connect to the portal with the old Internet Explorer has fixed the issue. The Image is now shown.