I wrote the following script to perform the recommended maintenance on Tumbleweed with btrfs running on a SSD. This is for a couple new installs so I don’t have much history of running it.
I decided to go for the manual route since I can follow what’s going on. It runs in about 25 sec here, so not much of a problem, at least until the drive goes way past the current 6% usage. Running once a fortnight seems a good schedule, and I can review everything in a single place.
Another relevant aspect is that individual tasks won’t interfere with each other, nor with a send/receive.
Currently it handles a single btrfs file system, but I plan on supporting any additional ones.
Hey Admin, Thanks for sharing this blog. I hope you will share more blogs like this. Keep blogging.You get here all the steps to fix 123.hp.setup issues.
Looking at your script and at this openSUSE SDB article https://en.opensuse.org/SDB:Disable_btrfsmaintenance, the switches and calls to balance as well as the scrub switch are different. Would you care to give a look and comment? Cheers.
Remove -(d/m)usage=0, because btrfs already handles this automatically since v3.18.
Remove -musage=3, because I’ve read somewhere this shouldn’t be done (not that it would crash on you, just don’t).
Remove -dusage=10, because I’ve plenty of space atm. YMMV
Scrub
btrfs scrub start -Bd /
This is simply a matter of how I want to consume the report. I have a single device, so no need for -d, and I want to see the result as soon as it’s done, otherwise a call to btrfs scrub status is necessary, so the -R.
On another note, I saw linux 5.6 brings the mount option discard=async, which is awesome and that’s when I’m gonna remove the fstrim call from the script.
Ah, another one, please: Your script, the btrfsmaintenance github https://github.com/kdave/btrfsmaintenance/blob/master/README.md, and the Arch Wiki mention scrub first, then balance. Only the openSUSE SDB has it the other way round. Haven’t checked the btrfs Wiki yet. Is there a rationale or recommendation as to the ordering?
Scrub checks if the file system can read from disk the same data that was written to it. I think it makes more sense running it before moving data around (balance). Every time a block is read from disk, its checksum is computed and compared. I understand that’s still the case if the block is to be relocated during a balance. If there’s a bit-flip in there, I don’t know how balance will deal with that, maybe it stops, or ignore the block. I’d prefer to handle it during a scrub. Good that you mention though, because I think my script will continue with the balance even in case scrub reports a checksum mismatch.