Shared Storage in Azure is backed by SMB Protocol which, in turn, is a Network File Sharing protocol. SMB stands for Server Message Block. The latest version of SMB protocol is 3.0 at the time I am writing this article.
Shared Storage in Azure treats the storage as a disk. The most common uses of SMB file shares include storing diagnostic data, storing shared application data, storing tools and utilities, and migrating on-premise applications using File share.
SMB File Shares allows your Azure Storage to act as a file repository.
Step 1
Open Azure Portal >> Select Resource Group - You can see this in my Resource Group I already have a Virtual Machine.
So first, provision one Azure VM in the resource group where you are going to create Shared Storage. You can visit my article Create Azure VM with PowerShell or Create Azure VM with Azure CLI.
Step 2
Create Storage Account. So in the resource group, click Add, select Storage Account, and click "Create".
Step 3
Now, provide all the necessary information, such as Storage Account Name. The storage account kind is general purpose (v1) and replication is Locally-Redundant Storage.
Here, I have selected the existing resource group and clicked "Create".
Step 4
Once the Storage Account is created, go to your storage account and click on "Files" to create a File Share.
Step 5
Click "File Share".
Step 6
Now here, I must provide the File Share name and if you want, you can set quota. I have set the quota limit to 5 GB here.
Step 7
Now, click on the File Share you have created and click on the Add Directory. However, you can directly upload the data but it is better to be organized.
Step 8
So here, you can see that I have created around 4 directories - Microsoft Azure, JavaScript Framework and Libraries, Dot Net Framework, SharePoint Server and O365.
Now, I have selected Microsoft Azure Directory and uploaded around 4 files.
In the same way, inside my JavaScript Frameworks and Libraries folder, I have uploaded 3 more files.
Here, I have created only one file share called coursecontent but the same way, you can create multiple file shares and each file share can have multiple directories.
Keep in mind that you can have multiple files inside a File Share but you are restricted to the capacity of 5 TB and the maximum file size is 1 TB.
Now, we will try to connect the Virtual Machine to it. Again, a point to remember here is that your virtual machine should be in the same resource group where your file share resides.
We can have multiple virtual machines connecting to a single File Share.
Before we try to connect our VM to the File Share, we must have our access keys handy.
Step 9
Go to your storage account >> click on Access Keys and copy the first key.
Step 10 - Launch your VM.
Go to your Resource Group >> Select VM and click on "Create". If you do not have any VM created, you can create a simple VM with Windows Server OS. You can refer my other articles to create a VM.
Step 11 - Mount SMB File Share to Azure VM.
Once we are logged in to the VM, we will mount our SMB File Share to this VM. Same steps you can perform to mount the SMB file share to another VM.
Now inside the VM, open PowerShell ISE.
Step 12
Go to your File Share and copy the path of your File Share as shown below.
Step 13 - persist your VM credentials with cmdkey.
Now, we will use cmdkey cmdlet to persist our credentials. So, after the reboot of your VM, you don’t need to re-enter the credentials to mount your File Share.
Command :
cmdkey /add:smbstorageacc.file.core.windows.net /user: smbstorageacc /pass: 5e695JE4jtMBPHfNQglaPFZoH9BnHeBHBH9FZqmG1l7HoAgeQXE39ZLWSxNTgGqXeaClUQMR0pXIl1DKIYfZkw==
Here, first, we define URL of our storage account in the add parameter (add:smbstorageacc.file.core.windows.net ), then user parameter holds my storage account name (smbstorageacc) and pass parameter contains the access key for the storage account pass:
5e695JE4jtMBPHfNQglaPFZoH9BnHeBHBH9FZqmG1l7HoAgeQXE39ZLWSxNTgGqXeaClUQMR0pXIl1DKIYfZkw==
You can see as a result, the credentials would be added successfully.
So, after reboot, our shared drive would be always mounted.
Step 14 - Mount share dirve using net use command.
Now, we will mount our Shared Drive. We will use net use command followed by the drive letter which connects to the storage account\file share name.
Command : net use k: \\smbstorageacc.file.core.windows.net\coursecontents
Step 15 - Check the output.
Now, if you go to Windows Explorer, you can see that your File Share is mounted.
If you dig into that, you can see all the directories and within Microsoft Azure directory, you will get the files too.
Now, right-click and add a new text document to Microsoft Azure Directory.
In the same way, if you have multiple VMs connected with the Azure File Share, the VMs can share files , .exes, tools and softwares. They all can write in the same log files etc…
The only thing to keep in mind is that your VMs and File Share must be in the same Resource Group.