How to add a disk and file share in Azure with powershell commands

How to add a disk and file share in Azure with powershell commands

Tempo de leitura: 4 minutos

Hi lads,

This blog post will teach you how you should do to add a new virtual managed disk to your VM and how to create a file share that is going to be used to transfer SQL server backups from on-prem to the Azure.

By continuing our last post, let’s assume after you have created the virtual machine, you need to add a managed disk to be used along with your computing. Moreover, your CEO asked you to move the SQL server backups from production to this new VM once the CEO’s aim is to start testing its workload in Azure.

Long story short, we will do the following:

  • Add a managed disk into your SQLVM01 (previously created on the last blog post)
  • Create a new file share and present it to the VM

This next code block is related to create a new managed disk with 20GB in size and an empty one. After defining the configs for the disk, I will attach it into the VM and up to date the VM as the following:

For this demo I named this disk as “MyDisk”, but it might be an input parameter within that .CSV file showed on the last post blog in the case where you should create a lot of virtual machines.

Once you have created this, go to the Azure portal and the disks will be there on virtual machine properties

Now we are going to create the Azure File share to be used to copy files from on-prem to VM in azure.

Before creating an Azure File Share, you must create a storage account, this command will create a storage account for you with some input parameters (referral to the documentation to learn further about that)

Once it’s done, you should get the storage account parameters (account name, resource group, key, and so on) to be able to proceed to create your file share

When the above command runs you will see something like that at your command prompt

If you want to make ensure that your file share has been created, got to the Azure portal and look at into your resource group

Now we need to log in to our VM in azure and run a command to ensure the file share will be available within our VM, before doing that make sure you haven’t closed yet your power shell command prompt and re-run the $StgKeyValue variable there to get the key back (if you closed it, no problem you can get this value from the azure portal in storage account properties). Copy it over and to be reused later

Go to the VM in azure and connect

When you log into the machine, run these commands to make the managed disk and file share available to be used.

PS – If you want to automatize all these steps, you could create an extension to be carried out when your machine starts, this is out of scope for this blog post, but, look at this article.

https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/features-windows

When you run these scripts, you will have the disk and file share ready to be used as below

References

https://docs.microsoft.com/en-us/azure/virtual-machines/managed-disks-overview

https://docs.microsoft.com/en-us/azure/storage/files/storage-files-introduction

See you next post! TC

Deixe uma resposta

%d blogueiros gostam disto: