Search CTRL + K

BTRFS

BTRFS(better filesystem) 是一个主打 copy-on-write(COW)的现代文件系统,主要保障错误容忍和修复以及简单运维。

主要特性有:

FAQ

修改了压缩算法后,文件系统仍然存在老的压缩协议

使用 compsize 工具可以查看某个目录下所有文件的压缩协议分布:

~ as 🧙 took 3s
❯ sudo compsize -x /home
Processed 108407 files, 116078 regular extents (120456 refs), 45587 inline.
Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL       70%      9.0G          12G          13G
none       100%      6.8G         6.8G         6.8G
zlib        38%      2.1M         5.6M         4.9M
zstd        34%      2.0G         5.8G         6.2G
prealloc   100%      134M         134M         142M

可以看到,我将原本是 zlib 压缩的文件系统转为 zstd 后,仍然包含 zlib 的文件。

每个子卷都要单独转:

btrfs filesystem defragment -r -v -czstd /

通过如下命令查看 zlib 压缩的文件 inode

sudo btrfs inspect-internal dump-tree -t 257 /dev/nvme0n1p2 | grep "compression.*\(zlib\)" -C5

其中 257 是 /home 子卷的 id,/dev/nvme0n1p2 是我文件系统所在设备。

举个例子:

item 79 key (241692 EXTENT_DATA 0) itemoff 9901 itemsize 53
generation 3143 type 1 (regular)
extent data disk byte 34422919168 nr 4096
extent data offset 0 nr 8192 ram 8192
extent compression 1 (zlib)

241692 就是 inode,通过如下命令反查路径:

~ as 🧙
❯ sudo btrfs inspect-internal inode-resolve 241692 /home
/home/charmer/.local/share/klipper/history2.lst

可以看到的确是 zlib 压缩的:

~ as 🧙
❯ sudo compsize /home/charmer/.local/share/klipper/history2.lst
Processed 1 file, 1 regular extents (1 refs), 0 inline.
Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL       50%      4.0K         8.0K         8.0K
zlib        50%      4.0K         8.0K         8.0K

再通过 defragment 命令转换即可。

What is BTRFS?

BTRFS is a modern copy on write (COW) filesystem for Linux aimed at implementing advanced features while also focusing on fault tolerance, repair and easy administration.[1]

BTRFS advantages

Its main features and benefits are:[1:1]

  • Snapshots which do not make a full copy of the files
  • Built-in volume management, support for software-based RAID 0, RAID 1, RAID 10 and others
  • Self-healing - checksums for data and metadata, automatic detection of silent data corruptions

  1. https://btrfs.readthedocs.io/en/latest/Introduction.html ↩︎ ↩︎