Tutorial: Create an SMB Azure file share and connect it to a Windows VM using the Azure portal

Azure Files offers fully managed file shares in the cloud that are accessible via the industry standard Server Message Block (SMB) protocol or Network File System (NFS) protocol. In this tutorial, you'll learn a few ways you can use an SMB Azure file share in a Windows virtual machine (VM).

If you don't have an Azure subscription, create a free account before you begin.

  • Create a storage account
  • Create a file share
  • Deploy a VM
  • Connect to the VM
  • Mount an Azure file share to your VM
  • Create and delete a share snapshot

Applies to

File share type SMB NFS
Standard file shares (GPv2), LRS/ZRS Yes No
Standard file shares (GPv2), GRS/GZRS Yes No
Premium file shares (FileStorage), LRS/ZRS Yes No

Getting started

Create a storage account

Before you can work with an Azure file share, you must create an Azure storage account.

A storage account is a shared pool of storage in which you can deploy an Azure file share or other storage resources, such as blobs or queues. A storage account can contain an unlimited number of shares. A share can store an unlimited number of files, up to the capacity limits of the storage account.

To create a storage account using the Azure portal:

  1. Under Azure services, select Storage accounts.

  2. Select + Create to create a storage account.

  3. Under Project details, select the Azure subscription in which to create the storage account. If you have only one subscription, it should be the default.

  4. If you want to create a new resource group, select Create new and enter a name such as myexamplegroup.

  5. Under Instance details, provide a name for the storage account. You might need to add a few random numbers to make it a globally unique name. A storage account name must be all lowercase and numbers, and must be between 3 and 24 characters. Make a note of your storage account name. You'll use it later.

  6. In Region, select the region you want to create your storage account in.

  7. In Performance, keep the default value of Standard.

  8. In Redundancy, select Locally redundant storage (LRS).

    Screenshot showing how to enter the project and instance details for a storage account using the Azure portal.

  9. Select Review to review your settings. Azure will run a final validation.

  10. When validation is complete, select Create. You should see a notification that deployment is in progress.

Create an Azure file share

Next, create an SMB Azure file share.

  1. When the Azure storage account deployment is complete, select Go to resource.

  2. Select File shares from the storage account pane.

    Screenshot showing how to select file shares from the storage account pane.

  3. Select + File Share.

    Screenshot showing how to create a new file share.

  4. Name the new file share qsfileshare and leave Transaction optimized selected for Tier.

  5. Select the Backup tab. By default, backup is enabled when you create an Azure file share using the Azure portal. If you want to disable backup for the file share, uncheck the Enable backup checkbox. If you want backup enabled, you can either leave the defaults or create a new Recovery Services Vault in the same region and subscription as the storage account. To create a new backup policy, select Create a new policy.

    Screenshot showing how to enable or disable file share backup.

  6. Select Review + create and then Create to create the file share.

  7. Create a new txt file called qsTestFile on your local machine.

  8. Select the new file share, then on the file share location, select Upload.

    Screenshot showing how to upload a file to the new file share.

  9. Browse to the location where you created your .txt file > select qsTestFile.txt > select Upload.

Deploy a VM

So far, you've created an Azure storage account and a file share with one file in it. Next, create an Azure VM with Windows Server 2019 Datacenter to represent the on-premises server.

  1. Expand the menu on the left side of the portal and select Create a resource in the upper left-hand corner of the Azure portal.

  2. Under Popular services select Virtual machine.

  3. In the Basics tab, under Project details, select the resource group you created earlier.

    Screenshot of the Basic tab with VM information filled out.

  4. Under Instance details, name the VM qsVM.

  5. For Security type, select Standard.

  6. For Image, select Windows Server 2019 Datacenter - x64 Gen2.

  7. Leave the default settings for Region, Availability options, and Size.

  8. Under Administrator account, add a Username and enter a Password for the VM.

  9. Under Inbound port rules, choose Allow selected ports and then select RDP (3389) and HTTP from the drop-down.

  10. Select Review + create.

  11. Select Create. Creating a new VM will take a few minutes to complete.

  12. Once your VM deployment is complete, select Go to resource.

Connect to your VM

Now that you've created the VM, connect to it so you can mount your file share.

  1. Select Connect on the virtual machine properties page.

    Screenshot of the VM tab, +Connect is highlighted.

  2. In the Connect to virtual machine page, keep the default options to connect by IP address over port number 3389 and select Download RDP file.

  3. Open the downloaded RDP file and select Connect when prompted.

  4. In the Windows Security window, select More choices and then Use a different account. Type the username as localhost\username, where <username> is the VM admin username you created for the virtual machine. Enter the password you created for the virtual machine, and then select OK.

    Screenshot of the VM log in prompt, more choices is highlighted.

  5. You may receive a certificate warning during the sign-in process. Select Yes or Continue to create the connection.

Map the Azure file share to a Windows drive

  1. In the Azure portal, navigate to the qsfileshare fileshare and select Connect.

  2. Select a drive letter and then Show script.

  3. Copy the script and paste it in Notepad.

    Screenshot that shows the contents of the box that you should copy and paste in Notepad.

  4. In the VM, open PowerShell and paste in the contents of the Notepad, then press enter to run the command. It should map the drive.

Create a share snapshot

Now that you've mapped the drive, create a snapshot.

  1. In the portal, navigate to your file share, select Snapshots, then select + Add snapshot and then OK.

    Screenshot of the storage account snapshots tab.

  2. In the VM, open the qstestfile.txt and type "this file has been modified". Save and close the file.

  3. Create another snapshot.

Browse a share snapshot

  1. On your file share, select Snapshots.

  2. On the Snapshots tab, select the first snapshot in the list.

    Screenshot of the Snapshots tab, the first snapshot is highlighted.

  3. Open that snapshot, and select qsTestFile.txt.

Restore from a snapshot

  1. From the file share snapshot tab, right-click the qsTestFile, and select the Restore button.

    Screenshot of the snapshot tab, qstestfile is selected, restore is highlighted.

  2. Select Overwrite original file and then select OK.

    Screenshot of the Restore pop up, overwrite original file is selected.

  3. In the VM, open the file. The unmodified version has been restored.

Delete a share snapshot

  1. Before you can delete a share snapshot, you'll need to remove any locks on the storage account. Navigate to the storage account you created for this tutorial and select Settings > Locks. If any locks are listed, delete them.

  2. On your file share, select Snapshots.

  3. On the Snapshots tab, select the last snapshot in the list and select Delete.

    Screenshot of the Snapshots tab, the last snapshot is selected and the delete button is highlighted.

Use a share snapshot in Windows

Just like with on-premises VSS snapshots, you can view the snapshots from your mounted Azure file share by using the Previous versions tab.

  1. In File Explorer, locate the mounted share.

    Screenshot of a mounted share in File Explorer.

  2. Select qsTestFile.txt and > right-click and select Properties from the menu.

    Screenshot of the right click menu for a selected directory.

  3. Select Previous Versions to see the list of share snapshots for this directory.

  4. Select Open to open the snapshot.

    Screenshot of the Previous versions tab.

Restore from a previous version

  1. Select Restore. This copies the contents of the entire directory recursively to the original location at the time the share snapshot was created.

    Screenshot of the Previous versions tab, the restore button in warning message is highlighted.

    Note

    If your file hasn't changed, you won't see a previous version for that file because that file is the same version as the snapshot. This is consistent with how this works on a Windows file server.

Clean up resources

When you're done, delete the resource group. Deleting the resource group deletes the storage account, the Azure file share, and any other resources deployed inside the resource group.

If there are locks on the storage account, you'll need to remove them first. Navigate to the storage account and select Settings > Locks. If any locks are listed, delete them.

You might also need to delete the Azure Backup Recovery Services vault before you're allowed to delete the resource group.

  1. Select Home and then Resource groups.
  2. Select the resource group you want to delete.
  3. Select Delete resource group. A window opens and displays a warning about the resources that will be deleted with the resource group.
  4. Enter the name of the resource group, and then select Delete.

Next steps