Table of Contents

UUID Information


Be aware of UUID

UUID stands for Universally Unique IDentifier of a partition. This ID is used in few different places to identify the partition. Most commonly this would be /etc/fstab.

UUID vs PARTUUID

UUIDs are not hardware-specific but stored in the partition's filesystem. That means cloning a disk or partition with dd will result in the same UUID. However recreating the partitions manually on the new disk (e.g. smaller disk), will result in new UUID. This could result in problems when booting the new disk uses UUID in fstab.

cat /etc/fstab
# /etc/fstab: static file system information.
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda3 during installation
UUID=b2fa29ee-670f-4d44-becc-d9ec368d4a41 /               ext4    noatime,nodiratime,errors=remount-ro 0       1

This can be solved by either changing the entries in fstab to the old style: /dev/dbX, Or by getting the new UUID and update fstab accordingy. Or update the UUID of the partition manually with the methods below.

Check current UUID of the filesystem

To find of the current UUID of the filesystem you can use either of the below commands.

# blkid  /dev/sda3
/dev/sda3: UUID="1fa3df4b-0f8b-47f0-b72b-2790bf42d581" TYPE="ext4" PARTLABEL="Linux swap" PARTUUID="27215f75-2130-4398-891d-ba56be2990ba"

# blkid -p /dev/sda3
/dev/sda3: UUID="1fa3df4b-0f8b-47f0-b72b-2790bf42d581" VERSION="1.0" TYPE="ext4" USAGE="filesystem" PART_ENTRY_SCHEME="gpt" PART_ENTRY_NAME="Linux swap" PART_ENTRY_UUID="27215f75-2130-4398-891d-ba56be2990ba" PART_ENTRY_TYPE="0657fd6d-a4ab-43c4-84e5-0933c84b4f4f" PART_ENTRY_NUMBER="3" PART_ENTRY_OFFSET="40112128" PART_ENTRY_SIZE="70629376" PART_ENTRY_DISK="8:0"

# dumpe2fs /dev/sda3 | grep UUID
dumpe2fs 1.44.5 (15-Dec-2018)
Filesystem UUID:          1fa3df4b-0f8b-47f0-b72b-2790bf42d581

Change UUID of Filesystems

To do this, we are going to use tune2fs. The partition has to be unmounted prior apply the new UUID:

# umount /dev/sdb1

# tune2fs -U 94ddf54e-53f7-4a1a-bd2f-d0a01ee448d1 /dev/sdb1 
# tune2fs -U random /dev/sdb1   // for random generated UUID

Tune2fs is for ext2/3/4 filesystems. Swap is its own filesystem. To change a UUID on swap, recreate it with mkswap:

# mkswap -U <UUID>

Change PARTUUID in partition table

You can change the PARTUUID of a partition with gdisk. I'd recommend to read man gdisk first. In the following example I show how I changed the PARTUUID of the second partition on my first drive (sda):

$ sudo gdisk /dev/sda
[sudo] password for mook: 
GPT fdisk (gdisk) version 1.0.5

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): x                                       # enter x to change to experts menu

Expert command (? for help): c                                # enter c to change PARTUUID
Partition number (1-2): 2                                     # enter the number of the partition you want to change
Enter the partition's new unique GUID ('R' to randomize): r 
New GUID is 76349364-D66C-4C19-B422-237A0D2DB9F5

Expert command (? for help): m                                # enter m to go back to main menu

Command (? for help): w                                       # enter w to write the change to disk

Command (? for help): q                                       # enter q to exit gdisk
$