I have two attached disks to my Azure VM. One needs to de deleted, other contains database :)
How to determine what is my target drive? oO
Official documentation says "check before detach".. Ok - How?!.. The only thing they show there is how to get OS disk, but the other two disks does not contain OS.
I know how to find OS the disk, but is not needed in my case:
# Get storage account name
$myServiceName = "bla"
$myVMname = "bla"
# Get Virtual machine
$vm = Get-AzureVM -ServiceName $myServiceName -Name $myVMname
# Get storage account name and path to vhd
$vmOSDisk = $vm | Get-AzureOSDisk;
This command does not tell me anything useful either:
Get-AzureDisk | Get-AzureDisk | Format-list DiskName, AttachedTo, DiskSizeInGB, OS
I tried to shrink volume to view the changes in powershell but it doesn't work.
upd.: Unfortunately there is Win Server 2008 R2, it does not support 'get-disk'. But I can use other function instead
$drive = gwmi Win32_DiskPartition
$drive
I can use something from
Win32_LogicalDisk Win32_MappedLogicalDisk Win32_DiskPartition Win32_DiskDrive Win32_LogicalDiskRootDirectory Win32_DiskQuota Win32_LogonSessionMappedDisk Win32_LogicalDiskToPartition Win32_DiskDrivePhysicalMedia Win32_DiskDriveToDiskPartition Win32_OfflineFilesDiskSpaceLimit
instead, but if I understand correctly it is not necessary. What means is order in Disk Manager? So disks added after D:\ will get LUN numbers beginning from zero?
So I succesfully deleted first volume, being of opinion that E has LUN zero, and H has 1
When you attach a disk to an Azure VM a LUN (Logical Unit Number) must be associated with it. If you attach via the portal it may default this number, but the number must be unique to each disk. Values can be 0-15 because the max number of data disks you can attach is 16. Figuring out the LUN is the key to determining which drive is which.
First, remote into the target machine and run the following PowerShell:
get-disk | format-list number, path
This will output the list of drives with their drive number (slot) and a path. For the data disks the path will look something like:
\?\scsi#disk&ven_msft&prod_virtual_disk#000001#{57f56307-b6bf-19d0-94f2-00a0c91efb8b}
Note specifically the disk#000001# bit. As far as I can tell the number there matches the LUN. In this case it's saying it's LUN 1.
Look at the Disk Management screen for the drive you want to drop and note the Disk Number on the left hand side. Match that with the number returned from the above command to find the LUN number, then you can match the LUN of the drive you want to drop.
Next, From the machine you are running your Azure PowerShell cmdlets form do the following:
get-azurevm iaasdiag | Get-AzureDataDisk | ft MediaLink, Lun
This will pull back the name of the disks in storage and the LUN value.
This should give you the mapping of a disk on the remote machine to the disk in storage.
I think there is likely a way to get at the LUN better in PowerShell, but I didn't look past this. I did a little testing and it seemed to prove out.
NOTE: This type of matching is likely the work of some inner workings of the storage system in Azure. While it may work now, it may also change in the future without notice. It would be nice if they had a better way to determine this.