Can I upgrade a managed disk used by an Azure VM without having to redeploy the VM?
I'm trying to convert a separate managed disk I added to my Windows 2019 Server VM from Standard SSD to a Premium SSD. According to the steps at https://docs.microsoft.com/bs-latn-ba/Azure/virtual-machines/windows/convert-disk-storage, I'll have to stop the VM to perform this--but I'm afraid that if I stop it, there will be a ripple effect that will delay my team's ability to get back online and keep working right away. One specific scenario I'm trying to avoid is a mandatory redeployment of the VM.
See, I have third-party software running on this Azure VM and its software licensing module (SLM) might need to be reset/reinitialized if the VM gets redeployed. That re-initialization can be a lengthy process because I've got to get on the phone with tech support, request the help, get rerouted who knows how many times, and wait for the reissued license, apply the new license, and test that everything is back to normal. It's something I'm trying to avoid because it might make my team lose a day's worth of work while I get the software manufacturer to reissue/reconfigure my SLM. The SLM relies on the CPUID and MAC ID of its host computer. Since a redeployment implies that the virtual machine may get deployed on a different physical piece of hardware, I would most likely need the SLM reset. I don't want that.
So my questions are,
If I shut down the VM for maintenance (such as upgrading an external managed disk from Standard SSD to Premium SSD, for instance), will that force a redeploy?
Is a shut down effectively the same as hitting Stop for that VM on the Azure portal?
I hear there's a Stop and a separate Stop/Redeploy option, but if so, I don't immediately see that. Is that Redeploy an option I'll see after I hit Stop?
Solution 1:
Eureka! I managed to upgrade my managed data disk without having to redeploy the VM! According to the Azure web portal, "Disks can be resized or account type changed only when they are unattached or the owner VM is deallocated." It seemed that if I could unattach/detach the managed disk in question, I could be home free without requiring a stop and deallocation of the VM! In fact, this was so.
I learned that, "You can hot remove a data disk using PowerShell, but make sure nothing is actively using the disk before detaching it from the VM." (Source: see my hyperlink #3 at bottom of this post.) Therefore, I went ahead and stopped my third-party services that depended on that disk, left the VM running, and from my own local PC I performed all the steps I record here.
I will detail further below the custom PowerShell commands I executed (as recorded from my Windows PowerShell ISE user interface, with results embedded, in what I call Phases 1, 2, and 4). I also needed to use the Azure web portal (in what I call Phase 3).
All this WORKED! Note again that I executed my solution in four phases. In brief, they are:
PHASE 1: This was done using PowerShell. Initially, up to the Connect-AzAccount command, what you'll see are preparatory steps that installed the necessary Azure PowerShell modules and set my PC up to allow script execution. I had to click Yes or Yes To All a few times to complete module installations
PHASE 2: Still using PowerShell. Here's where I had to enter my Azure portal credentials when I ran Connect-AzAccount. Basically, I then detach the disk while the VM is still running. That happens at the Remove-AzVMDataDisk command and the Update-AzVM that immediately follows it.
PHASE 3: At that point, I went back to my Azure web portal and I changed my managed data disk from Standard to Premium SSD.
PHASE 4: Finally, I came back to my PowerShell screen and proceeded to perform the steps that led up to the Add-AzVMDataDisk command to reattach my disk to the VM--and the subsequent Update-AzVM that sets that in motion. That brought the upgraded managed disk drive back to life on my VM!
What's even better, all the data was kept intact, the drive letter I had assigned it before was retained, and even the network share name I had given it was still accessible to other VMs via my virtual network!
(Note that in Phase 4, I also performed an additional step to hopefully get optimal Premium SSD performance with a read/write cache: that's the command, 'Set-AzVMDataDisk -VM $VM -Lun "0" -Caching ReadWrite'.)
Now, please observe all the detailed steps I took in PowerShell and what I did in the Azure web portal:
PHASE 1
PS C:\WINDOWS\system32> Install-Module -Name Az -AllowClobber
PS C:\WINDOWS\system32> Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Undefined
PS C:\WINDOWS\system32> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
PS C:\WINDOWS\system32> Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser RemoteSigned
LocalMachine Undefined
PHASE 2
PS C:\WINDOWS\system32> Connect-AzAccount
Account SubscriptionName TenantId
------- ---------------- --------
[email protected] Microsoft Azure (MYCOMPANY): #0000000 ffffff...
PS C:\WINDOWS\system32> $VirtualMachine = Get-AzVM -ResourceGroupName "MYFILESERVERRESOURCES" -Name "MyFileServer"
PS C:\WINDOWS\system32> Remove-AzVMDataDisk -VM $VirtualMachine -Name "MyStorageDrive"
ResourceGroupName : MYFILESERVERRESOURCES
Id : /subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resour
ceGroups/MYFILESERVERRESOURCES/providers/Microsoft.Compute/virtualMachines/MY
FileServer
VmId : eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee
Name : MyFileServer
Type : Microsoft.Compute/virtualMachines
Location : eastus
Tags : {}
DiagnosticsProfile : {BootDiagnostics}
Extensions : {AzureDiskEncryption, AzurePerformanceDiagnostics,
MicrosoftMonitoringAgent}
HardwareProfile : {VmSize}
NetworkProfile : {NetworkInterfaces}
OSProfile : {ComputerName, AdminUsername, WindowsConfiguration,
Secrets, AllowExtensionOperations}
ProvisioningState : Succeeded
StorageProfile : {ImageReference, OsDisk, DataDisks}
PS C:\WINDOWS\system32> Update-AzVM -ResourceGroupName "MYFILESERVERRESOURCES" -VM $VirtualMachine
RequestId IsSuccessStatusCode StatusCode ReasonPhrase
--------- ------------------- ---------- ------------
True OK OK
PHASE 3
Here is where I went back to the Azure portal and changed the drive from Standard SSD to Premium SSD and saved that change! To do so, I,
- Signed in to the Azure portal.
- Selected the MyFileServer from the list of Virtual Machines in the portal.
- I noticed my VM status showed it was still, "Running."
- In the pane for the VM, I selected Disks from the menu.
- I selected the disk that I wanted to convert, MyStorageDrive.
- I selected Configuration from the menu.
- I changed the Account type from Standard HDD to Premium SSD (this was impossible before as it was disabled until I detached the disk).
- I clicked Save, and closed the disk pane.
The disk conversion was literally instantaneous.
PHASE 4
PS C:\WINDOWS\system32> $rgName = "MYFILESERVERRESOURCES"
$vmName = "MyFileServer"
$location = "East US"
$dataDiskName = "MyStorageDrive"
$disk = Get-AzDisk -ResourceGroupName $rgName -DiskName $dataDiskName
PS C:\WINDOWS\system32> $vm = Get-AzVM -Name $vmName -ResourceGroupName $rgName
PS C:\WINDOWS\system32> $vm = Add-AzVMDataDisk -CreateOption Attach -Lun 0 -VM $vm -ManagedDiskId $disk.Id
PS C:\WINDOWS\system32> Update-AzVM -VM $vm -ResourceGroupName $rgName
RequestId IsSuccessStatusCode StatusCode ReasonPhrase
--------- ------------------- ---------- ------------
True OK OK
PS C:\WINDOWS\system32> $VM.StorageProfile.OsDisk.Caching
ReadWrite
PS C:\WINDOWS\system32> $vm.StorageProfile.DataDisks
Name :
DiskSizeGB :
Lun : 0
Caching : None
CreateOption : Attach
SourceImage :
VirtualHardDisk :
PS C:\WINDOWS\system32> Set-AzVMDataDisk -VM $VM -Lun "0" -Caching ReadWrite
ResourceGroupName : MYFILESERVERRESOURCES
Id : /subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/MYFILESERVERRESOURCES/providers
/Microsoft.Compute/virtualMachines/MyFileServer
VmId : eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee
Name : MyFileServer
Type : Microsoft.Compute/virtualMachines
Location : eastus
Tags : {}
DiagnosticsProfile : {BootDiagnostics}
Extensions : {AzureDiskEncryption, AzurePerformanceDiagnostics, MicrosoftMonitoringAgent}
HardwareProfile : {VmSize}
NetworkProfile : {NetworkInterfaces}
OSProfile : {ComputerName, AdminUsername, WindowsConfiguration, Secrets, AllowExtensionOperations}
ProvisioningState : Succeeded
StorageProfile : {ImageReference, OsDisk, DataDisks}
PS C:\WINDOWS\system32> Update-AzVM -VM $vm -ResourceGroupName $rgName
RequestId IsSuccessStatusCode StatusCode ReasonPhrase
--------- ------------------- ---------- ------------
True OK OK
PS C:\WINDOWS\system32>
These are the websites that helped me arrive at this solution:
1 https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-6
2 https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-2.5.0
3 https://docs.microsoft.com/en-us/azure/virtual-machines/windows/detach-disk
4 https://docs.microsoft.com/bs-latn-ba/Azure/virtual-machines/windows/convert-disk-storage
5 https://docs.microsoft.com/en-us/azure/virtual-machines/windows/attach-disk-ps
6 https://docs.microsoft.com/en-us/learn/modules/caching-and-performance-azure-storage-and-disks/6-exercise-manage-cache-settings-with-powershell