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:
- Open a terminal with sudo privileges.
$ whoami root
- List block devices and locate the target partition by name, filesystem type, and existing UUID.
$ lsblk -f NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS loop0 ext4 1.0 data 12fc1902-80ea-4b6b-bb14-f0f0df4d994b 906.2M 0% /mnt/data loop1 ext4 1.0 mountdemo 44518380-11db-4f05-8785-f92c04283278 loop2 ext4 1.0 uuiddemo d2b28f4c-5458-4117-9f27-76a8158a35df nbd0 nbd1 nbd2 nbd3 nbd4 nbd5 nbd6 nbd7 vda `-vda1 ext4 1.0 0f29d829-7b21-4784-8807-a473ed0d4528 1.7T 1% /etc/hosts /etc/hostname /etc/resolv.conf vdb erofs ab937823-7fcd-4a20-bf31-2ddb0fb68612 nbd8 nbd9 nbd10 nbd11 nbd12 nbd13 nbd14 nbd15lsblk with the -f option shows filesystem type, label, and UUID for each partition.
- Generate a new UUID value for the filesystem.
$ uuidgen 3d3133d9-8a20-4903-b2ed-05a72b7ecb9a
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 cc981e52-711d-4a74-8915-9eee31b45840
- Unmount the filesystem on the target partition so it can be modified safely.
$ sudo umount /dev/loop2
Replace loop2 with the actual partition identifier discovered in the listing step.
- Check the filesystem for errors before changing the UUID.
$ sudo e2fsck -f /dev/loop2 e2fsck 1.47.0 (5-Feb-2023) 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 uuiddemo: 11/65536 files (0.0% non-contiguous), 8268/65536 blocks
This step ensures the filesystem is consistent before applying a new UUID.
- Assign the new UUID value to the ext* filesystem with tune2fs.
$ sudo tune2fs -U 3d3133d9-8a20-4903-b2ed-05a72b7ecb9a /dev/loop2 tune2fs 1.47.0 (5-Feb-2023)
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.
- Confirm that the partition now reports the new UUID.
$ sudo blkid /dev/loop2 /dev/loop2: LABEL="uuiddemo" UUID="3d3133d9-8a20-4903-b2ed-05a72b7ecb9a" BLOCK_SIZE="4096" TYPE="ext4"
- Update the matching entry in /etc/fstab so that it references the new UUID for the partition.
$ sudoedit /etc/fstab
/etc/fstab UUID=3d3133d9-8a20-4903-b2ed-05a72b7ecb9a /mnt/uuiddemo ext4 defaults 0 2 ##### snipped #####
Incorrect /etc/fstab entries can prevent the system from booting if they affect root or other essential filesystems.
- Reload fstab-controlled mounts to apply the updated configuration.
$ sudo mount -a
No output typically indicates that all mounts defined in /etc/fstab succeeded.
- Verify that the partition is mounted as expected with the new UUID.
$ findmnt /dev/loop2 TARGET SOURCE FSTYPE OPTIONS /mnt/uuiddemo /dev/loop2 ext4 rw,relatime
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.
