Sibeesh Passion

Top Menu

  • Home
  • Search
  • About
  • Privacy Policy

Main Menu

  • Articles
    • Azure
    • .NET
    • IoT
    • JavaScript
    • Career Advice
    • Interview
    • Angular
    • Node JS
    • JQuery
    • Knockout JS
    • Jasmine Framework
    • SQL
    • MongoDB
    • MySQL
    • WordPress
  • Contributions
    • Medium
    • GitHub
    • Stack Overflow
    • Unsplash
    • ASP.NET Forum
    • C# Corner
    • Code Project
    • DZone
    • MSDN
  • Social Media
    • LinkedIn
    • Facebook
    • Instagram
    • Twitter
  • YouTube
    • Sibeesh Venu
    • Sibeesh Passion
  • Awards
  • Home
  • Search
  • About
  • Privacy Policy

logo

Sibeesh Passion

  • Articles
    • Azure
    • .NET
    • IoT
    • JavaScript
    • Career Advice
    • Interview
    • Angular
    • Node JS
    • JQuery
    • Knockout JS
    • Jasmine Framework
    • SQL
    • MongoDB
    • MySQL
    • WordPress
  • Contributions
    • Medium
    • GitHub
    • Stack Overflow
    • Unsplash
    • ASP.NET Forum
    • C# Corner
    • Code Project
    • DZone
    • MSDN
  • Social Media
    • LinkedIn
    • Facebook
    • Instagram
    • Twitter
  • YouTube
    • Sibeesh Venu
    • Sibeesh Passion
  • Awards
  • Linux Azure Function Isolated Dot Net 9 YAML Template Deployment

  • Build, Deploy, Configure CI &CD Your Static Website in 5 mins

  • Post Messages to Microsoft Teams Using Python

  • Get Azure Blob Storage Blob Metadata Using PowerShell

  • Deploy .net 6 App to Azure from Azure DevOps using Pipelines

Azure
Home›Azure›Creating an Azure VM from the VHDX/VHD File

Creating an Azure VM from the VHDX/VHD File

By SibeeshVenu
March 6, 2019
632
0
Share:
VM IP configuration

[toc]

Introduction

When you have an on premises Virtual Machine and if you need to move the same to a cloud, you should create a Virtual Hard Disk. The virtual hard disks are of two types, one is VHD and the other is VHDX. Unfortunately the Microsoft Azure cloud supports only the generation 1 VMs which are VHD, These VHDs are fixed size and the maximum size allowed is 1023 GB. Here in this article, we are going to see how we can spin up a Virtual Machine in Azure from the VHD file we have. I will explain why I came to this situation in the Background section. I hope you will find this article useful.

Background

I was working with a product called UCS (Univention Corporate Server), you can consider it as a private play store where you can install and use your custom applications, you are also allowed to use the existing ones as well. Now I wanted to create an Azure VM with the UCS in it, but all I had in my hand was a VHDX file, which is not supported in Azure.

Steps

In this article, we will be doing the following tasks.

  1. Converting the VHDX file to VHD
  2. Upload it to the Azure Blob storage
  3. Create a Managed Image from the VHD
  4. Create the Virtual Machine from the Managed Image

Spin up the Azure VM from VHDX

As we have discussed, the first step is to convert the VHDX file to VHD.

Convert VHDX to VHD

We are going to use PowerShell for the conversion as it has some modules already to support this conversion.

Convert-VHD –Path c:\CreateVM\ucs.vhdx –DestinationPath c:\CreateVM\ucs.vhd -VHDType Fixed

Please be noted that the Argument -VHDType is very important, otherwise you may be getting an error as follows, when you try to create the Managed image using the command New-AzImage.

New-AzImage : Only blobs formatted as VHDs can be imported.
ErrorCode: InvalidParameter
ErrorMessage: Only blobs formatted as VHDs can be imported.
ErrorTarget: disks
StatusCode: 400
ReasonPhrase: Bad Request
OperationID : 16baa116-be93-4054-8ba9-265eda636f0c
At line:1 char:10
+ $image = New-AzImage -ImageName $imageName -ResourceGroupName $rgName ...
+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzImage], ComputeCloudException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.Automation.NewAzureRmImage

Once you are done a new VHD image will be created in the destination path you have given. Please be noted that the size of this file may be huge, and when you upload it to the Blob storage, it may take a longer depends on the network speed you have.

Upload the VHD file to Azure Blob Storage

As a prerequisite, you should create a storage account before you start this process. Once you have created the storage account, you are good to go and start the upload. Go to your Storage account, and click on the Blobs under blob services.

Now you can click on the +Container menu item and create a new container which is nothing but the container for your files. Now we can go inside the container and click on the Upload button. In the upcoming pop up you can select the VHD file using the file picker option and upload the file. As I said earlier, this process is totally depends on your network speed.

Sometimes, due to the browser inactivity, the uploading of the heavy files to the blobs using Azure portal can be a headache as it throws error. One of the suggestion I can give you here is to use Azure Storage Explorer tool, which is quite easy to use and effective. Once you download the tool, login with your Azure credentials and got to the storage accounts and click on Blob Containers. In the new window click on Upload and then Upload files.

Please make sure that you are selecting the Blob type as Page Blob and then click upload. The uploading is really faster if you are using the tool instead of the portal.

Create a Managed Image from the VHD file

As we have our VHD file in our Blobs, now it is time to create an Image from the file. We are going to write some PowerShell commands to do the work for us. To set the configuration we are going to use the command New-AzImageConfig. If you are getting the error “The term New-AzImageConfig ‘ is not recognized as the name of a cmdlet”, you should install and import the module Az.Compute.

Install-Module Az.Compute
import-module Az.Compute

It is possible to get some additional error when you try to install the Az.Compute module. In that case, you can try the preceding command.

 Install-Module Az.Compute -AllowClobber

Once that is done, we can set some variables in the PowerShell as follows.

$vmName = "ucs"
$rgName = "ucs"
$location = "West Europe"
$imageName = "ucs"
$osVhdUri = "https://ucs.blob.core.windows.net/files/ucs.vhd"

Now we can start the image creation as preceding.

$imageConfig = New-AzImageConfig -Location $location
$imageConfig = Set-AzImageOsDisk -Image $imageConfig -OsType Linux -OsState Generalized -BlobUri $osVhdUri
$image = New-AzImage -ImageName $imageName -ResourceGroupName $rgName -Image $imageConfig

As the UCS is a Linux based system, I had given the -OsType as Linux, you may have to change it as per your needs. If you are trying to run the command New-AzImage with the VHDX blob, you will get an error as below.

New-AzImage : Blob name in URL https://ucs.blob.core.windows.net/files/ucs.vhdx must end with ".vhd" extension.
ErrorCode: InvalidParameter
ErrorMessage: Blob name in URL https://ucs.blob.core.windows.net/files/ucs.vhdx must end with ".vhd" extension.
ErrorTarget: blobUri
StatusCode: 400
ReasonPhrase: Bad Request
OperationID : 668b8e66-85b3-4c7b-a182-4f155e16b66d
At line:1 char:10
+ $image = New-AzImage -ImageName $imageName -ResourceGroupName $rgName ...
+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzImage], ComputeCloudException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.Automation.NewAzureRmImage

But we don’t need to worry about it as we already converted our VHDX file to VHD format. Once the New-AzImage command is successful, you can see the image in the Azure portal if you go to the Images section. You can search for the keyword “Images” in the portal.

Create a VM from the Managed Image

As we have the image now, we can create our VM easily from the Azure portal. Go to the Images and select your image and then click on the button +Create VM. In the next page, you can give the details of your VM. You can also create the VM by using the PowerShell command as preceding.

New-AzVm `
    -ResourceGroupName "myResourceGroup" `
    -Name "myVMfromImage" `
    -ImageName "myImage" `
    -Location "East US" `
    -VirtualNetworkName "myImageVnet" `
    -SubnetName "myImageSubnet" `
    -SecurityGroupName "myImageNSG" `
    -PublicIpAddressName "myImagePIP" `
    -OpenPorts 3389

Once you had filled all the details, you can either click on the Review+Create or you can go through each step. The creation of VM can take a few minutes. Once the task is done, you can go to your Virtual Machine and spin up the same. I would also recommend you to assign a static IP and DNS name to your VM.

Conclusion

In this article, we have learned,

  • What are VHDX and VHD files
  • How to convert the VHDX file to VHD
  • How to upload VHD files to Azure Blob storage
  • How to create Managed Image from the VHD file in Azure
  • How to create Virtual Machine using the Managed Image

Your turn. What do you think?

Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post as useful? Kindly do not forget to share me your feedback.

Kindest Regards
Sibeesh Venu

TagsAzureAzure Managed ImageAzure Virtual MachineAzure VMConvert VHDX to VHDpowershellVHDX and VHD
Previous Article

Create Your Own Cryptocurrency in Private Consortium ...

Next Article

Using Azure Cognitive Service Computer Vision AI ...

0
Shares
  • 0
  • +
  • 0
  • 0
  • 0

SibeeshVenu

I am Sibeesh Venu, an engineer by profession and writer by passion. Microsoft MVP, Author, Speaker, Content Creator, Youtuber, Programmer.

Related articles More from author

  • Azure Mobile App preview
    Azure

    Creating Azure Mobile App With Visual Studio

    April 24, 2016
    By SibeeshVenu
  • Azureazure devops

    Move Azure DevOps Work Items From One Organization to Another

    March 9, 2020
    By SibeeshVenu
  • Back Up And Restore Your Old MySQL Database to New Database
    AzureDatabaseMySQLVirtual Machine

    Back Up your ClearDB and restore in Azure Virtual Machine MySQL

    September 18, 2015
    By SibeeshVenu
  • Azure

    Azure Function Job to Delete Azure Blobs from Blob Containers

    July 24, 2019
    By SibeeshVenu
  • Azure

    Azure DevOps Service Connection with Multiple Azure Resource Group

    November 19, 2021
    By SibeeshVenu
  • Azure

    Validating Azure ARM Template Never Been Easier

    November 5, 2020
    By SibeeshVenu
0

My book

Asp Net Core and Azure with Raspberry Pi Sibeesh Venu

YouTube

MICROSOFT MVP (2016-2022)

profile for Sibeesh Venu - Microsoft MVP

Recent Posts

  • Linux Azure Function Isolated Dot Net 9 YAML Template Deployment
  • Build, Deploy, Configure CI &CD Your Static Website in 5 mins
  • Easily move data from one COSMOS DB to another
  • .NET 8 New and Efficient Way to Check IP is in Given IP Range
  • Async Client IP safelist for Dot NET
  • Post Messages to Microsoft Teams Using Python
  • Get Azure Blob Storage Blob Metadata Using PowerShell
  • Deploy .net 6 App to Azure from Azure DevOps using Pipelines
  • Integrate Azure App Insights in 1 Minute to .Net6 Application
  • Azure DevOps Service Connection with Multiple Azure Resource Group

Tags

Achievements (35) Angular (14) Angular 5 (7) Angular JS (15) article (10) Article Of The Day (13) Asp.Net (14) Azure (65) Azure DevOps (10) Azure Function (10) Azure IoT (7) C# (17) c-sharp corner (13) Career Advice (11) chart (11) CSharp (7) CSS (7) CSS3 (6) HighChart (10) How To (9) HTML5 (10) HTML5 Chart (11) Interview (6) IoT (11) Javascript (10) JQuery (82) jquery functions (9) JQWidgets (15) JQX Grid (17) Json (7) Microsoft (8) MVC (20) MVP (9) MXChip (7) News (18) Office 365 (7) Products (10) SQL (20) SQL Server (15) Visual Studio (10) Visual Studio 2017 (7) VS2017 (7) Web API (12) Windows 10 (7) Wordpress (9)
  • .NET
  • Achievements
  • ADO.NET
  • Android
  • Angular
  • Arduino
  • Article Of The Day
  • ASP.NET
  • Asp.Net Core
  • Automobile
  • Awards
  • Azure
  • Azure CDN
  • azure devops
  • Blockchain
  • Blog
  • Browser
  • C-Sharp Corner
  • C#
  • Career Advice
  • Code Snippets
  • CodeProject
  • Cognitive Services
  • Cosmos DB
  • CSS
  • CSS3
  • Data Factory
  • Database
  • Docker
  • Drawings
  • Drill Down Chart
  • English
  • Excel Programming
  • Exporting
  • Facebook
  • Fun
  • Gadgets
  • GitHub
  • GoPro
  • High Map
  • HighChart
  • How to
  • HTML
  • HTML5
  • Ignite UI
  • IIS
  • Interview
  • IoT
  • JavaScript
  • JQuery
  • jQuery UI
  • JQWidgets
  • JQX Grid
  • Json
  • Knockout JS
  • Linux
  • Machine Learning
  • Malayalam
  • Malayalam Poems
  • MDX Query
  • Microsoft
  • Microsoft ADOMD
  • Microsoft MVP
  • Microsoft Office
  • Microsoft Technologies
  • Microsoft Windows
  • Microsoft Windows Server
  • Mobile
  • MongoDB
  • Monthly Winners
  • MVC
  • MVC Grid
  • MySQL
  • News
  • Node JS
  • npm
  • Number Conversions
  • October 2015
  • Office 365
  • Office Development
  • One Plus
  • Outlook
  • Page
  • PHP
  • Poems
  • PowerShell
  • Products
  • Q&A
  • Raspberry PI
  • React
  • SEO
  • SharePoint
  • Skype
  • Social Media
  • Software
  • Spire.Doc
  • Spire.PDF
  • Spire.XLS
  • SQL
  • SQL Server
  • SSAS
  • SSMS
  • Storage In HTML5
  • Stories
  • Third Party Software Apps
  • Tips
  • Tools
  • Translator Text
  • Uncategorized
  • Unit Testing
  • UWP
  • VB.Net
  • Videos
  • Virtual Machine
  • Visual Studio
  • Visual Studio 2017
  • Wamp Server
  • Web API
  • Web Platform Installer
  • Webinars
  • WebMatrix
  • Windows 10
  • Windows 7
  • Windows 8.1
  • Wordpress
  • Writing

ABOUT ME

I am Sibeesh Venu, an engineer by profession and writer by passion. Microsoft MVP, Author, Speaker, Content Creator, Youtuber, Programmer. If you would like to know more about me, you can read my story here.

Contact Me

  • info@sibeeshpassion.com

Pages

  • About
  • Search
  • Privacy Policy
  • About
  • Search
  • Privacy Policy
© Copyright Sibeesh Passion 2014-2025. All Rights Reserved.
Go to mobile version