Mount Azure Blob Storage On Linux
Sumit Sengupta
Multi-Cloud Architect 12x certified - Azure, AWS, GCP, OCI | Ex- (Microsoft, Apple, MongoDB) | Cybersecurity Instructor | AWS Academy Educator | 2x Top Voice - Database, Data Architecture | Mentor / Tech Volunteer
Azure storage offers different type of storage services for different workloads and one of the most common ones used is Blob storage, that can store any type of files - unlimited scale - and can be accessed from anywhere. In this article what I am sharing is how you can access your blob storage container - from Linux OS from anywhere - on prem, or any cloud . As long as the blob storage is accessible via network and credentials are correct, the blob container can be accessed.
In a rush to just get it working for you ? Here is a script for you.
To start with, in case you are not familiar with azure blob, here are the basic concepts.
Step 1: First you create a storage account and the container that you want to access. To keep things simple, I have kept the storage account accessible from public network. You can restrict access to specific network if you want to. For me, in Azure portal storage networking blade it shows like this.
Step 2:Once the storage account is created, you will need your container created. Next step is to find out the access credentials for the container. You can access it with storage account name and key that gives full read/write access to the whole storage account. Alternately you can keep it more secure and create a SAS token that only has access to your container and you can restrict what permission you would like to share - read/write etc.
Step 3:Next head over to your Linux machine and install the blobfuse package as root.
Now you are ready to mount your container on Linux. You can mount it as a regular user.
Step 4: ( Optional but recommended) The following step is optional but highly recommended for better performance. Create a blobfuse temporary file for improved performance following this instruction. Following is a script that will do it for you. Replace your unix-user and unix-group with yours. In most shells you can get it by typing id command.
# Create the directory where you want the blob container to be mounted on your linux host. /usr/bin/bash if ! [[ -d /mnt/resource/blobfusetmp ]] ; then sudo mkdir /mnt/resource/blobfusetmp -p sudo chown <unix-user>:<unix-group> /mnt/resource/blobfusetmp
fi
Notice that if your Linux VM is an Azure VM, /mnt is on ephemeral disk which gets wiped on every reboot. So you have to run this on every reboot - add it on system startup scripts.
Step 5: Next step is to create a config file lists the storage blob account, container and access key. I named the file .fuse_connection.cfg
# Azure storage account name, password and the container to mount accountName <your_storage_account> accountKey <your_storage_key>
containerName <your_storage_container>
Step 6: The final step is to mount the filesystem. I am mounting it on /data/azure-blob-container directory below. There are a lot of additional mount options. We are going to use default options for most of them.
$ blobfuse /data/azure-blob-container --tmp-path=/mnt/resource/blobfusetmp --config-file=./.fuse_connection.cfg -o attr_timeout=240 -o entry_timeout=240 -o negative_timeout=120 -o nonempty
In the command above, tmp-path is the temporary directory created as an optional step for better performance in step 4 above. Config-file is the file that stores azure storage account, access key or sas token,
Notice that you can mount the container in user mode.
Step 7: ( Optional ) Finally if you need to unmount the filesystem there are two ways.
Unmount as the regular user that mounted it
$ umount /data/azure-blob-container
Alternately as root - you do not need to specify the mount directory.
# sudo umount blobfuse