Difference between revisions of "Btrfs"

4,827 bytes added ,  2 years ago
first scrub
(added warning out of space)
(first scrub)
Line 183: Line 183:


= Btrfs maintenance =
= Btrfs maintenance =
Btrfs needs maintenace like every filesystem. The more you use advanced features of btrfs, the more you have to watch for the right maintenance.
=== fragmentation ===
Files on btrfs tend to get somewhat fragmented, when they are appended or changed often. If you use a mechanical disk with slow seeks, it may be advisable to defragment some heavy used files from time to time (like once in a month). When the files are only written to, or are only read seldom, '''don't worry'''.
==== databases ====
It may be good to defragment a database if there is a ''noticeable'' slowdown when using it.
==== logfiles ====
It may be good to defragment a logfile, if there is a ''noticeable'' slowdown when booting your system.


== balance ==
== balance ==
When adding devices or changing the RAID-level of your volume, it may be necessary to balance your volume. While balancing, btrfs will read ALL (or a subset of all) '''chunks''' in, and write them out again using the actual RAID-level. It will stripe these files over all available devices equally. While this happens, the volume will keep being usable, but you may see some '''heavy load''' on it. Also '''this may take a very long time''' because '''ALL data must be''' read AND '''written''' again.
Don´t worry about shutdown. When you shutdown your computer while the balance is running, the balance will pause. After you restart the computer the balance will restart and continue until it is finished.
=== filters ===
Because a complete balance may take a long time, ther is the possibility of filters in balance. When using a filter only those chunks will be balanced, that are named by the filter.
=== merging chunks ===
As you use your volume, you will be creating some files, deleting some, modifying some. Then some parts of the chunks are empty. But this is not a coherent space that can be easily reused. Usually this is not a problem for btrfs and will be cleaned up automatically over time. However, if space is scarce (> 80% full), it is advisable to merge free areas together. This can be done by using balance with a filter.
=== after removing a device ===
When you remove a device from a volume, btrfs will automatically balance all "chunks" that where on the removed device. These chunks are placed on another device of the volume. So you don't need to balance by yourself after removing a device.
=== after adding a device ===
When you add a device there will be no automatic balance. Only when further using the volume, btrfs will use the additional free space according to the actual RAID-level.
=== after changing RAID-level ===
When you changed RAID-levels (for example from RAID 0 to RAID 1) there is no automatic duplication of the chunks. Only when writing further, btrfs will respect the changed RAID-level. This may not be what you intended. To complete the conversion to another RAID-level you need to tell btrfs to rewrite chunks where needed. You do this with a manual balance:
btrfs filesystem balance


== scrub ==
== scrub ==
A scrub of a btrfs volume is like inspecting your home. Does the light work in every room? Is the battery of a smoke alarm empty? Does the fire extinguisher need to be replaced? Is any faucet dripping?
Every now and then it is advisable to look for such things. And fix it right away!
==== check & repair on the fly ====
Every time btrfs reads a file, it checks the corresponding checksums. When btrfs is in RAID 0 and detects a 'damaged' file, it only can tell you that the file is damaged. You may delete it, or replace it from your backup.
When running in RAID 1 btrfs has 2 copies of every file. So if one file seems to be damaged, btrfs will read the other copy. If this other copy is ok, btrfs will automatically create another good copy of the file, and then afterwards delete the defect copy. You won't even notice this ''''automatic' repair.'''
==== full check ====
Sometimes you may want to check ALL files, and to get a report of defects, because:
* Some files are read very seldom, and you don't want "bitrott"
* You want to check your data completely for any faults
* Once in a while you want to make sure all is well
* You want to force your disk/device to verify all data
* ...
This is when you use btrfs scrub. Scrub will read ALL data of your complete volume. While this is done, all files and metadata will be checked by the checksums and all problems will be reportet. Because this will read and verify your complete volume (eventually a few Terra-byte), it may take some time. Scrub will not waste time in checking unused chunks.
While checking you can enable automatic repair for RAID 1 or disable it. If you disable automatic repair, scrub will work completely readonly, and will change nothing on your volume.
Scrub can be done automatically(for example every week), or manually. A manual scrub is done by:
btrfs filesystem scrub ...


= Btrfs options =
= Btrfs options =
translator
987

edits