How-to Change UUID Of A Disk

When cloning or restoring disk volumes is possible to run into problem which conflicting UUID values. Each disk volume needs to be assigned a unique UUID. The UUID is store on the volume. A cloned or restored disk will have the same UUID as volume from which it was generated.

By default you are not allowed to mount two volumes with the same UUID. This can overcome with the “nouuid” mount option:

mount -o nouuid /dev/xvdg1 /mnt

Often a server will be configured to select the root partition on boot by UUID. This makes is easy to ensure that the right volume is selected as the root. But if you have two volumes with the same UUID then the kernel will randomly select which volume to mount. This situation can occur when you’ve mounted a cloned or restored copy of the root volume and then reboot without removing the clone.

To list the UUID of all devices use the “blkid” command:

# blkid
/dev/nvme0n1p1: LABEL="cloudimg-rootfs" UUID="7cd9f6d2-bc78-4a5c-a12a-XXXXXXXX"                                                                       72" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="92323da4-8b16-40b7-9640-XXXXXXX"                                                                       

A new unique UUID can be generated with the “uuidgen” command:

# uuidgen
287d622b-f7d2-4ef8-a266-XXXXXXXX 

The UUID of an XFS volume can be changed with:

# xfs_admin -U 287d622b-f7d2-4ef8-a266-XXXXXXXX /dev/nvme4n1p2 

Or let xfs_admin handle generating the new UUID:

xfs_admin -U generate /dev/xvdg1 

For ext2/3/4 the tune2fs command can be used:

uuidgen
287d622b-f7d2-4ef8-a266-XXXXXXXX
tune2fs /dev/xvdg1 -U 287d622b-f7d2-4ef8-a266-XXXXXXXX

Or in a single line:

uuidgen | xargs tune2fs /dev/xvdg1 -U

WARNING: Changing the UUID of an actively mounted disk volume can have unpredictable effects. Always work on unmounted volumes.

Have a project or a problem?

Talk with a senior engineer for practical recommendations—no obligation.

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Categories

Get a free consultation from Reliable Penguin

Submit the form—or for immediate service call 866-649-7984.