Azure file service - Mount Azure fileshare on Linux

Azure fileservice enables access to file shares on multiple machines using standard SMB 2.1 protocol. Many enterprise on-premise applications depend on fileshares to store pictures etc and this feature one to do a lift and shift migration of applications to Azure cloud. The equivalent to this feature on AWS is Elastic File System.

We did a lift and shift migration of one such application which involved both Windows and Linux servers. Below are the steps for creating a file share, mounting it on Linux and windows.

Configure Azure CLI and/or Azure Powershell

Azure file service is currently in the preview. Neither the current management console nor the new portal allow you to create fileshares so you need command like tools like Azure-cli or Azure Powershell. I have blogged about setting up Azure-cli here. I will assume that you have Azure cli downloaded and configured.

Create Fileshare

From Azure cli, connect to your subscription. You need to download a publish settings file

azure account download  

It will launch your default browser and wait for credentials. Once authenticated, downloads a file. Import that file

azure account import "/Users/rk/Downloads/MyAccount-Azure.publishsettings"  

List the accounts after importing the publish settings file and select an account you would like to work on(if you have multiple accounts)

azure account list  
azure account set "Microsoft Azure Sponsorship"  

create a storage account. You might want to select storage type and location.

azure storage account create $storage_account_name  

If you visit the management console and check this storage account, you should see a files option in preview like below:

Get the access key for the storage account from manage access keys and create a container for your fileshare

export AZURE_STORAGE_ACCOUNT=appfileshare  
export AZURE_STORAGE_ACCESS_KEY=YourSuperSecretAccessKey  
export container_name=appshare  
echo "Creating the container..."  
azure storage container create $container_name  

Now we need to create a storage context and an object share which is unfortunately only possible via Azure Powershell for now.

Create a storage account context in Azure powershell

$context=New-AzureStorageContext <account name> <account key>

Next, create a new share

$share = New-AzureStorageShare appshare -Context $context

That's it. you now have a share ready to be mounted.

Mount the share on a Linux Machine

On your linux VM, in order to mount this smb share, instal cifs utils, make a directory and mount it

sudo apt-get install cifs-utils  
sudo mkdir /appdata  
mount -t cifs -o vers=2.1,username=appfileshare,password=SuperSecretAccessKey //appfileshare.file.core.windows.net/appshare /appdata  

Hope this helps someone. If you have questions, please get in touch and we would be happy to help.

comments powered by Disqus