Hello,

TL;DR: Use filesystem labels. This is the sort of thing they're for.

On Sun, Nov 12, 2023 at 06:55:33PM +0100, Hans wrote:
> However, after generating the stick the UUID of the first partition 
> (/dev/sdc1) 
> is changing, so next time, the script will not work again, of course.

Do you literally mean a GPT PARTUUID? Or do you mean a filesystem
UUID?

GPT partitions can also have a user-specified name. This is rarely
used.

MBR labels have a disk identifier which is incremented for each
partition, so disk with MBR partitions can also have PARTUUIDs. This
is really rarely used.

> But does the UUID also change of the device itself? Does the UUID of /dev/sdc 
> change, too?

Devices don't have a UUID (except that disk identifier for MBR as
mentioned). GPT partitions do have a PARTUUID. And the filesystem on
them does also have a UUID. So sdc being a disk not a partitions,
won't have a PARTUUID but could have a filesystem UUID if you put a
filesystem on it.

> I would like to work with UUID, as I never know, if the USB-stick I put in is 
> /dev/sdb or /dev/sdc. Thus UUID would be my favourite solution, but this 
> would 
> of course only work, if the device UUID after dd will not change.

UUIDs are meant to be unique, thus on filesystem creation they will
be random, and anything that copies the filesystem will copy around
the UUID as well because it's a property of the filesystem.

For your use case you will be wanting to use the relevant
filesystem-specific tool to write an fs label that you choose. Often
this can be done at mkfs time, but there should also be a tool to
query/change thre fs label afterwards as well. For ext* filesystems,
that tool is "e2label".

You can mount by label and also add an fstab entry by label.

Here is a fairly exhaustive discussion of your options:

    https://wiki.archlinux.org/title/fstab

If you meant GPT PARTUUIDs and absolutely insist on setting a
PARTUUID to a known value instead of just accepting the random one
that is picked at the time the GPT label is created, you can do it.
e.g. with gdisk:

    https://askubuntu.com/a/1250232/19809

Thanks,
Andy

-- 
https://bitfolk.com/ -- No-nonsense VPS hosting

Reply via email to