0

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?

Evan Carroll
  • 30,763
  • 48
  • 183
  • 315
  • Are you asking about the GPT PARTUUID or the filesystem UUID? If the latter, which filesystem? – muru Jul 31 '23 at 07:53
  • could also be the Disk identifier (GUID) (which sfdisk calls the label-id) – Jaromanda X Jul 31 '23 at 08:06
  • sfdisk has --disk-id option – Jaromanda X Jul 31 '23 at 08:09
  • You could just remove the UUIDs from the sfdisk dump before applying it on the new disk. – Paul Pazderski Jul 31 '23 at 08: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. – telcoM Jul 31 '23 at 08:21
  • @telcoM what about the disk identifier :p – Jaromanda X Jul 31 '23 at 08:23
  • Oops, forgot to clarify: Disk identifier seems to be another name for the PTUUID, at least on GPT disks. fdisk just calls it the "disk GUID". And unfortunately the OP did not specify which type of partition table the question is about - although the presence of NVMe devices makes GPT more likely. – telcoM Jul 31 '23 at 08:29
  • Was partition table so complicated that just manually recreating it was more complicated than trying to change UUIDs & GUIDs? And if drive not exactly same size, you also have to move backup partition table to end of drive, not sure if sfdisk does that with a copy or not. – oldfred Jul 31 '23 at 14:59

1 Answers1

0

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
Evan Carroll
  • 30,763
  • 48
  • 183
  • 315