0

I am using PowerShell ISE. When I run Add-AzureDisk I get a CLI wizard and fill in the DiskName and I have the vhd file uri in my clipboard (copied from the portal) When I use the uri without "..." I get:

Add-AzureDisk : Invalid URI: cannot parse the hostname.

At line:1 char:1

  • Add-AzureDisk
  • ~~~~~~~~~~~~~
    • CategoryInfo : NotSpecified: (:) [Add-AzureDisk], UriFormatException
    • FullyQualifiedErrorId : System.UriFormatException,Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.AddAzureDisk Command

When I do use the "uri here" I get:

Add-AzureDisk : Invalid URI: URI-scheme is invalid. At line:1 char:1

I used this button:

enter image description here

I started to think that my powershell modules are out of date or something, so I ran Get-Module AzureRm.Profile -ListAvailable as suggested here:

Directory: C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager

ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 4.0.0 AzureRM.Profile {Disable-AzureRmDataCollection, Disable-AzureRmContextAutosave,...

But I also have v5 (found this on the docs website):

Get-Module -ListAvailable -Name AzureRm.Resources | Select Version

Version

5.0.0

As you might have guessed, I am more used to the webportal. But I am trying to create a new vm with two unmanaged disks vhd's which are in my blob storage container.

Edit I tried the Azure CLI:

az vm create -n "tmp-vm" -g "resource-tmp" --attach-os-disk "https://the-uri-copied-from-ui.blob.core.windows.net/vhd-container/vm-osdisk.vhd" --size Standard_DS1_v2 --use-unmanaged-disk --os-type windows

and got:

At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details. 
{
  "status": "Failed",
  "error": {
    "code": "ResourceDeploymentFailure",
    "message": "The resource operation completed with terminal provisioning state 'Failed'.",
    "details": [
      {
        "code": "DiskBlobPendingCopyOperation",
        "message": "Disk blob https://the-uri-copied-from-ui.blob.core.windows.net/vhd-container/vm-osdisk.vhd is not ready. Copy state: Failed. Please retry when the blob is ready."
      }
    ]
  }
}  Correlation ID: 0e1231a9-aa0e-4d79-8953-92ea43c658eb

I created the vhd with the powershell commands that I have found here: https://stackoverflow.com/a/45569760/169714 perhaps that failed? I did not got an error or anything? How can I consolidate it?

edit2 I tried both templates and had a hard time getting the debug info. But I have found the error now. And it is the same as before:

enter image description here

The blob seems to have the expected size. The lease state says available. Last modified date is a second ago, so does that mean that the underlying storing is still in process? I tried to run Get-AzureStorageBlobCopyState -Blob tmpvmosdisk.vhd -Container vhd-containers -WaitForComplete but that gives an error about a non required (and unknown to me) argument: Get-AzureStorageBlobCopyState : Could not get the storage context. Please pass in a storage context or set the current storage context.

edit 3 data disk seems flushed again. It was 512gb and is now back to zero? enter image description here

so I got the not ready message again when I wanted to add the vhd as disk...

JP Hellemons
  • 5,977
  • 11
  • 63
  • 128
  • If you want to add a data disk to an Azure VM use: Add-AzureDataDisk Reference: https://learn.microsoft.com/en-us/powershell/module/azure/add-azuredatadisk?view=azuresmps-4.0.0 – Vikranth S Feb 13 '18 at 15:07
  • It's not just a data disk. It's primary the OS disk because I do not want managed disks but the cheaper unmanaged disks. So I stored a snapshot (I think/hope) in a blob container and want to create a vm with that. – JP Hellemons Feb 13 '18 at 15:10

2 Answers2

1

I can highlight multiple issues, i will try to answer all as best as i can.

First, Add Add-AzureDisk is a ASM (Classic Deployment) command but you are mentioning AzureRM Module. Is it an ARM or ASM deployment?

Second, you CLI is ARM deployment, that failed because you copied the VHD and the copy operation is not yet done so you cannot used the VHD. You should be able use the az storage blob show command to validate the VHD copy/move is completed before using VHD.

Hope this helps.

Hannel
  • 1,656
  • 3
  • 10
  • 17
1

As Hannel said, Add-AzureDisk is a classic command. You could not use it to create a ARM mode VM.

--attach-os-disk it requires a managed disk, now, you give a unmanaged disk(VHD), so, you get the error log. See this link.

According to your scenario, the easy way is to create VM with a template. You could use this template:Create a Virtual Machine from a User Image.

If you have existing VNet, you also could use this template.

Shui shengbao
  • 18,746
  • 3
  • 27
  • 45
  • Hi, does the template work for you? If you really want to use Power Shell to create a VM, you could use Power Shell in this [template](https://github.com/Azure/azure-quickstart-templates/tree/master/101-vm-from-user-image). – Shui shengbao Feb 14 '18 at 09:05
  • So the Azure CLI is ARM mode and cannot create a VM using unmanaged disks? So I need ASM and therefor the powershell (template) to use add-azuredisk to use a vhd and create an unmanaged disk? – JP Hellemons Feb 14 '18 at 10:34
  • But I think template could do it more easily. – Shui shengbao Feb 14 '18 at 10:38
  • Will try the template. But I have found why my blob was not ready... https://imgur.com/a/6sl2o So I have to retry creating the vhd – JP Hellemons Feb 14 '18 at 10:41
  • Yes, your VHD is 0. You need do it again. – Shui shengbao Feb 14 '18 at 10:43
  • My vhd's are now several gb's but when I run the template I got: https://imgur.com/a/QBajB which is hard to debug... – JP Hellemons Feb 14 '18 at 11:29
  • Your VHD has some issues. – Shui shengbao Feb 14 '18 at 11:57
  • How do you prepare this VHD? – Shui shengbao Feb 14 '18 at 12:04
  • These 3 lines of powershell https://stackoverflow.com/a/45569760/169714 – JP Hellemons Feb 14 '18 at 12:34
  • I will test it in my lad. Sorry I am not at office, I will work at Friday, I will update my answer. But I suggest you should check the size firstly. – Shui shengbao Feb 14 '18 at 12:47
  • Never mind. It worked. Took some time to fill the vhd. The total size was correct, but in the details I could see that there was still some data updating done in the background. – JP Hellemons Feb 14 '18 at 12:58
  • I know, but I have updated the question. Because the issue is related to the vhd creation. It creates and is 512gb in an instance. But when I reopen the details. I can see in the last modified that it is still being copied over. When it's done, I try to add the disk. but somehow without an error the vhd is 0 bytes again. it's driving me crazy. no log or whatsoever... – JP Hellemons Feb 14 '18 at 14:37
  • @JPHellemons Jason's answer should work for you. A managed disk largest size is 1TB. If possible, I suggest you could use more copy time.`$sas = Grant-AzureRmDiskAccess -ResourceGroupName "[ResourceGroupName]" -DiskName "[ManagedDiskName]" -DurationInSecond 7200 -Access Read ` – Shui shengbao Feb 16 '18 at 05:49