2022-06-25 11:36:16 +02:00
|
|
|
---
|
|
|
|
title: BTRFS
|
2022-11-19 15:25:20 +01:00
|
|
|
visible: true
|
2022-06-25 11:36:16 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
[toc]
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:36:16 +02:00
|
|
|
## Utils
|
2023-02-23 14:48:51 +01:00
|
|
|
|
|
|
|
`# pacman -S btrfs-progs`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
## Fstab example
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:36:16 +02:00
|
|
|
`UUID=2dc70a6e-b4cf-4d94-b326-0ba9f886cf49 /mnt/tmp btrfs defaults,noatime,compress-force=zstd,space_cache=v2,subvol=@ 0 0`
|
|
|
|
|
2023-02-23 14:48:51 +01:00
|
|
|
Options:
|
|
|
|
|
2022-06-25 11:36:16 +02:00
|
|
|
```
|
|
|
|
defaults -> Use whatever defaults
|
|
|
|
noatime -> Reading access to a file is not recorded
|
|
|
|
compress-force -> Send all files through the compression algorithm
|
|
|
|
space_cache -> Increases performance by mapping unallocated blocks
|
|
|
|
subvol -> Subvolume to mount
|
|
|
|
```
|
|
|
|
|
|
|
|
## Filesystem usage
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:36:16 +02:00
|
|
|
Show storage allocated, used and free
|
2023-02-23 14:48:51 +01:00
|
|
|
`# btrfs fi usage (mountpoint)`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
allocated: space used
|
|
|
|
unallocated: actual free space
|
|
|
|
Used: amount of data stored
|
|
|
|
Free: free storage based on "Used"
|
|
|
|
```
|
|
|
|
|
|
|
|
Start rebalance of datachunks filled less than 70%
|
2023-02-23 14:48:51 +01:00
|
|
|
`# btrfs balance start --b -dusage=70 -musage=70 (mountpoint)`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
Check status of rebalance
|
2023-02-23 14:48:51 +01:00
|
|
|
`# btrfs balance status -v (mountpoint)`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
## Disable CoW
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:36:16 +02:00
|
|
|
Disable copy on write for folders (Only works on new files)
|
2023-02-23 14:48:51 +01:00
|
|
|
`$ chattr +C (path)`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
## Device errors
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:36:16 +02:00
|
|
|
Error counts for a given mountpoint
|
2023-02-23 14:48:51 +01:00
|
|
|
`# btrfs dev stat (mountpoint)`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
## Compression
|
|
|
|
|
|
|
|
### Algorithms
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:36:16 +02:00
|
|
|
```
|
|
|
|
zlib: Slow, but strong compression, level 1-9
|
|
|
|
lzo : Fastest, weak compression
|
|
|
|
zstd: [Recommended] Medium, newer compression standard than the others, only works on newer kernels, level 1-15
|
|
|
|
```
|
|
|
|
|
|
|
|
Enable compression for existing files
|
|
|
|
`# btrfs filesystem defragment -r -v -c(alg) (path)`
|
2023-02-23 14:48:51 +01:00
|
|
|
_It is impossible to specify the level of compression wanted._
|
2022-06-25 11:36:16 +02:00
|
|
|
|
2023-02-23 14:48:51 +01:00
|
|
|
Add `compress=(alg)` to `/etc/fstab`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
To specify a level of compression (zlib and zstd) use `compress=(alg):(level)` in fstab.
|
2023-02-23 14:48:51 +01:00
|
|
|
For zstd compression it is recommended to use `compress-force=zstd:(level)`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
## Subvolumes
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:36:16 +02:00
|
|
|
List
|
2023-02-23 14:48:51 +01:00
|
|
|
`# btrfs subv list (path)`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
Create
|
2023-02-23 14:48:51 +01:00
|
|
|
`# btrfs subv create (path)`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
Mount a subvolume
|
2023-02-23 14:48:51 +01:00
|
|
|
`# mount -o subvol=@(subvolname) /dev/sdXX /(mountpoint)`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
## Snapshots
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:36:16 +02:00
|
|
|
TODO
|
|
|
|
|
|
|
|
## RAID
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:36:16 +02:00
|
|
|
An array can be mounted by specifying one of its members.
|
2023-02-23 14:48:51 +01:00
|
|
|
`# mount /dev/sdXX /mnt`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
2023-02-23 14:48:51 +01:00
|
|
|
All members of an array have the same UUID, which can be mounted through fstab.
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
### RAID 1
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:36:16 +02:00
|
|
|
On filesystem creation
|
2023-02-23 14:48:51 +01:00
|
|
|
`# mkfs.btrfs -m raid1 -d raid1 /dev/sdXX /dev/sdYY`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
### RAID 5
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:36:16 +02:00
|
|
|
On filesystem creation
|
2023-02-23 14:48:51 +01:00
|
|
|
_It is recommended not to use raid5/6 for metadata yet_
|
|
|
|
`# mkfs.btrfs -m raid1 -d raid5 /dev/sdXX /dev/sdYY /dev/sdZZ`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
### RAID 10
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:36:16 +02:00
|
|
|
On filesystem creation
|
2023-02-23 14:48:51 +01:00
|
|
|
`# mkfs.btrfs -m raid10 -d raid10 /dev/sdXX /dev/sdYY /dev/sdZZ /dev/sdQQ`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
### Convert to single device
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:36:16 +02:00
|
|
|
First, the files have to be collected on one device.
|
2023-02-23 14:48:51 +01:00
|
|
|
_DUP on system and metadata should only be used on HDDs. Use single on SSDs_
|
|
|
|
`# btrfs balance start -f -sconvert=dup,devid=(id) -mconvert=dup,devid=(id) -dconvert=single,devid=(id) /(mountpoint)`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
Now unused devices can be removed
|
2023-02-23 14:48:51 +01:00
|
|
|
`# btrfs device delete /dev/sdYY /(mountpoint)`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
### Replace dying/dead device in RAID array
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:36:16 +02:00
|
|
|
Show arrays that are available
|
2023-02-23 14:48:51 +01:00
|
|
|
`btrfs fi show`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
From my testing the log has to be dropped before btrfs will mount the incomplete array
|
2023-02-23 14:48:51 +01:00
|
|
|
`btrfs rescue zero-log /dev/sdXX`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
Mount with these options to be able to fix it
|
2023-02-23 14:48:51 +01:00
|
|
|
`mount -o rw,degraded /(mountpoint)`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
The ID has to be replaced with the ID of the **missing** device!
|
2023-02-23 14:48:51 +01:00
|
|
|
`btrfs replace start -B (id) /dev/sdYY /(mountpoint)`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
Query the status of the repace
|
2023-02-23 14:48:51 +01:00
|
|
|
`btrfs replace status /(mountpoint)`
|
2022-06-25 11:36:16 +02:00
|
|
|
|
|
|
|
Balance the filesystem at the end
|
2023-02-23 14:48:51 +01:00
|
|
|
`btrfs balance /(mountpoint)`
|
2022-07-09 14:43:01 +02:00
|
|
|
|
|
|
|
## Issues
|
|
|
|
|
|
|
|
### 100% CPU Usage
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-07-09 14:43:01 +02:00
|
|
|
`btrfs-transaction` and `btrfs-cleaner` will run on a single cpu core, maxing it out with 100% load.
|
2023-02-23 14:48:51 +01:00
|
|
|
_TODO: Check what enabled quotas in the first place. A likely candidate is snapper_
|
2022-07-09 14:43:01 +02:00
|
|
|
The issue is apparently caused by using quotas in btrfs.
|
|
|
|
Check if quotas are enabled:
|
|
|
|
`# btrfs qgroup show (path)`
|
|
|
|
Disable quotas:
|
2023-02-23 14:48:51 +01:00
|
|
|
`# btrfs quota disable (path)`
|