Overview and What You Will Learn
Azure Files provides fully managed file shares that many machines can mount at the same time over the standard SMB or NFS protocols, just like a traditional network drive. In this lab, you will create a share, mount it over SMB on two Linux VMs, write a file from one VM, and confirm the other VM sees the same file.
Why This Matters in Production
A shared mount gives every server one authoritative copy of the files they all need. An engineering team at Swiggy might have several application servers reading the same configuration files, and copying those files onto each VM's local disk is error-prone. One server gets the update, another does not, and the two start behaving differently. Azure Files gives every VM a single location to read and write.
Core Principles
A file share lives inside a storage account, not on any single VM, so it outlives the machines that mount it. Existing applications that expect a mapped drive usually need no code changes, because SMB is the same protocol an on-premises file server uses.
writes config] -->|SMB 445| S[(Azure Files share
shared-configs)] B[VM B
reads config] -->|SMB 445| S S --- ACC[Storage account
stfileslabrahul2026] classDef vm fill:#326CE5,color:#FFFFFF classDef share fill:#10B981,color:#FFFFFF classDef acct fill:#475569,color:#FFFFFF class A,B vm class S share class ACC acct
Choose the storage type by how it will be accessed:
| Option | Mounted by many VMs? | Access method |
|---|---|---|
| Azure Files | Yes | SMB or NFS |
| Blob Storage | Only via BlobFuse or NFS 3.0 | REST object API |
| Managed Disk | One VM by default | Block device |
RememberSMB uses TCP port 445. Azure VMs can reach it freely, but many home and corporate networks block outbound 445, so mounting from outside Azure needs a VPN, ExpressRoute, or Azure File Sync.
Detailed Step-by-Step Practical Lab
How to Create the Storage Account and File Share
Storage account names are globally unique, so change the suffix if yours is taken. The share is created through Azure Resource Manager, so no key is needed for this step.
export RG="rg-files-lab-mumbai"export SA="stfileslabrahul2026" az group create --name $RG --location centralindia az storage account create \ --name $SA \ --resource-group $RG \ --location centralindia \ --sku Standard_LRS \ --min-tls-version TLS1_2 az storage share-rm create \ --storage-account $SA \ --resource-group $RG \ --name shared-configs \ --quota 10How to Create Two Linux VMs
The mount commands run on VMs, so create two small ones. The --nsg-rule NONE flag skips the default SSH rule, because you will drive the VMs with az vm run-command and never need inbound access.
for n in a b; do az vm create \ --resource-group $RG \ --name vm-files-$n \ --image Ubuntu2204 \ --size Standard_B1s \ --admin-username azureadmin \ --generate-ssh-keys \ --nsg-rule NONE \ --output nonedoneHow to Mount an Azure Files Share over SMB
Fetch the storage account key and build a mount script. The script stores the credentials in a root-only file, so the key does not appear on the mount command line.
KEY=$(az storage account keys list \ --account-name $SA \ --resource-group $RG \ --query "[0].value" --output tsv) MOUNT_SCRIPT="cloud-init status --wait || trueapt-get update -y && apt-get install -y cifs-utilsmkdir -p /mnt/shared-configs /etc/smbcredentialsprintf 'username=$SA\npassword=$KEY\n' > /etc/smbcredentials/$SA.credchmod 600 /etc/smbcredentials/$SA.credmount -t cifs //$SA.file.core.windows.net/shared-configs /mnt/shared-configs \ -o credentials=/etc/smbcredentials/$SA.cred,vers=3.1.1,serverino,file_mode=0664,dir_mode=0775df -h /mnt/shared-configs" for n in a b; do az vm run-command invoke \ --resource-group $RG \ --name vm-files-$n \ --command-id RunShellScript \ --scripts "$MOUNT_SCRIPT" \ --query "value[0].message" --output tsvdoneSecurity
az vm run-commandleaves the script, including the key, on the VM's disk. That is acceptable for a throwaway lab, but never do it for real servers. Use Azure Key Vault to hold the key, or switch to identity-based authentication.
How to Write From One VM and Read From Another
Write a file from VM A, then read it from VM B, which mounted the same share separately.
az vm run-command invoke \ --resource-group $RG \ --name vm-files-a \ --command-id RunShellScript \ --scripts "echo 'shared config value' | tee /mnt/shared-configs/app-config.txt" \ --query "value[0].message" --output tsv az vm run-command invoke \ --resource-group $RG \ --name vm-files-b \ --command-id RunShellScript \ --scripts "cat /mnt/shared-configs/app-config.txt" \ --query "value[0].message" --output tsvHow to Verify the File From Outside the VMs
List the share's contents directly from Cloud Shell to prove the file lives in the share, not on either VM's disk.
az storage file list \ --account-name $SA \ --account-key "$KEY" \ --share-name shared-configs \ --output tableHow to Clean Up
Deleting the resource group removes the VMs, their disks, and the storage account together.
az group delete --name $RG --yes --no-waitProduction Best Practices & Common Pitfalls
Common MistakeTrying to give many VMs shared access through Blob Storage when the requirement is a real mountable file share. Blob Storage is an object store, and Azure Files exists for exactly this shared-mount case.
TipNever put the storage key on a command line or in a script that lands in shell history. Keep it in Azure Key Vault and fetch it at mount time, and use a root-only credentials file with
chmod 600as in this lab.
- Use Azure Files for multi-reader, multi-writer data. If only one VM ever touches the data, a Managed Disk is usually simpler and cheaper.
- Mount with
vers=3.1.1orvers=3.0. SMB 3.x encrypts data in transit, and Azure rejects unencrypted mounts when secure transfer is required. - Add
nofailfor persistent mounts. When you copy this mount into/etc/fstab, includenofailso a temporary storage problem does not stop the VM from booting. - Plan the quota, but know what it costs. On Standard shares you pay for used capacity, so the quota is only a ceiling that you can raise later. On Premium shares you pay for the provisioned size instead.
- Expect a short metadata cache. Clients cache file attributes briefly, so a file written on one VM can take a moment to show up on another.
- Restrict network access. Use a private endpoint or service endpoint so only your VNet can reach the share, and prefer identity-based authentication for SMB where your setup supports it.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
az storage share-rm create |
Create a share through Resource Manager |
az storage share-rm list --storage-account NAME |
List shares on an account |
az storage account keys list |
Retrieve a key for mounting |
mount -t cifs //ACCOUNT.file.core.windows.net/SHARE /mnt/PATH |
Mount the share over SMB on Linux |
az storage file list --share-name SHARE |
List files in a share from outside the VMs |
az vm run-command invoke --command-id RunShellScript |
Run a script on a VM without SSH |