I know I can create a managed disk from a Blob VHD.
However, my blob VHD is 4TB large (4095GB).
And then the console says:
The source blob's size must be 20 MiB - 4095 GiB.
Now my question is, is there a workaround that I can create the disk from this Blob?
Thank you.
You could try to use azure powershell to create it, refer to this article.
Sample:
#Provide the subscription Id where Managed Disks will be created
$subscriptionId = 'yourSubscriptionId'
#Provide the name of your resource group where Managed Disks will be created.
$resourceGroupName ='yourResourceGroupName'
#Provide the name of the Managed Disk
$diskName = 'yourDiskName'
#Provide the size of the disks in GB. It should be greater than the VHD file size.
$diskSize = '128'
#Provide the storage type for Managed Disk. PremiumLRS or StandardLRS.
$storageType = 'PremiumLRS'
#Provide the Azure region (e.g. westus) where Managed Disk will be located.
#This location should be same as the storage account where VHD file is stored
#Get all the Azure location using command below:
#Get-AzureRmLocation
$location = 'westus'
#Provide the URI of the VHD file (page blob) in a storage account. Please not that this is NOT the SAS URI of the storage container where VHD file is stored.
#e.g. https://contosostorageaccount1.blob.core.windows.net/vhds/contosovhd123.vhd
#Note: VHD file can be deleted as soon as Managed Disk is created.
$sourceVHDURI = 'https://contosostorageaccount1.blob.core.windows.net/vhds/contosovhd123.vhd'
#Provide the resource Id of the storage account where VHD file is stored.
#e.g. /subscriptions/6472s1g8-h217-446b-b509-314e17e1efb0/resourceGroups/MDDemo/providers/Microsoft.Storage/storageAccounts/contosostorageaccount
#This is an optional parameter if you are creating managed disk in the same subscription
$storageAccountId = '/subscriptions/yourSubscriptionId/resourceGroups/yourResourceGroupName/providers/Microsoft.Storage/storageAccounts/yourStorageAccountName'
#Set the context to the subscription Id where Managed Disk will be created
Select-AzureRmSubscription -SubscriptionId $SubscriptionId
$diskConfig = New-AzureRmDiskConfig -AccountType $storageType -Location $location -CreateOption Import -StorageAccountId $storageAccountId -SourceUri $sourceVHDURI
New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName
Related
I have an Azure disk of Windows 10 system. I want this disk must be converted into VHD and should be available in the azure storage account.
In easier words, I want my Azure VM data disk to be present in the azure storage BLOB without downloading the VHD onto my base machine. Is it possible. If yes, please guide me.
Can anyone please help me in this.
Thanks
Yes, it's possible. You can copy the managed disk into the VHD file and store it in the storage. Here is the example code through PowerShell:
#Provide the subscription Id of the subscription where managed disk is created
$subscriptionId = "yourSubscriptionId"
#Provide the name of your resource group where managed is created
$resourceGroupName ="yourResourceGroupName"
#Provide the managed disk name
$diskName = "yourDiskName"
#Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600.
#Know more about SAS here: https://learn.microsoft.com/en-us/Az.Storage/storage-dotnet-shared-access-signature-part-1
$sasExpiryDuration = "3600"
#Provide storage account name where you want to copy the underlying VHD of the managed disk.
$storageAccountName = "yourstorageaccountName"
#Name of the storage container where the downloaded VHD will be stored
$storageContainerName = "yourstoragecontainername"
#Provide the key of the storage account where you want to copy the VHD of the managed disk.
$storageAccountKey = 'yourStorageAccountKey'
#Provide the name of the destination VHD file to which the VHD of the managed disk will be copied.
$destinationVHDFileName = "yourvhdfilename"
#Set the value to 1 to use AzCopy tool to download the data. This is the recommended option for faster copy.
#Download AzCopy v10 from the link here: https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-v10
#Ensure that AzCopy is downloaded in the same folder as this file
#If you set the value to 0 then Start-AzStorageBlobCopy will be used. Azure storage will asynchronously copy the data.
$useAzCopy = 1
# Set the context to the subscription Id where managed disk is created
Select-AzSubscription -SubscriptionId $SubscriptionId
#Generate the SAS for the managed disk
$sas = Grant-AzDiskAccess -ResourceGroupName $ResourceGroupName -DiskName $diskName -DurationInSecond $sasExpiryDuration -Access Read
#Create the context of the storage account where the underlying VHD of the managed disk will be copied
$destinationContext = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
#Copy the VHD of the managed disk to the storage account
if($useAzCopy -eq 1)
{
$containerSASURI = New-AzStorageContainerSASToken -Context $destinationContext -ExpiryTime(get-date).AddSeconds($sasExpiryDuration) -FullUri -Name $storageContainerName -Permission rw
$containername,$sastokenkey = $containerSASURI -split "\?"
$containerSASURI = "$containername/$destinationVHDFileName`?$sastokenkey"
azcopy copy $sas.AccessSAS $containerSASURI
}else{
Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName
}
But in my test, there is something wrong with the VHD file when you use the azcopy command. And the command Start-AzStorageBlobCopy works well. So I recommend command Start-AzStorageBlobCopy for you. And for more details, see Export/Copy the VHD of a managed disk to a storage account in different region with PowerShell.
I am a bit confused with the Azure managed data disk (in ARM) created from VHDs stored in storage source blob. I have a script that creates snapshots on all the storage blobs, but for some reason the changes that are made on the managed disks are not applied to the VHDs.
So the previous dependencies were like:
storage blob -> container -> VHDs -> VMs
Currently:
storage blob -> container -> VHDs -> managed data disks -> VMs
I also have made sure when the VMs were created to use additional data disks, which were created from the existing VHDs. Any ideas about the synchronization?
but for some reason the changes that are made on the managed disks
are not applied to the VHDs.
If you create snapshot of managed disk, you can find snapshot via Azure portal, like this:
But if you create snapshot of VHDs(unmanaged disk), the snapshot will not show in Azure portal, you should use Azure PowerShell to list it:
$rg = "Your_resource_group_name"
$saname = "Your_storage_account_name"
$con = "vhds"
$keylist = Get-AzureRmStorageAccountKey -ResourceGroupName $RG -StorageAccountName $saname
$Key = $Keylist[0].Value
$Ctx = New-AzureStorageContext -StorageAccountName $SAname -StorageAccountKey $Key
$List = Get-AzureStorageBlob -Blob *.vhd -Container $Con -Context $Ctx
Output like this:
When you create a managed disk from your own VHD blob your blob is copied to create the managed disk's blob in a different account. The managed disk does not even exist in your account, so taking snapshots of the original blob won't show any updates. You could even delete the original VHD blob and the managed disk will still exist.
If you want to create another VM with a copy of the modified managed disk you need to create a managed snapshot of that disk and use that managed snapshot as a source for your next VM.
I seem to have a problem creating a managed disk from a snapshot.
It appears that I can only create a disk in one region which is West US.
Here is the PowerShell script I use:
Get-AzureRmSubscription –SubscriptionName 'MySubscription' | Select-AzureRmSubscription
$resourceGroupName = 'MyResourceGroup';
$diskName = 'MyNewDisk';
$location = 'West US';
$snapshotName = 'MySnapshot';
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName;
$diskConfig = New-AzureRmDiskConfig -AccountType $storageType -Location $location -SourceResourceId $snapshot.Id -CreateOption Copy;
$disk = New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName;
If I change the variable $region value to 'East US' or any other region, I get en error in PowerShell (resource not found).
The snapshot itself is in West US but I want to create a disk in East US.
What am I doing wrong?
The snapshot itself is in West US but I want to create a disk in East
US. What am I doing wrong?
We can't create a managed disk from snapshot to another location.
If you want to create a managed disk from snapshot to another location, we should export/Copy managed snapshots as VHD to a storage account in different region with PowerShell.
Here the sample script:
#Provide the subscription Id of the subscription where snapshot is created
$subscriptionId = "yourSubscriptionId"
#Provide the name of your resource group where snapshot is created
$resourceGroupName ="yourResourceGroupName"
#Provide the snapshot name
$snapshotName = "yourSnapshotName"
#Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600.
#Know more about SAS here: https://learn.microsoft.com/en-us/azure/storage/storage-dotnet-shared-access-signature-part-1
$sasExpiryDuration = "3600"
#Provide storage account name where you want to copy the snapshot.
$storageAccountName = "yourstorageaccountName"
#Name of the storage container where the downloaded snapshot will be stored
$storageContainerName = "yourstoragecontainername"
#Provide the key of the storage account where you want to copy snapshot.
$storageAccountKey = 'yourStorageAccountKey'
#Provide the name of the VHD file to which snapshot will be copied.
$destinationVHDFileName = "yourvhdfilename"
# Set the context to the subscription Id where Snapshot is created
Select-AzureRmSubscription -SubscriptionId $SubscriptionId
#Generate the SAS for the snapshot
$sas = Grant-AzureRmSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName -DurationInSecond $sasExpiryDuration -Access Read
#Create the context for the storage account which will be used to copy snapshot to the storage account
$destinationContext = New-AzureStorageContext –StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
#Copy the snapshot to the storage account
Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName
#Monitor status
Get-AzureStorageBlobCopyState -Context $destinationContext -Blob $destinationVHDFileName -Container $storageContainerName
More information about it, please refer to this link.
You can simple use azure site recovery and add azure2azure service and replicate you vm's into other cross regions, this will not restart the v, it will install the azure site recovery software inside the vm thats need to be replicated, and this will begain the replication, note in order to faster replicate the vm do use premium managed disks.
Note: If you are replicating something like East US 2 to North Europe, this will not be supported, there is a whole documentation which stats what regions are supported for replication. This is a good method if you want less downtime to copy a managed disks across regions.
There is no need to take snapshots if you are following this method.
Please do let me know if you have any other queries.
I ran sysprep artifact on my VM in DevTest lab using az lab vm apply-artifacts
command.
After that, when I run az lab vm show, I get back a computeId, which contains the resource id
compute ID looks like : "computeId": "/subscriptions/#####/resourceGroups/###/providers/Microsoft.Compute/virtualMachines/####".
How do I get the disk path from this. I am more interested in the SAS key, which I can use in AzCopy to download the vhd file associated with this VM.
For now, Azure does not support use Azcopy to download the VHD from devtest lab.
As a workaround, we can create custom image from this VM (create a snapshot), then use PowerShell to copy this snapshot to another storage account via Azure PowerShell.
Then we can use this PowerShell to copy this snapshot, Here are the script:
#Provide the subscription Id of the subscription where snapshot is created
$subscriptionId = "yourSubscriptionId"
#Provide the name of your resource group where snapshot is created
$resourceGroupName ="yourResourceGroupName"
#Provide the snapshot name
$snapshotName = "yourSnapshotName"
#Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600.
#Know more about SAS here: https://learn.microsoft.com/en-us/azure/storage/storage-dotnet-shared-access-signature-part-1
$sasExpiryDuration = "3600"
#Provide storage account name where you want to copy the snapshot.
$storageAccountName = "yourstorageaccountName"
#Name of the storage container where the downloaded snapshot will be stored
$storageContainerName = "yourstoragecontainername"
#Provide the key of the storage account where you want to copy snapshot.
$storageAccountKey = 'yourStorageAccountKey'
#Provide the name of the VHD file to which snapshot will be copied.
$destinationVHDFileName = "yourvhdfilename"
# Set the context to the subscription Id where Snapshot is created
Select-AzureRmSubscription -SubscriptionId $SubscriptionId
#Get the snapshot using name and resource group
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName
#Generate the SAS for the snapshot
$sas = Grant-AzureRmSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName -DurationInSecond $sasExpiryDuration -Access Read
#Create the context for the storage account which will be used to copy snapshot to the storage account
$destinationContext = New-AzureStorageContext –StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
#Copy the snapshot to the storage account
Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName
More information about this script, please refer to this link.
Update:
We can via Azure portal to create image, like this:
Would it be possible to access the blob in Azure managed disks? If say ,I needed to copy it to another storage account(regular storage account). Since managed storage only support LRS at the moment.
If say ,I needed to copy it to another storage account(regular storage
account).
You should understand the difference between managed disks and
unmanaged disks. With unmanaged disks, you had to create storage
accounts to hold the disks (VHD files) for your Azure VMs. When
scaling up, you had to make sure you created additional storage
accounts so you didn’t exceed the IOPS limit for storage with any of
your disks. With Managed Disks handling storage, you are no longer
limited by the storage account limits (such as 20,000 IOPS / account).
You also no longer have to copy your custom images (VHD files) to
multiple storage accounts. You can manage them in a central location –
one storage account per Azure region – and use them to create hundreds
of VMs in a subscription. More information please refer to this
link.
Update:
You could copy managed disk to your private storage account by using the following cmdlets.
$sas = Grant-AzureRmDiskAccess -ResourceGroupName shui -DiskName shuitest -DurationInSecond 3600 -Access Read
$destContext = New-AzureStorageContext –StorageAccountName contosostorageav1 -StorageAccountKey 'YourStorageAccountKey'
Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer 'vhds' -DestContext $destContext -DestBlob 'MyDestinationBlobName.vhd'
You can't copy to a regular storage account, but you can create copies of it to any location you want. Let's suppose the disk is in "eastus" and you want a copy in "brazilsouth"
Get disk:
$disk = Get-AzureRmDisk -ResourceGroupName $rgName -DiskName $diskName
Make a copy config to another location:
$location = "brazilsouth"
$snapshot = New-AzureRmSnapshotConfig -SourceUri $disk.Id -CreateOption Copy -Location $location
Create a snapshot:
New-AzureRmSnapshot -Snapshot $snapshot -SnapshotName $newDiskName -ResourceGroupName $rgName
All done! This way you can keep a secondary copy in another datacenter location.