Updated on 2026-06-16 GMT+08:00

Changing Disk Identifiers in the fstab File to UUID

Scenarios

To ensure that Linux can correctly identify disks when mounting the file system, you need to change the disk identifier in the fstab file of the ECS to UUID before creating a Linux private image.

Procedure

Run blkid to obtain the UUIDs of all partitions. Modify the /etc/fstab file and use the UUIDs of the partitions to configure automatic partition mounting.

  1. Log in to an ECS as user root.
  2. List all types of mounted file systems and their device UUIDs.
    blkid
    The command output is as follows:
    /dev/vda2: UUID="4eb40294-4c6f-4384-bbb6-b8795bbb1130" TYPE="xfs"  
    /dev/vda1: UUID="2de37c6b-2648-43b4-a4f5-40162154e135" TYPE="swap"

    The displayed information may vary depending on the distribution. You only need to pay attention to the UUID.

  3. Query the fstab file.
    cat /etc/fstab
    The command output is as follows:
    [root@CTU1000028010 ~]# cat /etc/fstab  
    /dev/vda2  /       xfs     defaults    0 0
    /dev/vda1  swap    swap    defaults    0 0
  4. Check whether the disk identifier in the fstab file is the device name.
    • If the disk is represented by a UUID, no further operation is required.
    • If the disk is represented by a device name, go to the next step.
  5. Open the fstab file.
    vi /etc/fstab
  6. Press i to enter insert mode and change the disk identifier in the fstab file to UUID.
    Before the change:
    [root@CTU1000028010 ~]# cat /etc/fstab
    /dev/vda2  /       xfs     defaults    0 0
    /dev/vda1  swap    swap    defaults    0 0

    After the change:

    [root@CTU1000028010 ~]# cat /etc/fstab UUID=4eb40294-4c6f-4384-bbb6-b8795bbb1130  /       xfs     defaults  0 0
    UUID=2de37c6b-2648-43b4-a4f5-40162154e135  swap    swap    defaults    0 0
  7. Press Esc, enter :wq, and press Enter. The system saves the configuration and exits the vi editor.
  8. Verify the change.
    cat /etc/fstab

    The change is successful if information similar to the following is displayed:

    [root@CTU1000028010 ~]# cat /etc/fstab  UUID=4eb40294-4c6f-4384-bbb6-b8795bbb1130  /       xfs     defaults    0 0
    UUID=2de37c6b-2648-43b4-a4f5-40162154e135  swap    swap    defaults    0 0