How to mount sub folder in Azure File share in Linux

Manoj Agrawal 20 Reputation points
2024-04-04T14:24:56.0266667+00:00

Hi,

I am not able to mount Sub folders created in Azure file share in my linux machine and hence I can only reach out to the parent file share and place files although I want to be able to place files inside a sub directory created under parent file share in Azure storage.

Please help,

Thanks

Manoj

Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,288 questions
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,911 questions
Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,171 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sumarigo-MSFT 46,286 Reputation points Microsoft Employee
    2024-04-05T09:56:51.62+00:00

    @Manoj Agrawal Welcome to Microsoft Q&A Forum, Thank you for posting you query here!

    You cannot mount a sub-folder. You need to mount the entire share. 

    If I cannot mount a sub folder (Azure File share in Linux) then, is it possible to mount the file share and then change directory in Linux machine to traverse to sub folder to place file? So, the answer to this question is. Yes, once you mount the file share, you can change directory to traverse to sub-folder and place file

    Mount fileshare root [has one folder (dir1) and one file (file1)

    azureuser@subm-ubuntu20:~$ sudo mount -t nfs submsapremium.file.core.windows.net:/submsapremium/nfs-share1 /mount/submsapremium/nfs-share1 -o vers=4,minorversio
    n=1,sec=sys,nconnect=4
    azureuser@subm-ubuntu20:~$ cd /mount/submsapremium/nfs-share1/
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1$ ls
    dir1  file1
    
    

    I can create a folder, subfolder and file in the mountpoint

    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1$ cd dir1/
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1/dir1$ ls
    dir2  file  file2  file3
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1/dir1$ cd dir2/
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1/dir1/dir2$ ls
    file3
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1/dir1/dir2$ mkdir dir3
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1/dir1/dir2$ cd dir3
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1/dir1/dir2/dir3$ touch file4
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1/dir1/dir2/dir3$ ls
    file4
    
    

     

    I can also mount sub-folder if required and then create files and directories under the mountpoint

     

    Below, I am just mounting the dir2 which is inside the dir1 -> inside root of the share. When I mount the subfolder, I can only see that folder and any child folders/files under the subfolder that is mounted.

    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1/dir1/dir2/dir3$ cd
    azureuser@subm-ubuntu20:~$ sudo umount /mount/submsapremium/nfs-share1 
    azureuser@subm-ubuntu20:~$ ls
    azureuser@subm-ubuntu20:~$ sudo mount -t nfs submsapremium.file.core.windows.net:/submsapremium/nfs-share1/dir1/dir2 /mount/submsapremium/nfs-share1 -o vers=4,minorversion=1,sec=sys,nconnect=4
    azureuser@subm-ubuntu20:~$ ls
    azureuser@subm-ubuntu20:~$ cd /mount/submsapremium/nfs-share1/
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1$ ls
    dir3  file3
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1$ touch file5
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1$ ls
    dir3  file3  file5
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1$ cd dir3/
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1/dir3$ touch file6
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1/dir3$ ls
    file4  file6
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1/dir3$ pwd
    /mount/submsapremium/nfs-share1/dir3
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1/dir3$ cd ..
    azureuser@subm-ubuntu20:/mount/submsapremium/nfs-share1$ ls
    dir3  file3  file5
    
    

    For SMB share, you cannot mount the sub-folder, but once you have mounted the root of the file share , you should be able to create subfolders and files under that subfolder

    Here, I am mounting the root of the smb share and also creating folders, sub-folders and files under the mountpoint

    azureuser@subm-ubuntu20:~$ sudo mount -t cifs //submsapremium.file.core.windows.net/smbshare1 /mnt/smbshare1 -o credentials=/etc/smbcredentials/submsapremium.cred,d
    ir_mode=0777,file_mode=0777,serverino,nosharesock,actimeo=30
    azureuser@subm-ubuntu20:~$ cd /mnt/smbshare1/
    azureuser@subm-ubuntu20:/mnt/smbshare1$ ls
    subm-vng.zip
    azureuser@subm-ubuntu20:/mnt/smbshare1$ mkdir dir1
    azureuser@subm-ubuntu20:/mnt/smbshare1$ cd dir1
    azureuser@subm-ubuntu20:/mnt/smbshare1/dir1$ touch file1
    azureuser@subm-ubuntu20:/mnt/smbshare1/dir1$ mkdir dir2
    azureuser@subm-ubuntu20:/mnt/smbshare1/dir1$ touch file2
    azureuser@subm-ubuntu20:/mnt/smbshare1/dir1$ ls
    dir2  file1  file2
    azureuser@subm-ubuntu20:/mnt/smbshare1/dir1$ cd ..
    azureuser@subm-ubuntu20:/mnt/smbshare1$ ls
    dir1  subm-vng.zip
    azureuser@subm-ubuntu20:/mnt/smbshare1$ mkdir dir3
    azureuser@subm-ubuntu20:/mnt/smbshare1$ cd dir3
    azureuser@subm-ubuntu20:/mnt/smbshare1/dir3$ touch file4
    azureuser@subm-ubuntu20:/mnt/smbshare1/dir3$ ls
    file4
    azureuser@subm-ubuntu20:/mnt/smbshare1/dir3$ pwd
    /mnt/smbshare1/dir3
    azureuser@subm-ubuntu20:/mnt/smbshare1/dir3$ cd
    azureuser@subm-ubuntu20:~$ sudo umount /mnt/smbshare1 
    
    

    If I directly try to mount a sub-folder, I get the error saying that path does not exist

    azureuser@subm-ubuntu20:~$ sudo mount -t cifs //submsapremium.file.core.windows.net/smbshare1/dir2 /mnt/smbshare1 -o credentials=/etc/smbcredentials/submsapremium.cred,dir_mode=0777,file_mode=0777,serverino,nosharesock,actimeo=30
    mount error(2): No such file or directory
    Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) and kernel log messages (dmesg)
    azureuser@subm-ubuntu20:~$ sudo mount -t cifs //submsapremium.file.core.windows.net/smbshare1 /mnt/smbshare1 -o credentials=/etc/smbcredentials/submsapremium.cred,dir_mode=0777,file_mode=0777,serverino,nosharesock,actimeo=30
    azureuser@subm-ubuntu20:~$ cd /mnt/smbshare1/
    azureuser@subm-ubuntu20:/mnt/smbshare1$ ls
    dir1  dir3  subm-vng.zip
    azureuser@subm-ubuntu20:/mnt/smbshare1$ cd dir3
    azureuser@subm-ubuntu20:/mnt/smbshare1/dir3$ ls
    file4
    azureuser@subm-ubuntu20:/mnt/smbshare1/dir3$ mkdir dir4
    azureuser@subm-ubuntu20:/mnt/smbshare1/dir3$ cd dir4
    azureuser@subm-ubuntu20:/mnt/smbshare1/dir3/dir4$ touch file6
    azureuser@subm-ubuntu20:/mnt/smbshare1/dir3/dir4$ 
    
    
    

    Please let us know if you have any further queries. I’m happy to assist you further.    


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Vinodh247 21,781 Reputation points
    2024-04-04T15:23:40.5333333+00:00

    Hi Manoj Agrawal,

    Thanks for reaching out to Microsoft Q&A.

    I don't think is possible to mount a subfolder. Please see the discussion below with evidence that there is a limitation on mounting subfolder from azure file share into Linux.

    https://stackoverflow.com/a/69265866

    Please 'Upvote'(Thumbs-up) and 'Accept' as an answer if the reply was helpful. This will benefit other community members who face the same issue.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.