All Products
Search
Document Center

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

Last Updated:Sep 18, 2024

You can configure UUIDs in the fstab file of a Linux Elastic Compute Service (ECS) instance to identify file systems. This way, even if the sequence in which data disks are attached to the Linux ECS instance is changed, the disks can be automatically and correctly mounted and the instance can run as expected after restart. This topic describes how to configure UUIDs in the fstab file to automatically mount the file systems of data disks.

Note

The fstab file 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 data 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 are mounted to the original mount points even when the sequence in which the data disks are attached is changed. We recommend that you use UUIDs to identify file systems.

Procedure

In this example, the following data disks on a Linux ECS instance are used: /dev/vdc, on which the /dev/vdc1 partition is created, and /dev/vdd, on which the /dev/vdd1 partition is created.

  1. Connect to a Linux ECS instance.

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

    sudo fdisk -lu

    The following command output is returned.

    image.png

  3. Run the following command to query the UUIDs, partition names, and file system types of the data disks:

    sudo blkid

    The following command output is returned.

    image.png

  4. (Conditionally required) If no file systems are mounted on the partitions of your data disk, create mount points for and mount file systems on the partitions.

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

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

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

      sudo mkdir /test02
  5. (Conditionally required) Mount the file systems on data disk partitions.

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

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

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

    df -h

    The following command output is returned.

    image.png

  7. Add mount information for data disk partitions to the fstab file to automatically mount the partitions on instance startup.

    1. Run the following command to open the /etc/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

      The following figure shows an example of the mount information.

      image.png

      No.

      Field

      Description

      <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.

      <dir>

      The mount point of the file system.

      You can use the /test01 and /test02 mount points that you created or run the df -Th commands to query the mount points of file systems.

      <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.

      <options>

      The mount parameters. Typically, the defaults parameter is used. If you specify multiple parameters, separate the parameters with commas (,). Example: defaults,noatime.

      • For more information about the <options> parameters, see fstab.

      • To mount Ext4 file systems, you can specify different mount parameters based on your data security and performance requirements for file systems. For more information, see Mount Ext4 file systems with mount command options.

      <dump>

      Specifies whether the dump tool backs up the file system. Valid values:

      • 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.

      <pass>

      Specifies whether fsck checks the file system. Valid values:

      • 0: The file system is not checked.

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

      • 2: All file systems except the file system 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 close the file.

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

    cat /etc/fstab

    The following command output is returned.

    image.png

  9. Run the following command to read the fstab file and automatically mount file systems based on the configurations in the file. If the command output does not contain errors, the fstab file is correctly configured.

    sudo mount -a

After you configure the fstab file, the system automatically mounts the data disks when you restart the ECS instance.

References