I would like to override a volume with a different volume on the vm at the time of bootup.

Rishabh Srivastava 20 Reputation points
2023-12-08T13:39:32.8966667+00:00

I would like to override a volume of a vm with a different volume on the vm at the time of bootup.
Right now first I delete the existing volume and then I try to attach the new volume. Is there any other way that azure recommends?

snapshot = a.compute_client.snapshots.get(resource_group_name=a.rg_name, snapshot_name='snap_db')
creation_data = CreationData(create_option=DiskCreateOption.copy, source_resource_id='/subscriptions/snap_db')
disk = Disk(location='eastus2', creation_data=creation_data, tags=set_tags ,zones=['1'], sku={"name": 'StandardSSD_LRS'})
created_disk = a.compute_client.disks.create_or_update(resource_group_name=a.rg_name,disk_name='snap_db_vol", disk=disk)
vm = a.compute_client.virtual_machines.get(a.rg_name, 'snap_host')
data_disk = {
    'lun': 12,  
    'create_option': DiskCreateOption.attach,
    'managed_disk': {
        'id': disk.id
    }
}
a.compute_client.virtual_machines.create_or_update(a.rg_name, 'snap_host', vm)
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,874 questions
Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
631 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.