Manjaro Difference between revisions of "Btrfs Maintenance"

Difference between revisions of "Btrfs Maintenance"

From Manjaro
(1st steps)
(Erste Vorschläge)
Line 12: Line 12:
   I do not say "free", because free does mean nothing with btrfs. The value you have to watch most is "unallocated" !
   I do not say "free", because free does mean nothing with btrfs. The value you have to watch most is "unallocated" !


==== Why this is wrong ====
==== Every filesystem needs some maintenance ====
Every filesystem needs some maintenance.


Some filesystems do an automatic chkfs at every XX. mount
Some filesystems do an automatic chkfs at every XX. mount
Line 25: Line 24:


=== Is the Volume in a clean state ===
=== Is the Volume in a clean state ===
At mount btrfs tests wether the volume is in a clean stat.
At mount btrfs tests wehter the volume is in a clean state.


==== not clean ====
==== power down ====
If the computer suddenly loses power, transactions may not or only partially be written to the volume. Btrfs attempts to bring the volume to a clean state by removing the last (uncompleted) action. This may mean losing the last changes you made before turning off. But you gain a clean file system that doesn't need to be repaired.
Most file systems are not prepared for a sudden loss of power. If the computer suddenly loses power, transactions may not be written or only partially written to the volume. File systems that use journaling can often recover after a power failure.
 
Btrfs attempts to clean the volume by removing the last (uncompleted) action. This can result in losing the last changes you made before turning off. But you get a clean file system that doesn't need to be repaired.


==== error ====
==== error ====
The filesystem will be mounted readonly
If btrfs encounters an unrecoverable error, such as a checksum mismatch, the filesystem is mounted read-only. (When using RAID2, such errors are auto-repaired)


==== clean ====
==== clean ====
btrfs will mount the subvolume read write.
btrfs will mount the subvolume read-write.
<!-- More Detail for formatter: https://www.mediawiki.org/wiki/Help:Formatting -->
 
== Manual Maintenace ==
From time to time it may be advisable to check the health of the volume. This is done with:
 
=== usage ===
Look if everything is OK with the unallocated space on your volume.
 
==== check unallocated space ====
 
 
{{RootCmd|command=btrfs filesystem usage -h /}}
Pay special attention to the unallocated space !
 
The commonly used term "free" is meaningless to btrfs users. Even if you have 50% of your volume "free", you may run out of storage space. **You must pay attention to the term unallocated**.
 
Try to keep at least 10% of your volume unallocated. If this is below 10%:
* expand your volume to double size (see: [[Btrfs]])
* delete some unused data
* delete some old snapshots
* balance ([[Btrfs]])
 
==== clean up unused snapshots ====
From time to time it is necessary to check if you have snapshots that you do not need any more, but that hold valuable space on your volume.
 
=== balance your free space ===
If you have some space "free" on your volume, but the unallocated space is below 10% (or close to 10%), you can help btrfs to rebalance some chunks.
 
{{RootCmd|command=btrfs balance start -musage=50 -dusage=50}}
Btrfs looks for chunks that contain more than 50% free space. It will take 2 of them and then move everything into a new chunk. After that, one chunk is released. This continues until each chunk is at least 50% full.
 
This will give you some unallocated(free) chunks that help btrfs **not** to get out of space.
 
If you have less than 20% unallocated space, please do the following:
{{RootCmd|command=btrfs balance start -musage=75 -dusage=75}}
Btrfs looks for chunks that are less than 75% full.
It will take 4 of them and then move everything into 3 new chunks. After that, one chunk can be released. This continues until each chunk is at least 75% full.
 
If you still have less than 20% unallocated space, please do the following:
{{RootCmd|command=btrfs balance start -musage=90 -dusage=90}}
 
 
=== scrub ===
Check if everything is ok with the checksums and the readability of your data. **Only do this when in doubt**. This may take a long time as btrfs has to read ALL the data. Btrfs only scans the portion of your volume that actually contains data.


<!-- If you use command, it should be inside of usercmd. You can see below example -->
{{RootCmd|command=btrfs scrub start -Bd /}}


{{UserCmd|command=example command should be here}}
Tip:watch -d btrfs scrub status /


<!-- If you use code, it should be like below example(a space before that) -->
<!-- If you use code, it should be like below example(a space before that) -->

Revision as of 19:10, 26 January 2023


Btrfs Maintenance

Btrfs needs no maintenance

This even may be true, when:

  • You always keep 10% of your volume unallocated
 I do not say "free", because free does mean nothing with btrfs. The value you have to watch most is "unallocated" !

Every filesystem needs some maintenance

Some filesystems do an automatic chkfs at every XX. mount Others need the user to do a chkfs manually. On most you have to watch not to fill them to 100%. Some reserve 5% for root. Some filesystems need to be defragmented. Others do not.

Every filesystem has its own needs and tools !

Automatic maintenance

Btrfs does some maintenance automatically.

Is the Volume in a clean state

At mount btrfs tests wehter the volume is in a clean state.

power down

Most file systems are not prepared for a sudden loss of power. If the computer suddenly loses power, transactions may not be written or only partially written to the volume. File systems that use journaling can often recover after a power failure.

Btrfs attempts to clean the volume by removing the last (uncompleted) action. This can result in losing the last changes you made before turning off. But you get a clean file system that doesn't need to be repaired.

error

If btrfs encounters an unrecoverable error, such as a checksum mismatch, the filesystem is mounted read-only. (When using RAID2, such errors are auto-repaired)

clean

btrfs will mount the subvolume read-write.

Manual Maintenace

From time to time it may be advisable to check the health of the volume. This is done with:

usage

Look if everything is OK with the unallocated space on your volume.

check unallocated space

root # btrfs filesystem usage -h / COPY TO CLIPBOARD


Pay special attention to the unallocated space !

The commonly used term "free" is meaningless to btrfs users. Even if you have 50% of your volume "free", you may run out of storage space. **You must pay attention to the term unallocated**.

Try to keep at least 10% of your volume unallocated. If this is below 10%:

  • expand your volume to double size (see: Btrfs)
  • delete some unused data
  • delete some old snapshots
  • balance (Btrfs)

clean up unused snapshots

From time to time it is necessary to check if you have snapshots that you do not need any more, but that hold valuable space on your volume.

balance your free space

If you have some space "free" on your volume, but the unallocated space is below 10% (or close to 10%), you can help btrfs to rebalance some chunks.

root # btrfs balance start -musage=50 -dusage=50 COPY TO CLIPBOARD


Btrfs looks for chunks that contain more than 50% free space. It will take 2 of them and then move everything into a new chunk. After that, one chunk is released. This continues until each chunk is at least 50% full.

This will give you some unallocated(free) chunks that help btrfs **not** to get out of space.

If you have less than 20% unallocated space, please do the following:

root # btrfs balance start -musage=75 -dusage=75 COPY TO CLIPBOARD


Btrfs looks for chunks that are less than 75% full. It will take 4 of them and then move everything into 3 new chunks. After that, one chunk can be released. This continues until each chunk is at least 75% full.

If you still have less than 20% unallocated space, please do the following:

root # btrfs balance start -musage=90 -dusage=90 COPY TO CLIPBOARD



scrub

Check if everything is ok with the checksums and the readability of your data. **Only do this when in doubt**. This may take a long time as btrfs has to read ALL the data. Btrfs only scans the portion of your volume that actually contains data.

root # btrfs scrub start -Bd / COPY TO CLIPBOARD


Tip:watch -d btrfs scrub status /


Example codes should be here.



See Also

Btrfs Learn basics about btrfs

Cookies help us deliver our services. By using our services, you agree to our use of cookies.