Creating and Mounting Azure File Shares

45 minutes
  • 2 Learning Objectives

About this Hands-on Lab

In this hands-on lab, we are tasked with creating a file share and mounting it to a Linux VM. File shares are located within our Storage Account. File shares are fully managed file storage systems, allowing us to easily store files from our local workstation by using the mounted drive, just as you would with local storage.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create the File Share
  1. Log in to the Portal and go to Storage accounts in the portal menu.

  2. Click on the provided storage account.

  3. Click on File shares in the resource menu, in the File service section.

  4. Click + File share.

  5. In the form that arrives:

    • Enter fileshare1 in the Name field.
    • Set the Quota, to 2.
  6. Click Create.

Mount the File Share to a Linux VM
  1. Navigate to Virtual machines in the portal menu.

  2. Click on the provided virtual machine.

  3. In the resource menu, under Support + troubleshooting, click Reset password. We will fill out the details on this page in just a moment.

  4. Click the >_ button at the top of the Azure Portal (in the global controls section) to open the Cloud Shell.

  5. Click the Bash link in the cloud shell.

  6. Click Show advanced settings.

  7. Set Cloud Shell region to the same region as the existing storage account.

  8. For Storage account, select Use existing.

  9. Under File share, select Create new and enter fileshareforcli.

  10. Click Create storage.

  11. Determine your account username:

    whoami
  12. Copy the user into the Username field in the Reset password window.

  13. Back in the shell, create an ssh key:

    ssh-keygen
  14. Press Enter to save it in the default location.

  15. Enter a passphrase of your choice.

  16. Display the ssh key:

    cat .ssh/id_rsa.pub
  17. Copy the displayed key into the SSH public key field in the Reset password window.

  18. Click Update. This may take a few moments to update.

  19. Find Overview and copy its Public IP address.

  20. Back in the terminal, run this:

    ssh [email protected]_IP

    Substitute the username (cloud) and the public IP.

  21. Enter yes at the prompt.

  22. Enter the passphrase you entered earlier.

  23. Install the cifs-utils:

    sudo apt install cifs-utils
  24. Create a directory:

    sudo mkdir /mnt/fileshare1
  25. Get the link for the file share:

    1. In the Azure Portal, click Storage accounts from the portal menu.

    2. Click the storage account provided as part of the lab.

    3. Click on File shares in the resource menu under File service.

    4. Click on fileshare1.

    5. Click Properties.

    6. Copy the URL field that’s out in the working pane, but leave off the https: (just grab the two forward slashes and everything else to the right).

  26. Retrieve the password for the account.

    Note: this step is done later in the video, but is necessary to complete the following steps now:

    1. In the Azure Portal, click on the Storage Accounts and our storage account.

    2. Click on Access keys under Settings in the resource menu.

    3. Copy the content in the Key box under key1.

  27. Return to Cloud Shell and enter the beginning of the mount command using the copied URL. Do not include "https" in the path. Replace the STORAGE_ACCOUNT_NAME with the name for your storage account (Ex: linuxazlabmrkxkpwyqzhmu). Also make sure to replace STORAGE_ACCOUNT_KEY with the key1 parameter from the previous step. Then run the command:

    sudo mount -t cifs //FILESHARE_URL_WITHOUT_HTTPS /mnt/fileshare1 -o vers=3.0,username=STORAGE_ACCOUNT_NAME,password=STORAGE_ACCOUNT_KEY,dir_mode=0777,file_mode=0777,serverino
  28. Verify that it is mounted (the name of the fileshare is listed):

    df -h
  29. Navigate to the mounted directory and add a file:

    cd /mnt/fileshare1
    touch file1.txt
  30. In the Azure Portal, get back to Storage accounts and into the one we’re working with. click File shares under the File service section of the resource menu.

  31. Click fileshare1 and verify the existence of file1.txt.

Additional Resources

We are tasked with creating a file share in Azure. Once created, we mount it to a virtual machine to access and add any additional files within that file share.

A Storage Account and VM are already been provisioned. We create a file share within that Storage Account and mount that file share to the provisioned Linux VM.

UPDATE: Use the same region as the existing storage account for the Cloud Shell Region, the existing Resource Group, the existing Storage Account, and a unique file share name.

Log in to the Azure Portal using the credentials provided on the lab instructions page.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?