News for hackers. Stuff that matters.
Re:Scripts for Btrfs Maintenance by xtracto on Tuesday June 06, 2023 @09:11PM (#36221465)
Just recently I had a worst-case nightmare scenario with a single BTRFS partition 5TB disk (no RAID or anything crazy). It was a single BTRFS disk, single partition external USB disk running under Linux Mint.

At some point after I restarted the computer and it wouldn't mount the partition saying that the path for mounting was already being used (even after restarting??), but the disk was not mounted. Searching around apparently there is some kind of bug where Linux will "cache" the BTRFS UUID [1].

At the time, the "solution" I read was to change the UUID of the BTRFS partition running btrfstune. Which I did... and it supposedly changed successfully. Except that after trying to mount the partition again, it will tell me that there was an error in the partition: the tree had mismatching UUIDs :-/. I tried updating the UUID several times, and the command ended in success, but the error remained. My BTRFS disk was officially broken...

After spending several hours trying to fix the issue following the BTRFS documentation (pretty shitty TBH), in the end, I ended up having to do `btrfs restore -iv ...` to extract the data from the disk into some other external disk (formatted NTFS this time!!). The command is still going, about 2 weeks later and I am slowly recovering my 5TB of data.

But the one thing clear to me is that I don't trust BTRFS or it's admin commands AT ALL after this experience. Once I finish recovering my data, I'll nuke the partition, format the disk in NTFS and forget about this sour experience.

[1] https://unix.stackexchange.com/questions/603528/why-am-i-get...

Re:Scripts for Btrfs Maintenance by bravetraveler on Tuesday June 06, 2023 @09:42PM (#36221712)
I can echo/support this claim - I wandered down the same rabbit hole.

It doesn't even get much better with many drives and avoiding the docs/tooling

BTRFS arrays will consistently corrupt with my reset button -- RAID10 on gen4 NVMe drives... while LVM/dm-raid + traditional file systems are absolutely fine

Re:Scripts for Btrfs Maintenance by xtracto on Tuesday June 06, 2023 @09:58PM (#36221867)
>BTRFS arrays will consistently corrupt with my reset button

YES!!! Sorry to beat a dead horse, but it has been so frustrating for me. I thought I did something wrong, like, how could the partition break for doing nothing! Where did I fucked up? I cannot imagine the experience with a RAIDed BTRFS array shudders

Re:Scripts for Btrfs Maintenance by phire on Tuesday June 06, 2023 @10:36PM (#36222159)
I had a BTRFS raid corrupt because one of my HDD had a firmware bug and was silently discarding writes.

Sure... HDDs shouldn't do that, but it's literally the job of a BTRFS raid to protect me from such issues. The data was all still intact on the other drive. I could see it with dd, but BTRFS refused to read it.

Re:Scripts for Btrfs Maintenance by curt15 on Tuesday June 06, 2023 @10:45PM (#36222236)
Isn't copy-on-write supposed to be inherently resilient to crashes[1]? Why would btrfs be more susceptible to resets than traditional filesystems?

[1]: https://unix.stackexchange.com/questions/634050/in-what-ways...

Re:Scripts for Btrfs Maintenance by bravetraveler on Wednesday June 07, 2023 @12:00AM (#36222667)
I doubt that because of the experience I just outlined

In theory perhaps, but absolutely not in practice. Making things atomic is tricky.

Re:Scripts for Btrfs Maintenance by londons_explore on Wednesday June 07, 2023 @05:47AM (#36224817)
I think most of the bugs are in the drives themselves - doing things like claiming data is flushed when it is not.

However, btrfs is a very fragile filesystem and any inconsistencies caused by the drive bugs tend to lead to it breaking and refusing to mount, whereas on other filesystems you'll just get a warning in dmesg.

It doesn't help that btrfs developers refuse to work around drive bugs.

Re:Scripts for Btrfs Maintenance by phire on Friday June 09, 2023 @11:20PM (#36267247)
> It doesn't help that btrfs developers refuse to work around drive bugs.

The entire selling point of the filesystem is that it's resilient to data corruption. Drive bugs are just another class of data corruption.

Re:Scripts for Btrfs Maintenance by yrro on Wednesday June 07, 2023 @09:36AM (#36226628)
> BTRFS arrays will consistently corrupt with my reset button

I know you don't want to get asked this, and I wouldn't if you'd just said "I tried this once a while ago and it happened", but if it's consistent... have you filed a bug?

Re:Scripts for Btrfs Maintenance by bravetraveler on Wednesday June 07, 2023 @10:24AM (#36227169)
It's a fair ask! I don't mind.

It's occurred to me, but I expect a fair bit of push back; 'you abuse the array and expect it to what?'

I'm not really interested in debating that - I know expecting coherency in this situation is a little silly, but BTRFS is notably less reliable

Avoiding a situation that may or may not occur, by not participating. Not saying it's a good thing, but it's easier for me to just use What Works

Re:Scripts for Btrfs Maintenance by yrro on Wednesday June 07, 2023 @11:41AM (#36228292)
With properly functioning hardware (i.e., that doesn't lie to you when it says "that has been committed to durable storage") then metadata or data corruption following power loss is definitely a bug! It didn't even occur to me that you might get a different response.

I'd be kind of annoyed if I went to the trouble of reporting a bug and got that response. But I'd also not assume it would end that way...

Re:Scripts for Btrfs Maintenance by bravetraveler on Wednesday June 07, 2023 @01:05PM (#36229723)
With where we're at with SSDs chasing the performance dragon... I suspect some deception is at play!

The DRAM caches are pretty hefty compared to metadata, so I wouldn't be surprised - though that's about my extent of understanding.

Even then, though - other filesystems are certainly more durable, dealing with whatever these drives are doing.

FWIW, this was with four Sabrent Rocket 4.0 Plus drives in RAID10 with 4K sectors. I'm not sure if these are particularly well known one way or another for deception/trickery

They hold up just fine with either dm-raid or native LVM raid10 under more traditional filesystems (I tested EXT4/XFS, using the latter consistently)

Re:Scripts for Btrfs Maintenance by Arnavion on Wednesday June 07, 2023 @02:25AM (#36223540)
>Searching around apparently there is some kind of bug where Linux will "cache" the BTRFS UUID [1].

It's not a bug. It's just a fact that every BTRFS filesystem visible to the kernel (mounted or not) should have a unique ID. Otherwise operations on one filesystem (including mounting the partition that contains it) can end up applying to the other filesystem.

>At the time, the "solution" I read was to change the UUID of the BTRFS partition running btrfstune.

The solution would've been to find out why you have two partitions with the same filesystem ID and remove one of them. One example is that if you have the BTRFS filesystem on an LVM partition and then you clone the LVM partition, you end up with two BTRFS filesystems with the same ID. I accidentally encountered it while converting an unencrypted BTRFS parition into an encrypted one by dd'ing it into a new LUKS device - when I tried to mount the encrypted partition it ended mounting the unencrypted one.

Since you say it's an external USB drive, perhaps it disconnected and reconnected uncleanly and the kernel thought there were two of that drive connected at the same time.

Re:Scripts for Btrfs Maintenance by londons_explore on Wednesday June 07, 2023 @05:43AM (#36224792)
Sounds like a kernel bug ... If it encounters another filesystem with the same ID, it should warn in dmesg and assign a null ID to one of them.
Re:Scripts for Btrfs Maintenance by _flux on Wednesday June 07, 2023 @07:40AM (#36225571)
If it was this simple, they'd have done it, right? The idea is that filesystems have have the same UUID are actually part of the same filesystem. It's a long-lasting hm feature of Btrfs.

I think the actual dynamic filesystem discovery is in user space and kernel just gets a list of devices, so it should be even easier to change that.

Re:Scripts for Btrfs Maintenance by thrtythreeforty on Wednesday June 07, 2023 @09:33AM (#36226587)
That's fine but we can have a "device UUID" and "filesystem UUID" as separate constructs and then the complaint remains valid. It's okay for it to fail if you dd and try to mount (suboptimal, but okay), but it should never silently start breaking things while appearing to work.
Re:Scripts for Btrfs Maintenance by _flux on Wednesday June 07, 2023 @09:58AM (#36226859)
Btrfs already has separate fsid and device id. Anyway, if you clone the device then those also stay the same, so I'm not sure what this would solve. How would the complete solution look like?

AFAIK the filesystem UUID, the device UUID, or both are sprinkled all around the filesystem, I suppose for reasons of identifying data belonging to the fs in case of fsck. According to my quick research device id cannot be changed. I suppose if it could be changed by some means, then btrfs rescue clear-uuid-tree could be used to fix the other uuids.

Re:Scripts for Btrfs Maintenance by bandrami on Wednesday June 07, 2023 @06:37AM (#36225113)
Indeed, before we had FS UUIDs the kernel would simply mount partitions at random, there being no other possible way to distinguish one filesystem from another. It was a wild time.
Re:Scripts for Btrfs Maintenance by tbrownaw on Wednesday June 07, 2023 @07:25AM (#36225489)
> It's not a bug. It's just a fact that every BTRFS filesystem visible to the kernel (mounted or not) should have a unique ID.

Maybe it's not a code bug, but imposing global uniqueness requirements where you can't just `cp /dev/blkdev1 myfs.img` and be able to work with the new image seems rather like a design bug.

Re:Scripts for Btrfs Maintenance by yrro on Wednesday June 07, 2023 @09:35AM (#36226612)
It seems like a bit of a tall order to expect this to work with a multi-device filesystem. To the kernel it looks like a second multipath connection to the same disk just appeared; how should it handle this? Refusing to mount the cloned block device looks sensible.

While not a multi-device filesystem, I believe XFS has the same behaviour and you have to change the UUID (or use xfs_copy in the first place) before you can mount a cloned block device.

(I wonder how ZFS handles this?)

Re:Scripts for Btrfs Maintenance by MaKey on Wednesday June 07, 2023 @03:28AM (#36223931)
I'm not sure you can fault BTRFS for the issue you've experienced. It sounds like your system had a problem which lead to you breaking your (likely perfectly fine) BTRFS file system.
Re:Scripts for Btrfs Maintenance by omniglottal on Wednesday June 07, 2023 @07:58PM (#36235343)
A filesystem breaks by the user pushing a button on their computer and you blame the user...?!
Re:Scripts for Btrfs Maintenance by MaKey on Thursday June 08, 2023 @12:51PM (#36244937)
He had trouble mounting it on his system because of a duplicate UUID - this doesn't mean that the filesystem was broken. As Arnavion wrote:

> Since you say it's an external USB drive, perhaps it disconnected and reconnected uncleanly and the kernel thought there were two of that drive connected at the same time.

Re:Scripts for Btrfs Maintenance by _flux on Wednesday June 07, 2023 @07:49AM (#36225642)
Surely this incident highlights the importance of backups, right? 5 TB is even a manageable amount of data.

I also used to run btrfs in btrfs-RAID10 configuration until apparently a flapping SATA link and fsck attempts were able to break the fs completely. Full system backups were great that day. I run https://kopia.io/ nowadays every three hours during day time and I've been quite happy with it.

Nowadays I run bcachefs.. Backups are still handy :).

I suppose the reason why you chose NTFS was to be able to access the data from Windows, at least in case of emergency? Because there are a lot of filesystems that are presumably more mature than NTFS is for Linux.

Re:Scripts for Btrfs Maintenance by xtracto on Wednesday June 07, 2023 @10:34AM (#36227296)
The finny thing is that , THAT is my backup drive, mostly. It has lots of crap, including GB synced from Google Drive (photos being the mos important). Other than that, it's stuff I could re-download from elsewhere, but 3TB is a lot to re-download. Aah yeah and it also has the TimeHift backups.

I thought of going EXT4 , but as you said, NTFS is more widely supported.

Re:Scripts for Btrfs Maintenance by generalizations on Tuesday June 20, 2023 @11:19AM (#36405267)
That doesn't even sound like a BTRFS problem; I recently (couple weekends ago) had the same UUID cache problem with an XFS partition.