Azure: Cannot specify storage account while creating a new UN - managed disk for azure.

354 views Asked by At

I am trying to create and attach an unmanaged storage disk to Azure. I am unable to specify the storage account while creating the disk.

vm.update().defineUnmanagedDataDisk(diskLabel)
                    .withNewVhd(lun)
                    .withLun(lun)
                    .withCaching(CachingTypes.NONE)
                    .attach()
                    .apply();
2

There are 2 answers

0
Jay Gong On BEST ANSWER

As mentioned in this official document:

In an unmanaged disk, you manage the storage accounts that you use to store the virtual hard disk (VHD) files that correspond to your VM disks. VHD files are stored as page blobs in Azure storage accounts.

You can follow the tutorial to upload VHD file to your Storage Account,then use .storeAt(storageAccount.name(), "diskvhds", "datadisk1vhd.vhd") to specify the storage account.Please refer to the source code from here.

 VirtualMachine virtualMachine = computeManager.virtualMachines()
                .define(VMNAME)
                .withRegion(REGION)
                .withExistingResourceGroup(RG_NAME)
                .withNewPrimaryNetwork("10.0.0.0/28")
                .withPrimaryPrivateIPAddressDynamic()
                .withoutPrimaryPublicIPAddress()
                .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
                .withRootUsername("Foo12")
                .withRootPassword("abc!@#F0orL")
                .withUnmanagedDisks()
                .defineUnmanagedDataDisk("disk1")
                    .withNewVhd(100)
                    .withLun(2)
                    .storeAt(storageAccount.name(), "diskvhds", "datadisk1vhd.vhd")
                    .attach()
                .defineUnmanagedDataDisk("disk2")
                    .withNewVhd(100)
                    .withLun(3)
                    .storeAt(storageAccount.name(), "diskvhds", "datadisk2vhd.vhd")
                    .attach()
                .withSize(VirtualMachineSizeTypes.STANDARD_DS2_V2)
                .withOSDiskCaching(CachingTypes.READ_WRITE)
                .create();

Note that .storeAt(storageAccount.name(), "diskvhds", "datadisk1vhd.vhd")

means .storeAt(<your account name>, <container name>, <blob name>)

0
Shui shengbao On

The root reason is Azure does not support attach unmanaged disk to a VM that uses managed disk.

If your VM uses managed disks, you can only attach additional managed data disks. Also, you can only attach unmanaged data disks to a VM that uses unmanaged disks in a storage account. In other words, Azure does not support attach managed disk and unmanaged disk to a VM at same time.