All Products
Search
Document Center

Elastic Compute Service:Configure UUIDs in the fstab file to automatically mount data disks

Last Updated:Mar 28, 2024

In Linux, you can configure Universally Unique Identifiers (UUIDs) in the fstab file to identify file systems. This ensures that data disks can be automatically and correctly mounted even if the sequence in which the disks are attached is changed. Previously, if the sequence is changed, the related ECS instance cannot run as expected after it is restarted. If you configure UUIDs in the fstab file, this exception does not occur. This topic describes how to configure UUIDs in the fstab file to automatically mount the file systems of data disks and prevent the preceding exception.

Note

fstab allows you to identify a file system by using a disk partition name such as /dev/vdb1 or by using a UUID. The two methods differ in the following aspects:

  • If you use disk partition names to identify file systems in the fstab file, the disk partitions may not be mounted to the original mount points when the sequence in which the disks are attached is changed. In this case, applications that run on your ECS instance may be affected.

  • If you use UUIDs to identify file systems in the fstab file, the disk partitions can still be mounted to the original mount points even when the sequence in which the disks are attached is changed. We recommend that you use UUIDs to identify file systems.

Prerequisites

The data disks attached to the instance are initialized. For more information, see Initialize a data disk whose size does not exceed 2 TiB on a Linux instance or Initialize a data disk that is larger than 2 TiB in size.

Procedure

In this example, two data disks on an instance, /dev/vdc (Partition /dev/vdc1) and /dev/vdd (Partition /dev/vdd1), are used.

  1. Connect to an instance.

  2. Run the following command to view information of the disks on the instance:

    sudo fdisk -lu

    A command output similar to the following one is returned.

    image.png

  3. Run the following command to query the UUIDs of data disks:

    sudo blkid

    A command output similar to the following one is returned.

    image.png

  4. Conditionally required. If no mount directory is available, create mount points for the data disk partitions.

    You can use existing directories as mount points to mount data disk partitions, without creating mount points. In this example, mount points are created.

    • To create the /test01 mount point for /dev/vdc1, run the following command:

      sudo mkdir /test01
    • To create the /test02 mount point for /dev/vdd1, run the following command:

      sudo mkdir /test02
  5. Add mount information for data disk partitions to the fstab file.

    1. Run the following command to edit the fstab file:

      sudo vi /etc/fstab
    2. Press the I key to enter Insert mode.

    3. Add the following mount information:

      UUID=d18698d2-61ea-4992-a8a9-26ee214e****   /test01     ext4    defaults     0   0
      UUID=6c5b3eea-930f-477d-abc6-42aa413d****   /test02     xfs     defaults     0   0

      A command output similar to the following one is returned.

      image.png

      No.

      Field

      Description

      1

      <file system>

      The file system on the partition to mount.

      We recommend that you use the UUIDs of the file systems. You can run the blkid command to query the UUIDs of file systems on the partitions.

      2

      <dir>

      The mount point of the file system.

      You can create mount points. In this topic, the /test01 and /test02 mount points are created.

      3

      <type>

      The type of the file system on the partition to mount.

      You can run the blkid command to query the types of file systems.

      4

      <options>

      The parameters used for mounting. Typically, the defaults parameter is used. If you want to use multiple parameters, separate them with commas (,). Example: defaults,noatime.

      5

      <dump>

      Indicates whether the dump tool backs up the file system.

      • 0: The dump tool does not back up the file system.

      • 1: The dump tool backs up the file system.

      In most cases, the dump tool is not used. In this case, this field is set to 0.

      6

      <pass>

      Indicates whether fsck checks the file system.

      • 0: The file system is not checked.

      • 1: The file system corresponding to root directory (/) is checked.

      • 2: All file systems except the one corresponding to root directory (/) are checked.

      In most cases, this field is set to 0.

    4. Press the Esc key to exit Insert mode.

    5. Enter :wq and press the Enter key to save and exit the file.

  6. Run the following command to view the fstab file:

    cat /etc/fstab

    A command output similar to the following one is returned.

    image.png

  7. Conditionally required. Mount the file systems on data disk partitions.

    • To mount /dev/vdc1, run the following command:

      sudo mount /dev/vdc1 /test01
    • To mount /dev/vdd1, run the following command:

      sudo mount /dev/vdd1 /test02
  8. Run the following command to check whether the file systems on the data disk partitions are mounted:

    df -h

    A command output similar to the following one is returned.

    image.png

After the fstab file is configured, the system automatically mounts the data disks after you restart the ECS instance.

References

System startup exceptions caused by incorrect configuration of the /etc/fstab file of a Linux instance