Lainad
Lainad

Reputation: 221

How to create Azure VM with smaller storage

The default Disk Size when creating a VM in azure is 30GB. I only use around 3GB of it. Now, Azure offers a 4GB disk, at a sixteenth of the cost. They decided to make it SO complicated to make it 4GB or 8GB, instead of just offering as an option when creating a VM.

All I need to do is to create a new 4GB managed disk. enter image description here

How do I get the VHD file for ubuntu so I can finally make the disk? I was looking everywhere but can't find the answer.

Upvotes: 4

Views: 1520

Answers (2)

olin000
olin000

Reputation: 1066

I managed to go as low as to just 3 GB and have Ubuntu 20.04 LTS (Focal Fossa) running as an Azure VM.

enter image description here

Prerequisites are below mentioned images downloaded from https://cloud-images.ubuntu.com/focal/current/, a tool to convert VMDK to VHD (e.g. 2Tware Convert VHD) and Hyper-V Manager installed/turned on under local Windows features.

  1. I couldn’t go that low when using the dedicated focal-server-cloudimg-amd64-azure.vhd.zip. When unpacked the file livecd.ubuntu-cpc.azure.vhd is 30-31 GB large. I didn’t manage to shrink it (only an expansion was possible), so the result would have been worse than the original (30GB) Ubuntu VMs from Azure Marketplace.

enter image description here

  1. I have downloaded focal-server-cloudimg-amd64.vmdk instead. Here a conversion to VHD was needed with help of 2Tware Convert VHD. Unfortunately, if uploaded to Azure this image is not accepted as it is a Dynamic VHD.
  2. I had to use Hyper-V Manager to convert it to fixed. Here however I faced one another issue. When in Hyper-V Manager going through Edit Disks…->Browse…->Convert->VHD->Fixed the file I was getting was 10 GB large (noticeable improvement, but still larger than the final 3 GB).
  3. Instead of going through Edit Disks… I went for Quick Create… of a new Virtual Machine. I chose Local installation source and selected the VHD file converted from VMDK. Finally, I clicked Create Virtual Machine.
  4. The VM is created, but there is no need to connect to it. In fact, it can be deleted right away, as what is really needed is the file (presumably) stored as New Virtual Machine.vhdx under C:\Users\Public\Documents\Hyper-V\Virtual hard disks\ or C:\ProgramData\Microsoft\Windows\Virtual Hard Disks\.
  5. With help of Hyper-V Manager this time I managed to both convert the file to Fixed VHD as well as to shrink it to 3 GB.

enter image description here

  1. Later the process is as described in @Ked Mardemootoo’s answer (the instruction from IBM). A new Storage account needs to be created in Azure. Then in the Storage Account a new blob Container needs to be created. The VHD file is to be uploaded to the Container. Later a new Image needs to be created from this Storage blob and from this image a new small VM can be successfully created.

enter image description here

Upvotes: 1

Ked Mardemootoo
Ked Mardemootoo

Reputation: 1595

EDIT:

As mentioned in the comments, what you require is the Desktop version of Ubuntu and not the Server one. In addition to Ubuntu NOT providing any Azure-compatible Desktop version of Ubuntu, Azure only endorses the Ubuntu versions below:

Ubuntu Server and Pro. 16.x, 18.x, 20.x Information about extended support for Ubuntu 12.04 and 14.04 can be found here: Ubuntu Extended Security Maintenance.

Additional distro support info here too.

For the images below, you rightly pointed out (apologies for overlooking) that it will still provide you with a 30GB image after conversion.

Also, because Ubuntu Server and Desktop editions share the same kernel, it should be possible for you to follow the same steps to download and create your custom image by following the same prep steps outlined for non-endorsed distros, convert it to VHD and then upload it. Even if this is successful, it's also possible that it will cause some other issues with underlying Azure services.

One last option I thought of is using Azure Migrate to move an existing on-premises Ubuntu VM to Azure. This option failed when we tried but I should disclose our VM was running a much older version of CentOS. When using Azure Migrate, Azure will analyse your machine and tell you whether your VM is supported.


Original Answer:

So here's the thing - you can only use images that are in an Azure Storage Account. Although it seems you've been through a lot already, I'm afraid it doesn't get any easier but steps are generally clear on how it can be done.

1 - Get the image

The Azure documentation on the topic actually recommends to download it from the official Ubuntu cloud repository.

Note

Before attempting to create your own custom Ubuntu image for Azure, please consider using the pre-built and tested images from https://cloud-images.ubuntu.com/ instead.

You can also just download one of the two versions listed on the documentation - this will provide you with a .VHDX file.

enter image description here

2 - Convert the VHDX to VHD

Azure does not support the .VHDX format. See:

The VHDX format is not supported in Azure, only fixed VHD. You can convert the disk to VHD format using Hyper-V Manager or the Convert-VHD cmdlet.

Here's an article which explains how to do this with both options.

3 - Upload the VHD to Blob

Once you have the file in VHD format, you can now upload it to Azure.

  1. You can use AzCopy which is rather complicated when compared to a direct upload, but just mentioning that this can also be done. It also seems to be the recommended approach from Azure.

  2. The easiest option is to upload manually through the Portal. See this article that goes into details - pick what's relevant to you.

    (a) Choose your storage account, create/select a container you want to upload to

    (b) Click Upload and select the Ubuntu VHD file to upload.

Ensure that the Blob type is set to Page Blob.

4 - Create a Managed Disk and VM

  1. Once your Ubuntu VHD is uploaded, go to its properties page and get the blob URI.
  2. Use that when creating the disk.
  3. Create a VM from the managed disk.

That should be all - it's very painful but possible

Upvotes: 2

Related Questions