azurediskazure-disk

Shared Disk data not updating between Linux VMs


I am trying to use Shared Disk feature to mount a single SSD drive to multiple Linux VMs.

I am able to attach a single Shared Disk to multiple Linux VMs. I am able to create a partition (tried ext4, xfs, ntfs filesystem) on the Shared Disk. I can do sudo mount /dev/sdc1 /data on my VMs and it works. If there was any data in /dev/sdc1/, then it is visible in all the VMs with this Shared Disk mounted.

My problem starts when I want to write to the Shared Disk from one of the VMs. The results of the write operation is visible to the machine it was called from, but it is not visible on other machines attached to the Shared Disk, unless I umount and mount the Shared Disk manually.

To make the write operation from machine A visible on the machine B, I need to call the following commands on machine B:

sudo umount /data
sudo mount /dev/sdc1 /data

After doing this, I can see the changes made by A from B.

I tried to solve the problem by creating different machine configurations, creating the Shared Disk from scratch multiple times - in case it was corrupted, changing partition filesystem, adding the mount to /etc/fstab with "nosync" option, but the results are always the same.

I expect the "Shared Disk" feature to create read+write capable Shared Disk that can be read and modified from multiple VMs. Specifically, I want to be able to read+write from machines A and B at the same time. I want machine B to see changes made by machine A.

EDIT: After creating and attaching the Shared Disk to the VMs, I use these instructions from Microsoft to format and mount the Disk. I create the partition once, from one of the VMs. From the other machines I run only sudo mount /dev/sdc1 /data.


Solution

  • As mentioned in post, ext4, xfs and ntfs are the file system protocols to organize and manage data and not to share data between different systems.

    To enable shared volumes across multiple VMs, we should use network shared file systems like NFS or SMB server. I have tried with NFS and got the results as expected.

    Create premium storage account in azure and select File shares as Premium account type. Next, create a file share as shown below.

    enter image description here

    enter image description here

    Create a private endpoint for NFS file share in the same network where VMs are deployed and disable secure transfer on the file share. Refer to this link for more information.

    Now login to the both VMs and add the below line to /etc/fstab file.

    <storage-accountname>.file.core.windows.net:/<storage-accountname>/<nfsfilesharename> /datadrive nfs vers=4,minorversion=1,sec=sys 0 0

    /datadrive in above line is the shared folder created with mkdir command. whatever files added to that folder will be accessed over the 2 VMs.

    enter image description here

    Now create files in VM01 and acces it from VM02 as below.

    enter image description here

    Kindly refer to this link Mount NFS Azure file share on Linux | Microsoft for more information.