In Linux, disk partitions must be mounted to access the data stored on them. Mounting using a UUID (Universally Unique Identifier) is a reliable method because the UUID remains consistent, even if the device name changes. This approach ensures that the correct partition is always mounted, which is particularly useful in systems with multiple storage devices.

Using UUID prevents conflicts that can occur with device names or labels. Device names can change based on detection order or hardware configuration, but the UUID is unique and stable. This makes it a preferred choice for mounting partitions, ensuring system stability and data integrity.

To mount a partition using UUID in Linux, you need to find the UUID, create a mount point, and update the fstab file for persistent mounting. This process involves a few simple steps that ensure the partition is correctly mounted and available each time the system boots.

Steps to mount disk partitions by UUID in Linux:

  1. Open the terminal.
  2. Find the UUID of the partition you want to mount (or assign a UUID to the partition if it doesn't have one).
    $ sudo blkid

    The command above lists all partitions with their corresponding UUID.

  3. Create a directory to serve as the mount point.
    $ sudo mkdir -p /mnt/uuidtest
  4. Temporarily mount the partition using its UUID.
    $ sudo mount UUID=39ea80c4-e748-47eb-835c-64025de53e26 /mnt/uuidtest 
  5. Unmount the partition after testing.
    $ sudo umount /mnt/uuidtest
  6. Open the /etc/fstab file in a text editor.
    $ sudo vi /etc/fstab
  7. Add an entry in /etc/fstab with the UUID and mount point.
    UUID=39ea80c4-e748-47eb-835c-64025de53e26       /mnt/uuidtest   ext4    defaults          0    1

  8. Remount the partition using the updated /etc/fstab entry.
    $ sudo mount -a

    This command mounts all filesystems listed in the /etc/fstab file, including the one you just added.

Discuss the article:

Comment anonymously. Login not required.