All Products
Search
Document Center

Elastic Compute Service:Automatically mount a data disk using a UUID in /etc/fstab

Last Updated:Sep 11, 2025

To automatically mount your data disk at startup, add its Universally Unique Identifier (UUID) to the /etc/fstab file. Otherwise, you must manually mount the file system after each reboot to access the files on the disk.

Procedure

Before you begin, ensure your data disk is In Use, initialized, and has a mounted file system.

  1. Log on to the Elastic Compute Service (ECS) instance.

    1. Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.

    2. Go to the instance's details page. Click Connect and select Workbench. Follow the on-screen prompts to log on and access the terminal.

  2. To prevent errors from incorrect configuration, create a backup of the /etc/fstab file.

    sudo cp /etc/fstab /etc/fstab.bak
  3. Configure the mount information.

    1. Get the information of the target disk.

      Run the sudo lsblk -f command. Record the target device name, mount point, and file system type for the disk you want to configure.

      $ sudo lsblk -f
      NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
      vda                                                      
      └─vda1 ext4   root  33b46ac5-7482-4aa5-8de0-60ab4c3a4c78 /
      vdb    ext4         3d7a3861-da22-484e-bbf4-b09375894b4f                                                         
      └─vdb1 ext4         f1645951-134f-4677-b5f4-c65c71f8f86d /mnt
      vdc    xfs          3d7a3861-da22-484e-bbf4-b09375894b4f /test
      • If the device has a partition, the target device name is the partition name. In the example, for data disk vdb, the target device name is vdb1, the mount point is /mnt, and the file system type is ext4.

      • If the device does not have a partition, the target device name is the same as the device name. In the example, for data disk vdc, the target device name is vdc, the mount point is /test, and the file system type is xfs.

    2. Add the mount information to /etc/fstab.

      Replace the <target_device_name>, <mount_point>, and <file_system_type> in the command with the information from the previous step, and then run the command. For parameter descriptions, see fstab man-pages.

      Important

      When you set the options to defaults,nofail, the instance can start normally even with an incorrect mount configuration. However, the system does not report an error. You must carefully verify that the automatic mount succeeded to avoid writing data to the wrong device.

      sudo sh -c "echo `sudo blkid /dev/<target_device_name> | awk '{print \$2}' | sed 's/\"//g'` <mount_point> <file_system_type> defaults 0 0 >> /etc/fstab"
      For example, to configure a disk where the target device name is vdb1, the mount point is /mnt, and the file system type is ext4:
      sudo sh -c "echo `sudo blkid /dev/vdb1 | awk '{print \$2}' | sed 's/\"//g'` /mnt ext4 defaults 0 0 >> /etc/fstab"

  4. Verify the automatic mount configuration.

    1. Unmount the current mount point.

      Replace <target_device_name> with the target device name from Step 2.a.

      sudo umount /dev/<target_device_name>
    2. Reload the /etc/fstab file.

      Run the following command to mount all unmounted file systems listed in /etc/fstab.

      sudo mount -a

      If an error occurs, you can quickly restore the original /etc/fstab file by running sudo mv /etc/fstab.bak /etc/fstab.

    3. Check if the mount was successful.

      Run the sudo lsblk command. If the output shows a mount point (MOUNTPOINT) for the target device, the configuration is successful.

  5. Run the sudo reboot command to restart the operating system and verify that it starts normally.

    Important

    Rebooting the operating system can impact your live services. Proceed with caution.

    If the instance starts successfully, run the sudo lsblk command. If the output shows a mount point (MOUNTPOINT) for the target device, the configuration is successful.

    If the instance fails to start, follow the instructions in Troubleshoot system startup failures on a Linux instance caused by an /etc/fstab configuration error to resolve the issue.

FAQ

What should I do if my instance fails to start after a reboot due to an /etc/fstab configuration error?

You can follow the instructions in Troubleshoot system startup failures on a Linux instance caused by an /etc/fstab configuration error to connect to the instance using a VNC connection and manually correct the mount information in emergency mode.

Why is using a UUID recommended over a partition name (such as /dev/vdb1) when configuring /etc/fstab?

  • Using a disk partition name: If the disk mount order changes, the system-assigned partition name can also change. This can cause the mount entry in fstab to point to the wrong partition or fail entirely. This failure can prevent applications from accessing data and may cause service disruptions.

  • Using a UUID: A UUID is a unique identifier for the disk. It is unaffected by the disk mount order, which ensures the system always locates and mounts the correct partition.