Data disk on Azure VM (Ubuntu 20) is automatically unmounted time to time

Jayashan 0 Reputation points
2024-03-22T16:00:41.6266667+00:00

I have created a virtual machine with Ubuntu 20 OS. It has one OS disk and 128GB secondary data disk (seperately purchased) to store all the application data.

I have mounted it on /mnt/data directory. But time to time that mount is dissapearing.

after restart the drive mame is sda -> sda1 and another time it will become sdc -> sdc1.

Already updated the FSTAB as below.

/dev/sda1 /mnt/data ext4 defaults 0 2

how to solve this.

Thanks in advance.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,472 questions
Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
590 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sedat SALMAN 13,265 Reputation points
    2024-03-22T17:51:52.1266667+00:00

    If your Azure VM's data disk is unmounting by itself, switch from using the device name (like /dev/sda1) to using the disk's UUID in your /etc/fstab. Find the UUID with sudo blkid, and then update /etc/fstab like this: UUID=your-uuid /mnt/data ext4 defaults 0 2. This prevents the issue where device names change, which is likely causing your mounts to disappear.

    0 comments No comments

  2. Sumarigo-MSFT 44,906 Reputation points Microsoft Employee
    2024-03-25T10:27:44.86+00:00

    @Jayashan Welcome to Microsoft Q&A forum, Thank you for posting your query here!

    To ensure persistent disk mounting for secondary data disks on an Azure VM with Ubuntu, you should use UUIDs instead of device names in your /etc/fstab file, as device names can change across reboots. Here's how you can set it up:

    1. Find the UUID of the disk you want to mount by running the following command:
            sudo blkid
         
      
      This will output a list of all the available disks and their UUIDs.
    2. Once you have the UUID, add an entry to the /etc/fstab file using the following format:
          UUID=<UUID> <mount_point> <file_system_type> <options> <dump> <pass>
       
    

    For example, if the UUID of your disk is 33333333-3b3b-3c3c-3d3d-3e3e3e3e3e3e and you want to mount it at /datadrive with the xfs filesystem type and default options, you can add the following line to the /etc/fstab file:

          UUID=33333333-3b3b-3c3c-3d3d-3e3e3e3e3e3e   /datadrive  xfs    defaults,nofail   1  2
       
    

    After adding the entry, save and close the file using Ctrl+O to write the file and Ctrl+X to exit the editor.

    By using UUIDs, you ensure that the correct disk is mounted to the specified mount point regardless of the device name assigned at boot.

    Option 2

    Here's how you can do it using the UUID:

    1. Find out the UUID of your secondary data disk using the following command:
    
    sudo blkid
    

    This command will display information about all block devices. Look for the line corresponding to your secondary data disk (/dev/sdX1) and note down its UUID.

    Update your /etc/fstab file to use the UUID instead of the device name. Open the file using a text editor:

    
    sudo nano /etc/fstab
    

    Modify the line for your secondary data disk to use the UUID. The line should look something like this:

    
    UUID=<your-uuid> /mnt/data ext4 defaults 0 2
    

    Replace <your-uuid> with the UUID you obtained in step 1.

    Save the changes and exit the text editor.

    You may need to remount the filesystem to apply the changes immediately:

    
    sudo mount -a
    

    Now, your secondary data disk should be mounted consistently across reboots, regardless of the device enumeration order. This approach ensures that your system always mounts the correct disk based on its unique identifier

    References:

    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