使用btrfs文件系统透明压缩
本文为个人工作系统维护操作记录。
Btrfs 是 Linux 的现代写入复制 (COW) 文件系统,旨在实现高级功能,同时专注于容错、修复和易于管理。
Btrfs 还支持透明和自动压缩,这减小了文件的大小,并通过减少写入放大来显著延长基于闪存的介质的使用寿命。
1. 安装btrfs-progs
对于用户空间实用程序,请安装基本操作所需的 btrfs-progs 软件包。
#apt install btrfs-progs
如果您需要从 Btrfs 文件系统(即内核和 initramfs 驻留在 Btrfs 分区上)引导,请检查您的引导加载程序是否支持 Btrfs。
2. 格式化分区创建子卷
mkfs.btrfs /dev/sdd10 # 格式化主分区
mkdir -p /tmp/mnt
mount /dev/sdd10 /tmp/mnt # 挂载分区
# 创建子卷
btrfs subvolume create /tmp/mnt/@backup
btrfs subvolume create /tmp/mnt/@work
#列出子卷
btrfs subvolume list -p /tmp/mnt/
umount /dev/sdd10 # 卸载分区
3. 挂载子卷
接下来就是挂载子卷了,使用 subvol 挂载选项来指定挂载的子卷:
mkdir -p /tmp/mnt/work
mount /dev/sdd10 /tmp/mnt/work -o discard,noatime,autodefrag,compress=zstd:3,rw,subvol=@work
mkdir -p /tmp/mnt/backup
mount /dev/sdd10 /tmp/mnt/backup -o discard,noatime,autodefrag,compress=zstd:3,rw,subvol=@backup
4. fstab配置
/etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sdc5 during installation
UUID=71e531d8-9c92-4943-a31d-fe2ab536c2ca / btrfs discard,noatime,autodefrag,compress=zstd:3,rw,subvol=@ 0 1
# /boot/efi was on /dev/sdc3 during installation
UUID=2581-B275 /boot/efi vfat ro,umask=0077 0 1
# /home was on /dev/sdc5 during installation
UUID=71e531d8-9c92-4943-a31d-fe2ab536c2ca /home btrfs discard,noatime,autodefrag,compress=zstd:3,rw,subvol=@home 0 2
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义