Changing the UUID of a disk or partition prevents conflicts when disks are cloned, swapped between machines, or attached alongside similar layouts. A unique identifier also keeps mount points stable when device names such as sda1 or sdb1 change after hardware modifications.

On Linux systems, mount configuration usually refers to partitions by UUID in /etc/fstab instead of by device name. The kernel and systemd read these identifiers during boot, match them to block devices, and mount filesystems at their configured locations.

Changing a filesystem identifier affects any configuration that refers to the old value, especially entries in /etc/fstab and bootloaders that rely on specific UUIDs. The procedure requires unmounting the filesystem, validating its integrity, assigning the new UUID, and updating configuration files to avoid unmountable filesystems or failed boots.

Steps to change disk or partition UUID in Linux:

  1. Open a terminal with sudo privileges.
    $ whoami
    user
  2. List block devices and locate the target partition by name, filesystem type, and existing UUID.
    $ lsblk -f
    NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
    sda                                                      
    ├─sda1 ext4         39ea80c4-e748-47eb-835c-64025de53e26 /
    ├─sda2 swap         7c6dbf99-0b77-4a3b-8b27-0de5e05f68f8 [SWAP]
    sdb                                                      
    └─sdb1 ext4  DATA  0f8b9a9a-3f0f-4e4e-b17b-0b1f37f3c3f4 /mnt/data
    ##### snipped #####

    lsblk with the -f option shows filesystem type, label, and UUID for each partition.

  3. Generate a new UUID value for the filesystem.
    $ uuidgen
    39ea80c4-e748-47eb-835c-64025de53e26

    uuidgen is normally installed by default on most Linux systems.

    Another random UUID can be read from /proc/sys/kernel/random/uuid.

    $ cat /proc/sys/kernel/random/uuid
    5c27b2b3-58f4-4469-a717-45865f517400
  4. Unmount the filesystem on the target partition so it can be modified safely.
    $ sudo umount /dev/sdb1

    Replace sdb1 with the actual partition identifier discovered in the listing step.

  5. Check the filesystem for errors before changing the UUID.
    $ sudo e2fsck -f /dev/sdb1
    e2fsck 1.46.5 (30-Dec-2021)
    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

    This step ensures the filesystem is consistent before applying a new UUID.

  6. Assign the new UUID value to the ext* filesystem with tune2fs.
    $ sudo tune2fs -U 39ea80c4-e748-47eb-835c-64025de53e26 /dev/sdb1
    tune2fs 1.46.5 (30-Dec-2021)
    Setting the UUID on this filesystem could take some time.
    Proceed anyway (or wait 5 seconds to proceed) ? (y,N) y

    tune2fs operates only on ext2, ext3, and ext4 filesystems; other types such as XFS or Btrfs require tools like xfs_admin or btrfs filesystem label for equivalent operations.

  7. Confirm that the partition now reports the new UUID.
    $ sudo blkid /dev/sdb1
    /dev/sdb1: UUID="39ea80c4-e748-47eb-835c-64025de53e26" TYPE="ext4" PARTUUID="2c6a7a3a-01"
  8. Update the matching entry in /etc/fstab so that it references the new UUID for the partition.
    $ sudoedit /etc/fstab
    /etc/fstab
    UUID=39ea80c4-e748-47eb-835c-64025de53e26 /mnt/data ext4 defaults 0 2
    ##### snipped #####

    Incorrect /etc/fstab entries can prevent the system from booting if they affect root or other essential filesystems.

  9. Reload fstab-controlled mounts to apply the updated configuration.
    $ sudo mount -a

    No output typically indicates that all mounts defined in /etc/fstab succeeded.

  10. Verify that the partition is mounted as expected with the new UUID.
    $ findmnt /dev/sdb1
    TARGET    SOURCE    FSTYPE OPTIONS
    /mnt/data /dev/sdb1 ext4   rw,relatime
Discuss the article:

Comment anonymously. Login not required.