MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.2k stars 21.36k forks source link

How do you download images from Azure Image Gallery? #32886

Closed GuyPaddock closed 2 years ago

GuyPaddock commented 5 years ago

The docs say:

The second option is to create the image locally by downloading the image, provisioning a Hyper-V VM, and customizing it to suit your needs, which we cover in the following section.

And:

Once you've downloaded the image to a local location, open Hyper-V Manager to create a VM with the VHD you copied.

How do you download the image? This is not clear.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

mimckitt commented 5 years ago

Thanks for the feedback! We are currently investigating and will update you shortly.

mimckitt commented 5 years ago

@GuyPaddock thanks for pointing this out. I completely agree the steps to download are not clear and or not there at all.

@Heidilohr can you take a look?

TETZUO commented 5 years ago

Any Update on this?

TomHickling commented 5 years ago

Go to the VM in the Portal and deallocate it , click on the Disk, then Disk Export, follow the instructions to create a SAS and then you can download the VHD. Might be worthwhile deploying Hyper-V in Azure to save some time in the download and resulting upload process.

bergerpascal commented 4 years ago

Found this blog post that helps: https://www.microcloud.nl/create-a-wim-file-from-the-wvd-vhd-file/#_First,_we_need

lmcdasm commented 3 years ago

Hello there.

any update on this - it seems that we shouldnt have to provision an VM so that we can get to the DISK and then export as an image.

LH-MSFT commented 3 years ago

Have a need for the same -- do we have any update on this? Would prefer to download a marketplace image without having to provision a VM?

tim-ebu commented 2 years ago

Two years since issue was raised and docs are neither updated to say you cannot do this, nor updated to explain how to do it!

Tim

Mslance commented 2 years ago

Here is how to download an image without provisioning a VM using Powershell:

$location = "Central US" $rgName = "rg" $region = "Central US"

$imgver = Get-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName "gallery" -GalleryImageDefinitionName "myImg" -Name "myImgVer" $galleryImageVersionID = $imgver.Id

$diskName = "tmpOSDisk" $imageOSDisk = @{Id = $galleryImageVersionID} $OSDiskConfig = New-AzDiskConfig -Location $location -CreateOption "FromImage" -GalleryImageReference $imageOSDisk $osd = New-AzDisk -ResourceGroupName $rgName -DiskName $diskName -Disk $OSDiskConfig

$sas = Grant-AzDiskAccess -ResourceGroupName $rgName -DiskName $osd.Name -Access "Read" -DurationInSecond 3600 $wc = New-Object System.Net.WebClient $wc.DownloadFile($sas.AccessSAS, "c:\targetdir\myImg.vhd")

Don't forget to delete the disk created above.

Revoke-AzDiskAccess -ResourceGroupName $rgName -DiskName $diskName Remove-AzDisk -ResourceGroupName $rgName -DiskName $diskName -Force

dknappettmsft commented 2 years ago

Closing the loop on this - the change from dcbrown16 has been incorporated to provide links on how to do this.

please-close

030 commented 2 years ago

Here is how to download an image without provisioning a VM using Powershell:

$location = "Central US" $rgName = "rg" $region = "Central US"

$imgver = Get-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName "gallery" -GalleryImageDefinitionName "myImg" -Name "myImgVer" $galleryImageVersionID = $imgver.Id

$diskName = "tmpOSDisk" $imageOSDisk = @{Id = $galleryImageVersionID} $OSDiskConfig = New-AzDiskConfig -Location $location -CreateOption "FromImage" -GalleryImageReference $imageOSDisk $osd = New-AzDisk -ResourceGroupName $rgName -DiskName $diskName -Disk $OSDiskConfig

$sas = Grant-AzDiskAccess -ResourceGroupName $rgName -DiskName $osd.Name -Access "Read" -DurationInSecond 3600 $wc = New-Object System.Net.WebClient $wc.DownloadFile($sas.AccessSAS, "c:\targetdir\myImg.vhd")

Don't forget to delete the disk created above.

Revoke-AzDiskAccess -ResourceGroupName $rgName -DiskName $diskName Remove-AzDisk -ResourceGroupName $rgName -DiskName $diskName -Force

I did the same, but then by using the az-cli.

Lancelot0105 commented 8 months ago

Hey @030 , Could you please share the template for the code which you used using az - cli ? I am having the above use case as well and If the solution was towards az-cli formatted, it would be really helpful.

030 commented 8 months ago

@Lancelot0105 I do not work with Azure at the moment.

Lancelot0105 commented 8 months ago

Hey @030, could you please help me with the flow on how I can download an image without provisioning a VM using az cli?

030 commented 8 months ago

I used https://github.com/Azure/azure-storage-azcopy back then, but no idea if that would still work well as I do not work with Azure anymore for more than a year now.