Changing a file system UUID under Linux for a bcachefs file system.
According to the following table, it would be a common feature of file systems to allow the UUID to be changed retrospectively:
- https://gparted.org/features.php
The external UUID is relevant for the mount option UUID= and is recognised by tools such as blkid. The internal UUID is used for internal purposes (e.g. for device assignments). Unlike ext4 (where tune2fs -U random works) or Btrfs (where btrfs filesystem resize or similar tools help), bcachefs lacks a corresponding tune command for UUIDs.
How do you do this under Linux via the console? This information is needed so that this capability can be added to GParted for bcachefs.
For ext 4, you would probably do something like this:
To change the UUID of an ext4 file system using tune2fs, first ensure the file system is unmounted:sudo umount /dev/sdXY
Then verify the current UUID:
sudo blkid /dev/sdXY
Generate a new UUID:
sudo uuidgen
Finally, change the UUID: sudo tune2fs -U new_uuid_here /dev/sdXY
How do you do this in Linux via the console for bcachefs?
It may be possible to change the UUID under bcachef as follows (be carefull, maybe its wrong):
Manual superblock modification (not recommended for non-experts):
Bcachefs superblocks may be located at offset 4 KiB (primary), plus redundant copies.
Use hexdump or dd to read/write:
Read superblock:
sudo dd if=/dev/sdX bs=1 skip=4096 count=4096 | hexdump -C
The UUID fields are hexadecimal encoded (approx. bytes 0x100–0x110 for external UUID).
Generate a new UUID:
uuidgen
Write back:
echo -n ‘new-uuid-hex’ | dd of=/dev/sdX bs=1 seek=4096 conv=notrunc
I'm not really sure if the code example works this way, as I'm not a programmer and don't have any special knowledge of becachefs.
From my point of view, it seems sensible to provide such a function, e.g. via the bcachefs tools, so that end users who are not programmers have a robust way of using it and so that bcachefs-friendly projects such as GParted can integrate it.
Please add the option to change the UUID. THX
@Nihon-Ryori the super block has crc checks built in to detect partial writes and other issues that might arise, while that might replace the UUID, it would probably be detected as corruption.
if someone wants a quick and dirty method, it's probably best to just hard code the UUID in the superblock code in tools, and then run some sort of command that updates the super block (like toggling a file system option), even then I'm unsure if the full superblock is written or if it's just that specific field and the crc value.
I'd also really really recommend backing up your superblock before doing anything like this tho, infact, you should be able to run bcachefs-tools on a file of a copy of the superblock and see if it validates.
[@YellowOnion] the super block has crc checks ...
If there is more than one superblock, as is likely to be the case with dupe = 2 and some RAID-like variants, the other superblocks would also have to be replaced so that they have the same CRC value and are not corrected again by self-healing mechanisms.
It is possible that the solution for changing a UUID is similar to the solution for changing the label, as shown here:
- https://github.com/koverstreet/bcachefs/issues/933
Maybe the follow source give information about the count and position of bcachefs super blocks:
- https://bcachefs-docs.readthedocs.io/en/latest/ondiskformat.html