tencent cloud

Feedback

Setting the Fstab Disk Identification Method to UUID

Last updated: 2024-01-08 09:37:01

    Operation Scenario

    To guarantee correct disk recognition by the Linux system during file system mounting, please inspect and correctly set the fstab file disk identification method.
    The file system table (fstab) is a configuration file in the Linux system that stores file system mounting information. Typically, the /etc/fstab file supports the use of device names (such as /dev/vda1) to identify file systems. However, device names may change due to the change in the actual operating environment after an image is imported, so there may be some problems using device names to identify file systems. To avoid these problems, you can change the file system identification method in the /etc/fstab file to UUID. The UUID is a unique characteristic string that identifies a disk partition and won't be affected by the change in device names. Using a UUID as the fstab file disk identification can ensure that the system can still correctly mount the file system when the device name changes.

    Setting the Fstab Disk Identification Method to UUID

    Confirming the Current Configuration of Fstab

    Run the following command to view the current configuration method.
    sudo cat /etc/fstab
    If the output resembles the following one, with the first column beginning with UUID, it indicates that the current fstab is configured using the UUID method.
    UUID=c0b9ecd8-f922-4e5d-bccb-83fbc94ad23b / ext4 defaults 1 1
    If the output resembles the following one, with the first column beginning with the block device name (such as /dev/vda1), it indicates that the current fstab is using a device name. You can refer to the subsequent operation to switch to the UUID method.
    /dev/vda1 / ext4 defaults 1 1

    Obtaining the UUID

    To obtain the UUID of a partition, the blkid command can be used. Running the blkid command will display the detailed information of all the available partitions including the UUIDs. Run the following command in the terminal:
    sudo blkid
    The output similar to the following one indicates that the associated UUID of the device /dev/vda1 is c0b9ecd8-f922-4e5d-bccb-83fbc94ad23b.
    /dev/vda1: UUID="c0b9ecd8-f922-4e5d-bccb-83fbc94ad23b" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="bcfcb5cb-01"

    Modifying fstab

    1. Backup the current /etc/fstab file to the /home directory.
    sudo cp /etc/fstab /home
    2. Use the vi editor to open the /etc/fstab file.
    sudo vi /etc/fstab
    3. Edit the configurations beginning with device names in the fstab file. Change device names to the UUID=xxx format. The content after UUID= is the UUID value corresponding to the device returned by running the blkid command.
    # Before modification
    /dev/vda1 / ext4 defaults 1 1
    # After modification
    UUID=c0b9ecd8-f922-4e5d-bccb-83fbc94ad23b / ext4 defaults 1 1
    4. Press Esc to enter :wq. Press Enter to save the configuration and exit the editor.
    5. (Optional) Run the following command to ensure that the modification has been successfully saved.
    sudo cat /etc/fstab
    If the following content is returned, it indicates the modification has been saved successfully.
    UUID=c0b9ecd8-f922-4e5d-bccb-83fbc94ad23b / ext4 defaults 1 1
    6. (Optional) Run the following command. If no errors are returned, it means that the configuration has been successfully performed in accordance with the UUID method.
    sudo mount -a
    7. (Optional) Delete the backup fstab file in the /home directory.
    If the modification to UUID identification failed, the system can be restored to the original state by restoring the fstab file.
    sudo mv /home/fstab /etc/fstab
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support