Mount an Azure File Share on a Linux VM

Use Case: This article provides an example of how to mount and unmount an Azure Storage account File Share on a Linux VM.

Mount an Azure Storage File Share on a Linux VM

Step 1: Install Required Packages

First, ensure that your Linux VM has the necessary packages installed to support CIFS (Common Internet File System).

sudo apt-get update

sudo apt-get install cifs-utils -y

For Red Hat-based distributions, use:

sudo yum install cifs-utils -y

Step 2: Create a Directory for Mounting

Create a directory where you want to mount the Azure File Share.

sudo mkdir /mnt/azurefileshare

You can replace /mnt/azurefileshare with any directory of your choice.

Step 3: Mount the Azure File Share

Use the mount command to mount the Azure File Share to the directory created.

sudo mount -t cifs //<storage-account-name>.file.core.windows.net/<file-share-name> /mnt/azurefileshare -o vers=3.0,username=<storage-account-name>,password=<storage-account-key>,dir_mode=0777,file_mode=0777,serverino
  • Replace <storage-account-name> with your Azure Storage account name.
  • Replace <file-share-name> with the name of your Azure File Share.
  • Replace <storage-account-key> with your storage account key.
Step 4: Verify the Mount

Check if the Azure File Share is successfully mounted.

df -h | grep /mnt/azurefileshare

This command should show the mounted file share.

Step 5: Automount on Reboot 

If you want the Azure File Share to be mounted automatically on system reboot, add the following line to your /etc/fstab file:

Edit the /etc/fstab file using a text editor like nano or vi:

sudo nano /etc/fstab 

sudo vi /etc/fstab 

Add the below line to the end of the file, save, and exit.

//<storage-account-name>.file.core.windows.net/<file-share-name> /mnt/azurefileshare cifs vers=3.0,username=<storage-account-name>,password=<storage-account-key>,dir_mode=0777,file_mode=0777,serverino 0 0

Unmounting the File Share on a Linux VM

If you need to unmount the Azure File Share:

sudo umount /mnt/azurefileshare

Troubleshooting Unmounted File Shares on Ubuntu Linux Servers

When a file share is unmounted from Ubuntu Linux servers, you can check the logs to diagnose any issues in a couple of ways: using Syslog and dmesg.

Checking Syslog

You can find additional information related to mounting and unmounting in the syslog. Use the following command to search for relevant logs:

grep 'Mounted\|Unmounted' /var/log/syslog*

This will display entries related to mounted and unmounted filesystems.

Using dmesg

The dmesg command provides kernel ring buffer messages, including information about disk mounting and filesystem activity.

To find logs related to mounting or ext4 filesystems, use the following command:

grep -e mount -e ext4 -lR /var/log 2> /dev/null

Archived versions of dmesg logs are also available (e.g., dmesg.*).

Monitoring Log Files in Real-Time

If you’re administering remote Ubuntu servers without a graphical interface, you can monitor log files directly from the terminal using:

tail -f /var/log/messages