Thursday, December 17, 2015

Create an Azure File Share and mount drive (and persists) on Windows and Centos

Pre-requisite: Azure Storage Account.
Steps:
1.       Create a file share either in portal.azure.com or through PS (you can’t create AFS in ARM template yet)
PS C:\Users\xyz> $storageContext=New-AzureStorageContext -StorageAccountName saaccount -StorageAccountKey yourkey

PS C:\Users\xyz> $storageContext |  New-AzureStorageShare -Name yourshare
2.       Test that file share exists
a.       Via PS
PS C:\Users\xyz> $storageContext |  Get-AzureStorageShare

b.       Via Azure File Explorer
3.       Mount the share
cmdkey /add:yoursaacount.file.core.windows.net /user:yoursaacount /pass:yoursakey
net use z: \\yoursaacount.file.core.windows.net\yourshare
4.       Test the share in windows
PS C:\Users\xyz> net use
Also, test in the File Explorer
a.       Reboot the machine
b.       Retest for the persistence

cmds on Centos:
mkdir /mnt/yourshare

sudo mount -t cifs //yourstorageaccountname.file.core.windows.net/yourshare /mnt/yourshare -o vers=3.0,user=yourstorageaccountname,password=yoursakey,dir_mode=0777,file_mode=0777

df -h /mnt/yourshare/


cd /mnt/yourshare/

Persist in /etc/fstab

//yourstorageaccountname.file.core.windows.net/yourshare  /mnt/yourshare   cifs  _netdev,username=yourstorageaccountname,password=yoursakey,dir_mode=0755,file_mode=0755,uid=500,gid=500 0 0

Troubleshooting tips:
·         Unable to connect (System error 53):
o   Ensure that outbound 425 port for TCP (for smb) is open
o   Ensure that you launched cmd as an administrator
o   Ensure that cmdkey has persisted
   cmdkey /list
o   Last resort troubleshoot with WireShark like tool
·         Unable to persists (share prompts for password after reboot of the box)

net use y: \\yoursaacount.file.core.windows.net\yourshare /u:yoursaacount yoursakey /P:Yes -- if you have use, then try cmdKey instead.
·         In linux mnt fails
 e.g.
systemd: Mounting /mnt/yourshare...
kernel: Key type dns_resolver registered
kernel: Key type cifs.spnego registered
kernel: Key type cifs.idmap registered
kernel: CIFS VFS: cifs_mount failed w/return code = -112
mount: mount error(112): Host is down


Ensure that the host is able to reach the file server. You might want to add an entry in /etc/hosts.

6 comments:

  1. What are the resolution from 'mount: mount error(112): Host is down'

    ReplyDelete
    Replies
    1. The message is misleading. Please check the cif versions. Also, check if the necessary port is open.

      Delete
  2. The message is kind of misleading, but ensure that OS version and cisf version probably. Based on my testing CentOS 7.1 doesn't have this problem whereas Centos 6.6 does.

    ReplyDelete
  3. How to set permissions to different folders within the mount? The chown does not seem to work

    ReplyDelete
    Replies
    1. AFS is not Posix compatible. If there is an intent to share globally, then SAS could be an option.

      Delete