In this post, I will show you how to map a network drive (Azure File Share) to a Linux and Windows Azure VMs.

Mount SMB on Azure Linux VM

At first, you’ll need to create a new file, i.e. filesharecredentials

sudo mkdir -p /etc/filesharecredentials

and store the Azure Storage account credentials, including Username (Storage account name) and Password (Key).

sudo vi /etc/filesharecredentials/azstoracc.cred

The image below depicts the page where you can copy the Username (Storage account name) and the Password (Key).

The following is what it should look like after you edit and paste the values:

To save and exit vi editor, do the below:

  • Press Esc key
  • Press : (colon)
  • Type wq, to save and exit the file.
  • Press Esc → Ctrl + : → wq

For mounting, create a new directory:

sudo mkdir -p /mnt/sharefldr

Edit the fstab file

sudo vi /etc/fstab

All filesystems should be mounted in fstab.

Instead of following the above steps, you may copy the Linux script from the Azure File Share resource and run it against the Linux virtual machine.

 

Mount SMB on Windows VM

It is much simpler to mount SMB on a Windows virtual machine than it is on a Linux VM, and all you need to do is copy a PowerShell script.

Use the PowerShell ISE, for example, to run the script

$connectTestResult = Test-NetConnection -ComputerName demolinuxstorage.file.core.windows.net -Port 445
if ($connectTestResult.TcpTestSucceeded) {
# Save the password so the drive will persist on reboot
cmd.exe /C "cmdkey /add:`"demolinuxstorage.file.core.windows.net`" /user:`"localhost\demolinuxstorage`" /pass:`"LK0m8IfdJ0hLyb4fxxNbEVZO+ckMlJFTVSYNEb3vJOORj7BCRNc5P+i1E4iOpPJ7ncBEBqANwudD+AStNhKbag==`""
# Mount the drive
New-PSDrive -Name Z -PSProvider FileSystem -Root "\\demolinuxstorage.file.core.windows.net\winshare" -Persist
} else {
Write-Error -Message "Unable to reach the Azure storage account via port 445. Check to make sure your organization or ISP is not blocking port 445, or use Azure P2S VPN, Azure S2S VPN, or Express Route to tunnel SMB traffic over a different port."
}

The network share will be displayed in a few seconds.

Useful Links

https://learn.microsoft.com/en-us/azure/storage/files/storage-how-to-use-files-linux

 

 

 

 

 

Share This