使用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

参考链接

Btrfs-Arch wiki

posted @ 2024-02-25 13:48  沐多  阅读(286)  评论(0编辑  收藏  举报