In most major Linux distributions, UUIDs (Universally Unique Identifiers) are created and assigned to disk partitions during the system installation process. These UUIDs are then utilized as identifiers to mount partitions within the /etc/fstab file. This system provides a static reference to partitions, addressing the issue of potential device name changes that could invalidate the fstab entry and prevent the filesystem from mounting.

You can generate and assign UUIDs for newly created partitions or modify the UUIDs of existing partitions in Linux using the terminal.

Steps to generate and assign a disk partition UUID in Linux:

  1. Open the terminal application.
  2. Generate a new UUID by running the uuidgen command.
    $ uuidgen

    uuidgen is normally installed by default in most Linux systems.

    You can also get UUID from /proc/sys/kernel/random/uuid.

    $ cat /proc/sys/kernel/random/uuid
  3. Ensure that the partition you want to assign the UUID to is unmounted.
    $ sudo umount /dev/sdb1
  4. Perform a filesystem check on the target partition.
    $ sudo e2fsck -f /dev/sdb1
    e2fsck 1.44.6 (5-Mar-2019)
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Checking reference counts
    Pass 5: Checking group summary information
    /dev/sdb1: 11/1310720 files (0.0% non-contiguous), 126322/5242624 blocks
  5. Use the tune2fs command to assign the new UUID to the partition.
    $ sudo tune2fs /dev/sdb1 -U 39ea80c4-e748-47eb-835c-64025de53e26
    tune2fs 1.44.6 (5-Mar-2019)
    Setting the UUID on this filesystem could take some time.
    Proceed anyway (or wait 5 seconds to proceed) ? (y,N) y
  6. Verify that the UUID has been successfully assigned to the partition.
    $ sudo blkid /dev/sdb1
    /dev/sdb1: UUID="39ea80c4-e748-47eb-835c-64025de53e26" TYPE="ext4" PARTUUID="2c6a7a3a-01"
Discuss the article:

Comment anonymously. Login not required.