How to detach azure VMSS OS disk

Gopi CB 0 Reputation points
2023-11-07T09:44:12.9+00:00

We tried to update OS 18.04 to OS 20.04, but after that, the Linux VM got a grub file that was not found and it was not able to take the serial console of the machine, so any one update how to detach the Azure VMSS OS disk (unmanaged disk) and attach it to the new VM to fix the issue?

Azure Virtual Machine Scale Sets
Azure Virtual Machine Scale Sets
Azure compute resources that are used to create and manage groups of heterogeneous load-balanced virtual machines.
348 questions
{count} votes

1 answer

Sort by: Most helpful
  1. vipullag-MSFT 24,206 Reputation points Microsoft Employee
    2023-11-14T07:17:06.9366667+00:00

    Hello Gopi CB

    Welcome to Microsoft Q&A Platform, thanks for posting your query here.

    Please note that this process involves deleting all the VM instances in the VMSS, so make sure to take a backup of any important data before proceeding.

    To detach the OS disk from an Azure VM Scale Set (VMSS), you can follow the below steps:

    -Deallocate all the VM instances in the VMSS by running the following command:

    az vmss deallocate --resource-group <resource-group-name> --name <vmss-name>

    -Update the VMSS model to remove the OS disk by running the following command:

    az vmss update --resource-group <resource-group-name> --name <vmss-name> --set virtualMachineProfile.storageProfile.osDisk.managedDisk.id=''

    This command removes the managed disk ID from the VMSS model, which effectively detaches the OS disk from the VMSS.

    -Delete the VMSS instances by running the following command:

    az vmss delete-instances --resource-group <resource-group-name> --name <vmss-name> --instance-ids *

    This command deletes all the VM instances in the VMSS.

    -Create a new VM using the detached OS disk by running the following command:

    az vm create --resource-group <resource-group-name> --name <new-vm-name> --attach-os-disk <detached-os-disk-id> --os-type linux

    This command creates a new VM using the detached OS disk.

    -Once the new VM is created, you can connect to it and fix the grub file issue.

    After fixing the issue, you can create a new VMSS using the fixed OS disk by running the following command:

    az vmss create --resource-group <resource-group-name> --name <new-vmss-name> --image "" --os-disk-name <fixed-os-disk-name> --storage-sku Standard_LRS --instance-count <instance-count> --upgrade-policy-mode Automatic --admin-username <admin-username> --ssh-key-value "<ssh-public-key>"

    This command creates a new VMSS using the fixed OS disk.

    Hope this helps.
    I used AI provided by ChatGPT to formulate this response. Hope this resolves your Query !!

    0 comments No comments