Disk is not visible in portal

Mohsin Khan 45 Reputation points
2024-07-20T13:15:23.9733333+00:00

Hello Everyone.

I am trying to add one OS disk as data disk into my vm using powershell. I am able to update the vm. after this it is not showing in portal.
are we need to add manually. I want to reduce this efforts as well. I really appreciate for quick reply.

8------------------------------------------------------------------------------------------
$rgName = "myResourceGroup"

$vmName = "RecoveryVM"

$location = "eastus"

$dataDiskName = "newOSDisk"

$disk = Get-AzDisk -ResourceGroupName $rgName -DiskName $dataDiskName

$vm = Get-AzVM -Name $vmName -ResourceGroupName $rgName

$vm = Add-AzVMDataDisk -CreateOption Attach -Lun 0 -VM $vm -ManagedDiskId $disk.Id

Update-AzVM -VM $vm -ResourceGroupName $rgName

Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
603 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,331 questions
{count} votes

2 answers

Sort by: Most helpful
  1. akinbade abiola 9,390 Reputation points
    2024-07-20T20:26:43.7766667+00:00

    possibly a LUN issue. Try adding a condition like below:

    # Find the next available LUN
    $lun = 0
    while ($vm.DataDisks.Lun -contains $lun) {
        $lun++ } 
    
    

    You can mark it 'Accept Answer' and 'Upvote' if this helped you

    Regards,

    Abiola


  2. Nehruji R 4,766 Reputation points Microsoft Vendor
    2024-07-22T11:52:06.2433333+00:00

    Hello Mohsin Khan,

    Greetings! Welcome to Microsoft Q&A Platform.

    • I understand that your script is executing correctly, but the disk isn’t appearing in the Azure portal. Please consider checking the below following factors to resolve the issue,
    • Double-check that the disk is properly attached to the VM. You can do this by running,
    $vm = Get-AzVM -ResourceGroupName $rgName -Name $vmName
    $vm.StorageProfile.DataDisks
    
    
        This command will list all data disks attached to the VM. Ensure your new disk is listed.
    
    • Sometimes, changes take a bit of time to reflect in the Azure portal. Try refreshing the portal or logging out and back in.
    • Ensure the disk is in the same resource group and region as your VM. You can verify this in the Azure portal under the disk’s properties.
    • After attaching the disk, you might need to mount it within the VM. This can be done using the following PowerShell commands:
    $vm = Get-AzVM -ResourceGroupName $rgName -Name $vmName
    $vm.StorageProfile.DataDisks | ForEach-Object {
        if ($_.Lun -eq 0) {
            $_.CreateOption = "Attach"
            $_.ManagedDisk = $disk
        }
    }
    Update-AzVM -ResourceGroupName $rgName -VM $vm
    
    

    If the disk still doesn’t show up, you might need to manually add it through the Azure portal. Go to your VM’s settings, select “Disks,” and then add the data disk from there. refer - https://learn.microsoft.com/en-us/azure/virtual-machines/windows/tutorial-manage-data-disk, https://learn.microsoft.com/en-us/azure/virtual-machines/windows/os-disk-swap.

    Hope this information helps! Please let us know if you have any further queries. I’m happy to assist you further.   


    Please "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments