Skip to main content

Creating and Mounting Azure File Shares

Hands-On Lab

 

Photo of Chad Crowell

Chad Crowell

DevOps Training Architect II in Content

Length

00:30:00

Difficulty

Beginner

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 and use the mounted drive, just as you would local storage.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Creating and Mounting Azure File Shares

Introduction

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 and use the mounted drive, just as you would local storage.

Solution

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

Create a File Share

  1. Click on Storage accounts from the left-hand menu.

  2. Click on the provided storage account.

  3. Click on Files at the bottom of the storage account menu under File service.

  4. Click + File share.

  5. Enter "fileshare1" in the Name box.

  6. Under Quota, enter "2".

  7. Click Create.

Mount the File Share to a Linux Virtual Machine

  1. Click Virtual machines from the left-hand menu.

  2. Click on the provided virtual machine.

  3. Under Support + troubleshooting, click Reset password.

  4. Click the >_ button at the top of the Azure Portal to open cloud shell.

  5. Click the Bash link in the cloud shell.

  6. Click Show advanced settings.

  7. Choose the existing Resource Group and Storage Account. Under File share, select Create new and enter "fileshareforcli" in the box provided.

  8. Click Create storage.

  9. Determine your account username.

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

  2. Back in the shell, create an ssh key.

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

  4. Enter a passphrase of your choice.

  5. Display the ssh key.

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

  7. Click Update.

  8. In the menu for the VM, click Overview.

  9. Copy the Public IP address.

  10. Connect to the VM through the CloudShell using the copied IP address and the username discovered when you used the whoami command above.

    ssh USERNAME@PUBLIC_IP_ADDRESS
  11. Provide the passphrase from the SSH key.

  12. Verify your are on the lab VM.

    hostname
  13. Install the cifs-utils.

    sudo apt install cifs-utils
  14. Create a directory.

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

    1. In the Azure Portal, click Storage accounts from the left-hand menu.

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

    3. Click on Files at the bottom of the storage account menu under File service.

    4. Click on fileshare1.

    5. Click Properties.

    6. Copy the URL field.

  16. Return to cloud shell and enter the beginning of the mount commantusing the copied URL. Do not include "https" in the path. Replace the STORAGE_ACCOUNT_NAME with the name for your storage account.

    sudo mount -t cifs //FILESHARE_URL_WITHOUT_HTTPS /mnt/fileshare1 -o vers=3.0,username=STORAGE_ACCOUNT_NAME
  17. Retrieve the password for the account.

    1. In the Azure Portal, click on the storage account at the top of the screen.

    2. Click on Access keys under Settings.

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

  18. Finish entering the mount command replacing 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
  19. Verify that it is mounted.

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

    cd /mnt/fileshare1
    touch file1.txt
  21. In the Azure Portal, click Files under File service.

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

Conclusion

Congratulations — you've completed this hands-on lab!