Azure file shares provide a simple and reliable way to store data in a typical directory hierarchy. Moreover, file share data can be accessed using the widely supported Samba protocol. This enables you to mount Azure file shares to a virtual machine and easily interact with the files from your VM. In this lab, you will have the opportunity to mount an Azure file share to a Linux VM. By the time you have completed the lab, you will be able to read and write to an Azure file share from your Linux VM.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Create a Secure Credentials File to Store Credentials for the Samba Share
Create a file that will contain the Samba credentials for the storage account. Note that for the file name, you should enter your unique service account name:
sudo mkdir -p /etc/smbcredentials
sudo vi /etc/smbcredentials/<STORAGE_ACCOUNT_NAME>.cred
Store the Samba user (storage account name) and password (storage account key) in the file. Input your unique storage account name and key, which you can find via Azure portal.
The file should look like this:
username=<STORAGE_ACCOUNT_NAME> password=<STORAGE_ACCOUNT_KEY>
Set permissions on the credential file so that only root can read it:
sudo chmod 600 /etc/smbcredentials/<STORAGE_ACCOUNT_NAME>.cred
- Mount the File Share to the Linux VM
Create a directory for the mount:
sudo mkdir -p /mnt/sattrecords
Edit the
fstab
file:sudo vi /etc/fstab
At the end of the file, add a line to automatically mount the Azure file share whenever the server starts up:
//<STORAGE_ACCOUNT_NAME>.file.core.windows.net/records /mnt/sattrecords cifs nofail,vers=3.0,credentials=/etc/smbcredentials/<STORAGE_ACCOUNT_NAME>.cred,serverino
Mount the file share by mounting all filesystems in
fstab
.sudo mount -a
Browse the mounted directory. You should see files there that are stored in the Azure file share:
cd /mnt/sattrecords
ls -la
Test your ability to write to the Azure file share by creating a test file:
sudo vi test_file.txt
Write some text to your test file and save it. If you wish, you can navigate to the file share in the Azure portal and view your new file there.