1

I just used sfdisk to clone my partition table to a new disk,

sudo sfdisk -d /dev/nvme0n1 > /tmp/part.txt
sudo sfdisk /dev/nvme1n1 <  /tmp/part.txt

However, now both drives have the same uuid. How can I fix that and generate a new UUID for device with the cloned partition table?


The number that are duped can be seen with sudo fdisk -l. You can see the "523436E9-4DA5-474F-87CA-D784E4BF345D" is shared as a common "Disk identifier"

Disk /dev/nvme1n1: 1.82 TiB, 2000398934016 bytes, 3907029168 sectors
[...]
Disklabel type: gpt
Disk identifier: 523436E9-4DA5-474F-87CA-D784E4BF345D
[...]


Disk /dev/nvme0n1: 1.82 TiB, 2000398934016 bytes, 3907029168 sectors
[...]
Disklabel type: gpt
Disk identifier: 523436E9-4DA5-474F-87CA-D784E4BF345D

You can also see a shared UUID with,

❯ lsblk -o +uuid
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS UUID
nvme1n1     259:0    0  1.8T  0 disk             
├─nvme1n1p1 259:2    0  512M  0 part             
└─nvme1n1p2 259:3    0  1.8T  0 part             7d78ed4b-e4aa-4270-853d-6489ea4d6c54
nvme0n1     259:1    0  1.8T  0 disk             
├─nvme0n1p1 259:4    0  512M  0 part /boot/efi   1D40-E385
└─nvme0n1p2 259:5    0  1.8T  0 part /           7d78ed4b-e4aa-4270-853d-6489ea4d6c54

On the partition "7d78ed4b-e4aa-4270-853d-6489ea4d6c54" is shared?

8
  • Are you asking about the GPT PARTUUID or the filesystem UUID? If the latter, which filesystem? Commented Jul 31, 2023 at 7:53
  • could also be the Disk identifier (GUID) (which sfdisk calls the label-id) Commented Jul 31, 2023 at 8:06
  • sfdisk has --disk-id option Commented Jul 31, 2023 at 8:09
  • You could just remove the UUIDs from the sfdisk dump before applying it on the new disk. Commented Jul 31, 2023 at 8:13
  • This question includes answers on how to change the PARTUUIDs and the PTUUID using fdisk, and also how to change the UUIDs of many filesystem types. Commented Jul 31, 2023 at 8:21

1 Answer 1

1

The device identifier UUID

I was able to change the UUID of disk with sfdisk,

sudo sfdisk --disk-id /dev/nvme1n1 $(uuidgen)
Disk identifier changed from 523436E9-4DA5-474F-87CA-D784E4BF345D to E15A552B-CD07-4332-B73C-E67765D11F4E.

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Partition UUIDs

In order to give the partitions a new UUID with

sudo btrfstune -f -U $(uuidgen) /dev/nvme1n1p2

I had to first take the device offline by removing it from the raid1 array -- which because there were only two disks required first removing raid1,

sudo btrfs filesystem balance start -dconvert=single -mconvert=dup

Then I was able to remove the device,

sudo btrfs device remove /dev/nvme1n1p2 / 

Then I had to create a btrfs filesystem on the device so I could use btrfstune

sudo mkfs.btrfs /dev/nvme1n1p2

Then I could change the partition uuid,

sudo btrfstune -f -U $(uuidgen) /dev/nvme1n1p2

But lsblk -o +uuid does not show the partition (nvme1n1p2)'s uuid, so I'm not sure what exactly is going on,

lsblk -o +uuid
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS UUID
nvme1n1     259:0    0  1.8T  0 disk             
├─nvme1n1p1 259:2    0  512M  0 part             
└─nvme1n1p2 259:3    0  1.8T  0 part             
nvme0n1     259:1    0  1.8T  0 disk             
├─nvme0n1p1 259:4    0  512M  0 part /boot/efi   1D40-E385
└─nvme0n1p2 259:5    0  1.8T  0 part /           7d78ed4b-e4aa-4270-853d-6489ea4d6c54

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.