How to create new uuid for external drive

Greetings all!
I’m running the current version of EndeavourOS on my System76 OryxPro.
I cloned my entire system to an external drive using Rescuezilla which worked fine and I can boot into that drive with no problems.

What I would prefer to do now, however, is to be able to mount that drive every few days or so while I’m running my main system and sync (with rsync) any updated files to that drive so that I always have an up-to-date system ready to go in case of a main drive failure.

Since the second drive is an exact clone of my main drive, it also has the same UUID which prevents me from mounting it while running the main system. Does anyone know how to change the UUID on the external drive so that it can be mounted? Many thanks!

Welcome to the forum. Is the filesystem on your drive ext4?

If so, it can easily be done with tune2fs

tune2fs <device_filename> -U <new_uuid>

Where <device_filename> is something like /dev/sda1, corresponding to the drive… You can use the uuidgen command to generate a new UUID.

Make sure to have a backup of all important data, just in case something goes wrong. That should go without saying.

I don’t know how to do it on Brtfs.

7 Likes

Gee, you learn something everyday. Never heard of tune2fs before today.

man page

https://www.man7.org/linux/man-pages/man8/tune2fs.8.html

Pudge

2 Likes

This is kind of nit picky, but I have never seen a UUID for a storage device itself. The device usually has a device name i.e. /dev/sda but no UUID.

Partitions such as /dev/sda1 do have UUIDs which are assigned during formatting the partition. So you will need to mount more than one partition to update the entire SSD.

Pudge

EDIT:
The storage device does have a name. Do the following to display the device name

ll -l /dev/disk/by-id
ata-Samsung_SSD_840_PRO_Series_SerialNumbeR -> ../../sda
lrwxrwxrwx 1 root root 10 Jul 17 10:31 ata-Samsung_SSD_840_PRO_Series_SerialNumbeR-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Jul 17 10:31 ata-Samsung_SSD_840_PRO_Series_SerialNumbeR-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Jul 17 10:31 ata-Samsung_SSD_840_PRO_Series_SerialNumbeR-part3 -> ../../sda3

It will display the name of the storage device and usually the Serial Number of the Drive

Do the following to display the uuid

ls -l /dev/disk/by-uuid
lrwxrwxrwx 1 root root 10 Jul 17 10:31 XXXXXXXX-XXXX-XXXX-XXX-XXXXXXXXXXXX -> ../../sda2
lrwxrwxrwx 1 root root 10 Jul 17 10:31 58C3-7B6B -> ../../sda1
lrwxrwxrwx 1 root root 10 Jul 17 10:31 XXXXXXXX-XXXX-XXXX-XXX-XXXXXXXXXXXX -> ../../sda3

Notice that partition one is FAT32 so it has a different UUID than the ext4 partitions.

1 Like

Greetings and thanks to all for the suggestions. They were most helpful! One problem I ran in to was luks encryption:

❯ sudo tune2fs /dev/sda2 -U f15ad81b-a169-411a-b428-f78900611728
[sudo] password for someUser:
tune2fs 1.47.0 (5-Feb-2023)
tune2fs: Bad magic number in super-block while trying to open /dev/sda2
/dev/sda2 contains a crypto_LUKS file system

I came across these two articles that dealt specifically with changing the UUID on an encrypted system:

For the sake of clarity, here are the partitions on my main drive (not my real UUIDs!):

NVME1:
Contents: FAT (32-bit version) — Mounted at /efi
Device:   /dev/nvme1n1p1
UUID:     C427-BCCA
Partition Type: EFI System

Contents:  LUKS Encryption (version 1) — Unlocked
Device:    /dev/nvme1n1p2
UUID:      38e2598f-7849-47b2-9e79-887daef783b8
Partition Type: Linux Filesystem

Contents:  Ext4 (version 1.0) — Mounted at Filesystem Root
Device:    /dev/mapper/luks-38e2598f-7849-47b2-9e79-887daef783b8
UUID:      bd59ec6f-4b62-4596-bc79-3fa79cd08f8e
Partition Type:

and my cloned external drive before changing the UUID
(Realtek at /dev/sda):

Contents: FAT (32-bit version) — Mounted at /efi
Device:   /dev/sda1
UUID:     C427-BCCA
Partition Type: EFI System

Contents: LUKS Encryption (version 1) — Unlocked
Device:   /dev/sda2
UUID:     38e2598f-7849-47b2-9e79-887daef783b8
Partition Type: Linux Filesystem

Contents: Ext4 (version 1.0) — Mounted at Filesystem Root
Device:   /dev/mapper/luks-38e2598f-7849-47b2-9e79-887daef783b8
UUID:     bd59ec6f-4b62-4596-bc79-3fa79cd08f8e   
Partition Type: Linux Filesystem

I booted into my main operating system and connected the external drive attached via a usb port. I ran Disks (Gnome) to verify its location (the encrypted drive was on /dev/sda2) and ran the following command:

sudo cryptsetup luksUUID --uuid=bd0c7f08-5957-41aa-91ab-015a8df421fb /dev/sda2

which generated the following:

WARNING!
========
Do you really want to change UUID of device?

Are you sure? (Type 'yes' in capital letters): YES

This worked. The external drive is now visible from my main system’s file manager (Nemo) and has the UUID entered in the above command. Clicking on it asked for the encryption password which upon verification now gives me access from my main system to all the directories and files on the external drive. I can now use rsync to easily sync new or changed files on my main system with the identical one on the external drive. The external drive is also still bootable in case I screw up my main system (again).

Note that I only changed the UUID for the encrypted drive (/dev/sda2) since that is where all the files are that I wanted to access. I don’t know if it is necessary to change the other UUIDs or not.