Gabriel
Gabriel

Reputation: 33

Azure: blob uri null when creating image from VM

I am using the Azure CLI v2.0 and when I try to create an image from a VM, the blob URI is null: { ... "osDisk": { "blobUri": null, ... } ... }

I followed the steps from the Microsoft doc and I used a Ubuntu LTS VM created on the Azure portal.

The weird thing is that I already created an image from a VM and at this time, I had a blob URI for my image.

I need the blob URI to get the SAS in order to publish an app in the Azure marketplace.

Also, the URI does not appear in the Azure portal as well and if I try to create a VM from this image, it is successful.

Does anyone have any suggestion on why this is happening?

Thank you.

Upvotes: 1

Views: 2889

Answers (1)

Jason Ye
Jason Ye

Reputation: 13954

By default, we create image with CLI 2.0, the new create image not store in Azure storage account, we can find it in images:
enter image description here

========================================================
Update:
Create a image from a managed disk, we can't find the URI in Azure portal: enter image description here

For now, we can't create SAS for managed image.
In your scenario, I think we should use snapshots. A snapshot is a copy of a disk at the point in time it is taken, it only applies to one disk. If you have a VM that only has one disks(the OS), we can take a snapshot of it(we should generalize it first).

After snapshot created, we can grant access to this snapshot, also we can copy this snapshot to target Azure subscription. Then we can use this snapshot to create a image and use this image to create a new vm.(snapshot can copy to a different region.)

About create SAS of this snapshot, we can use CLI 2.0 to do it.

C:\Users\jason>az snapshot grant-access --help

Command
    az snapshot grant-access: Grant read access to a snapshot.

Arguments
    --duration-in-seconds [Required]: Time duration in seconds until the SAS access expires.

Resource Id Arguments
    --ids                           : One or more resource IDs (space delimited). If provided, no
                                      other 'Resource Id' arguments should be specified.
    --name -n                       : The name of the snapshot.
    --resource-group -g             : Name of resource group. You can configure the default group
                                      using `az configure --defaults group=<name>`.

More information about create new VM with snapshot, please refer to this link.

How to create a managed image from a snapshot, please refer to this link.

Update2:

we can use powershell to copy managed disk to azure storage account:

##create $SAS
$sas = Grant-AzureRmDiskAccess -ResourceGroupName shui -DiskName test -DurationInSecond 3600 -Access Read 
$destContext = New-AzureStorageContext –StorageAccountName contosostorageav1 -StorageAccountKey 'YourStorageAccountKey' 
Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer 'vhds' -DestContext $destContext -DestBlob 'MyDestinationBlobName.vhd'

Update3:
We can use CLI 2.0 to copy snapshot to azure storage account:

az account set --subscription $subscriptionId

sas=$(az snapshot grant-access --resource-group $resourceGroupName --name $snapshotName --duration-in-seconds $sasExpiryDuration --query [accessSas] -o tsv)

az storage blob copy start --destination-blob $destinationVHDFileName --destination-container $storageContainerName --account-name $storageAccountName --account-key $storageAccountKey --source-uri $sas

More information about copy snapshot to storage account, please refer to this link.

Upvotes: 1

Related Questions