惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
Netflix TechBlog - Medium
大猫的无限游戏
大猫的无限游戏
爱范儿
爱范儿
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Register - Security
The Register - Security
IT之家
IT之家
博客园_首页
Microsoft Security Blog
Microsoft Security Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
I
InfoQ
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
Apple Machine Learning Research
Apple Machine Learning Research
M
MIT News - Artificial intelligence
博客园 - Franky
C
Check Point Blog
T
The Blog of Author Tim Ferriss
V
Visual Studio Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Tailwind CSS Blog
Recent Announcements
Recent Announcements
云风的 BLOG
云风的 BLOG
美团技术团队
The Cloudflare Blog
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
V
V2EX
aimingoo的专栏
aimingoo的专栏
GbyAI
GbyAI
G
Google Developers Blog
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
U
Unit 42
罗磊的独立博客
量子位
MongoDB | Blog
MongoDB | Blog
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
D
Docker
人人都是产品经理
人人都是产品经理

陈少文的网站

巨变与机遇的未来十年 Kubernetes 平台管理软件压力测试方案 使用镜像部署 Hexo 静态页面 终于等到你 - GitHub 镜像仓库服务(ghcr.io) 一起来学 Go --(6)Interface 一起来学 Go --(5)Goroutine 和 Channel 什么是函数式编程 如何在 Kubernetes 集群集成 Kata 柯里化与偏函数 使用 PyGithub 自动创建 Label 软件产品是团队能力的输出 Helm 2 、Helm 3 比较 IoT 变现 Kubernetes 中的 DNS 服务 国内的 Helm 镜像源 Harbor 使用自签证书支持 Https 访问 DevOps 工具链之 Prow 如何使用 kfctl 安装 Kubeflow VS Code 无法下载 Go 插件的工具包 工程师更应具有服务精神 你不知道的 Docker 使用技巧 使用 Docker 运行 Tensorflow 论中国 什么是左移 如何清空 Git 仓库全部历史记录 一禅小和尚 有风吹过厨房 时间的玫瑰 如何在 CentOS 安装 GPU 驱动 开发 Tips(19) 使用 Velero 备份 Kubernetes 集群 Kubernetes Cheat Sheet 开发 Tips(18) 如何构建一个 Java 工程 开发 Tips(17) KubeSpray 安装 Kubernetes 报错 ip in ansible_all_ipv4_addresses 基于 Kubernetes 和 Jenkins 搭建自动化测试系统 在 Kubernetes 上动态创建 Jenkins Slave 使用 Jenkins 进行服务拨测 开发 Tips(16) Kubernetes 签发 Ingress 证书及日常故障运维 Kubernetes 中 Deployment 的基本操作 Kubernetes 中的证书 如何使用 KubeBuilder 开发一个 Operator Kubernetes 1.6.0 安装问题汇总 镜像管理工具 -- Harbor 开发 Tips(15) Docker 如何拉取镜像 开发 Tips(14) 使用 Helm 安装 harbor 开发 Tips(13) 使用 S2I 构建云原生应用 在 Kubernetes 中使用 emptyDir、hostPath、localVolume 开发 Tips(12) 开发 Tips(11) 代码质量分析工具 SonarQube 使用 Kubeadm 安装 Kubernetes 集群 一起来学 Go --(4)常用函数 Kubernetes 中的 Ceph Kubernetes 之 Volumes Kubernetes 之 Labels、Selectors 开发 Tips(10) 开源正在重构商业模式 Kubernetes 之网络 Kubernetes 之 API 使用 Helm 和 Operator 快速部署 Prometheus Kubernetes 复杂有状态应用管理框架 -- Operator Kubernetes 的包管理器 -- Helm 一起来学 Go --(3)Go Modules 如何一步一步地优化博客方案 kubectl 实用指南 Kubernetes 中的基本概念 搭建远程 Kubernetes 开发环境 大公司和小公司的 ToB 思路 开发 Tips(9) Go 入门指南 一起来学 Go --(2)数据与逻辑结构 如何预防 Web 富文本中的 XSS 攻击 django-xss-cleaner 云工作时代 一起来学 Go --(1)背景与特点 SaaS 开发团队的不同阶段 你不知道的 Git 使用技巧 输出既服务 微服务设计 继续奔跑 开发 Tips(8) 从账户安全到二次验证 Django 性能之数据库查询优化 Django 性能之分库分表 敏捷开发之研发流程 打造一致性的团队 开发 Tips(7) Pytest 进阶学习之 Mock PaaS 部署之 buildpack Go 开发配置 领域输出才是 PaaS 的核心竞争力 Pytest 入门学习 开发 Tips(6) 如何使用 Jenkins、Docker、GitLab 搭建 Django 自动化部署流程
RAID 下 Btrfs 运维操作
微信公众号 · 2025-10-03 · via 陈少文的网站

Please enable Javascript to view the contents

Btrfs 支持在线扩容、缩容、换盘与 RAID 模式转换;本篇主要介绍在 RAID 0/RAID 1/RAID 10/RAID 6 拓扑下创建文件系统、加盘、换盘、缩容及常用运维操作。

1. Btrfs 配置

  • single:单副本,无冗余,单盘或可多盘聚合。
  • raid0:条带,无冗余,等价 RAID 0。
  • raid1:镜像,至少 2 块盘,等价 RAID 1。
  • raid10:条带 + 镜像,至少 4 块盘,等价 RAID 10。
  • raid5:单校验,至少 3 块盘,允许 1 块盘故障,等价 RAID 5。
  • raid6:双校验,至少 4 块盘,允许 2 块盘故障,等价 RAID 6。

数据与元数据可分别设置配置档(如 -d raid10 -m raid1),元数据一般用更高冗余。

常用概念:

  • degraded:降级,有设备缺失但可读(甚至可写,取决于 profile)。
  • balance:在设备间重新分布数据块,以满足新 profile 或新设备;加盘、改 RAID 后常需 balance。
  • replace:在线用新盘替换旧盘,无需卸载,数据会拷贝到新盘后移除旧盘。

2. RAID 0

2.1 创建 Btrfs 文件系统

  • 使用多块盘创建 RAID 0(数据与元数据均为 raid0)
1
mkfs.btrfs -d raid0 -m raid0 -f /dev/nvme0n1 /dev/nvme1n1
  • 挂载

可只指定一块盘,会识别到其他盘。

1
2
mkdir -p /mnt/btrfs
mount /dev/nvme0n1 /mnt/btrfs
  • 查看设备使用情况
1
btrfs device usage /mnt/btrfs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
/dev/nvme0n1, ID: 1
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 0/2:            1.00GiB
   Metadata,RAID 0/2:      512.00MiB
   System,RAID 0/2:          8.00MiB
   Unallocated:           743.70GiB

/dev/nvme1n1, ID: 2
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 0/2:            1.00GiB
   Metadata,RAID 0/2:      512.00MiB
   System,RAID 0/2:          8.00MiB
   Unallocated:           743.70GiB
  • 查看文件系统使用情况
1
btrfs filesystem df /mnt/btrfs
1
2
3
4
Data, RAID 0: total=2.00GiB, used=0.00B
System, RAID 0: total=16.00MiB, used=16.00KiB
Metadata, RAID 0: total=1.00GiB, used=208.00KiB
GlobalReserve, single: total=3.25MiB, used=0.00B
  • 查看空间
1
2
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1    1.5T  3.5M  1.5T   1% /mnt/btrfs

两块盘下,raid0 做条带,得盘率 100%。

2.2 加盘扩容

  • 将新盘加入已挂载的文件系统
1
btrfs device add -f /dev/nvme2n1 /mnt/btrfs

-f 会强制覆盖已有的文件系统。

  • 查看设备使用情况
1
btrfs device usage /mnt/btrfs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
/dev/nvme0n1, ID: 1
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 0/2:           25.00GiB
   Metadata,RAID 0/2:      512.00MiB
   System,RAID 0/2:          8.00MiB
   Unallocated:           719.70GiB

/dev/nvme1n1, ID: 2
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 0/2:           25.00GiB
   Metadata,RAID 0/2:      512.00MiB
   System,RAID 0/2:          8.00MiB
   Unallocated:           719.70GiB

/dev/nvme2n1, ID: 3
   Device size:           745.21GiB
   Device slack:              0.00B
   Unallocated:           745.21GiB
  • 执行 balance,使数据按 raid0 分布到所有设备
1
btrfs balance start -dconvert=raid0 -mconvert=raid0 /mnt/btrfs

命令会 hang 住,需要等待 balance 完成。可以另外开一个终端查看进度。

  • 查看 balance 进度
1
btrfs balance status /mnt/btrfs
1
10 out of about 27 chunks balanced (11 considered),  63% left
  • 查看设备使用情况
1
btrfs device usage /mnt/btrfs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/dev/nvme0n1, ID: 1
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 0/3:           17.00GiB
   Metadata,RAID 0/3:      352.00MiB
   System,RAID 0/3:         32.00MiB
   Unallocated:           727.84GiB

/dev/nvme1n1, ID: 2
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 0/3:           17.00GiB
   Metadata,RAID 0/3:      352.00MiB
   System,RAID 0/3:         32.00MiB
   Unallocated:           727.84GiB

/dev/nvme2n1, ID: 3
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 0/3:           17.00GiB
   Metadata,RAID 0/3:      352.00MiB
   System,RAID 0/3:         32.00MiB
   Unallocated:           727.84GiB

2.3 减盘缩容

raid0 无冗余,缩容需保证目标盘数下其他盘有足够空间容纳被移走盘上的数据。

  • 移除一块盘

数据会自动迁到其余盘

1
btrfs device remove /dev/nvme2n1 /mnt/btrfs
  • 查看设备列表
1
btrfs device usage /mnt/btrfs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
/dev/nvme0n1, ID: 1
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 0/2:           25.00GiB
   Metadata,RAID 0/2:      512.00MiB
   System,RAID 0/2:          8.00MiB
   Unallocated:           719.70GiB

/dev/nvme1n1, ID: 2
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 0/2:           25.00GiB
   Metadata,RAID 0/2:      512.00MiB
   System,RAID 0/2:          8.00MiB
   Unallocated:           719.70GiB

3. RAID 1

3.1 创建 Btrfs 文件系统

  • 移除已有的文件系统
  • 使用 2 块盘创建 RAID 1
1
mkfs.btrfs -d raid1 -m raid1 -f /dev/nvme0n1 /dev/nvme1n1
  • 挂载
1
2
mkdir -p /mnt/btrfs
mount /dev/nvme0n1 /mnt/btrfs
  • 查看设备使用情况
1
btrfs device usage /mnt/btrfs
  • 查看空间
1
2
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1    746G  3.5M  745G   1% /mnt/btrfs

两块盘下,raid1 做镜像,得盘率 50%。

3.2 单盘替换

  • 清空新盘
  • 用新盘替换旧盘
1
btrfs replace start /dev/nvme1n1 /dev/nvme2n1 /mnt/btrfs
  • 查看替换进度
1
btrfs replace status /mnt/btrfs
1
6.7% done, 0 write errs, 0 uncorr. read errs

替换期间文件系统可正常读写。替换完成后,旧盘会从文件系统中移除。

  • 若新盘比旧盘大,新空间会自动纳入可用空间
1
btrfs device usage /mnt/btrfs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
/dev/nvme0n1, ID: 1
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 1:             51.00GiB
   Metadata,RAID 1:          1.00GiB
   System,RAID 1:           32.00MiB
   Unallocated:           693.18GiB

/dev/nvme2n1, ID: 2
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 1:             51.00GiB
   Metadata,RAID 1:          1.00GiB
   System,RAID 1:           32.00MiB
   Unallocated:           693.18GiB

3.3 加盘扩容

  • 清空新盘
1
2
wipefs -a /dev/nvme3n1
wipefs -a /dev/nvme4n1
  • 加两块盘后可转为 raid10
1
btrfs device add /dev/nvme3n1 /dev/nvme4n1 /mnt/btrfs
  • 查看设备使用情况
1
btrfs device usage /mnt/btrfs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/dev/nvme0n1, ID: 1
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 1:             51.00GiB
   Metadata,RAID 1:          1.00GiB
   System,RAID 1:           32.00MiB
   Unallocated:           693.18GiB

/dev/nvme2n1, ID: 2
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 1:             51.00GiB
   Metadata,RAID 1:          1.00GiB
   System,RAID 1:           32.00MiB
   Unallocated:           693.18GiB

/dev/nvme3n1, ID: 3
   Device size:           745.21GiB
   Device slack:              0.00B
   Unallocated:           745.21GiB

/dev/nvme4n1, ID: 4
   Device size:           745.21GiB
   Device slack:              0.00B
   Unallocated:           745.21GiB
  • 再 balance 为 raid10
1
btrfs balance start -dconvert=raid10 -mconvert=raid10 /mnt/btrfs

命令会 hang 住,需要等待 balance 完成。可以另外开一个终端查看进度。

  • 查看 balance 进度
1
btrfs balance status /mnt/btrfs
1
34 out of about 53 chunks balanced (35 considered),  36% left
  • 查看设备使用情况
1
btrfs device usage /mnt/btrfs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/dev/nvme0n1, ID: 1
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 10/4:          51.00GiB
   Metadata,RAID 10/4:       1.00GiB
   System,RAID 10/4:        32.00MiB
   Unallocated:           693.18GiB

/dev/nvme2n1, ID: 2
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 10/4:          51.00GiB
   Metadata,RAID 10/4:       1.00GiB
   System,RAID 10/4:        32.00MiB
   Unallocated:           693.18GiB

/dev/nvme3n1, ID: 3
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 10/4:          51.00GiB
   Metadata,RAID 10/4:       1.00GiB
   System,RAID 10/4:        32.00MiB
   Unallocated:           693.18GiB

/dev/nvme4n1, ID: 4
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 10/4:          51.00GiB
   Metadata,RAID 10/4:       1.00GiB
   System,RAID 10/4:        32.00MiB
   Unallocated:           693.18GiB

3.4 减盘缩容

  • 移除一块盘
1
btrfs device remove /dev/nvme4n1 /mnt/btrfs
  • 查看设备
1
btrfs device usage /mnt/btrfs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
/dev/nvme0n1, ID: 1
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 10/2:          34.00GiB
   Metadata,RAID 10/2:       1.00GiB
   System,RAID 10/2:        32.00MiB
   Unallocated:           710.18GiB

/dev/nvme2n1, ID: 2
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 10/2:          34.00GiB
   Metadata,RAID 10/2:       1.00GiB
   Unallocated:           710.21GiB

/dev/nvme3n1, ID: 3
   Device size:           745.21GiB
   Device slack:              0.00B
   Data,RAID 10/2:          34.00GiB
   System,RAID 10/2:        32.00MiB
   Unallocated:           711.18GiB

4. RAID 10

4.1 创建 Btrfs 文件系统

  • 移除已有的文件系统
  • 使用 4 块盘创建 RAID 10
1
mkfs.btrfs -d raid10 -m raid10 -f /dev/nvme0n1 /dev/nvme1n1 /dev/nvme2n1 /dev/nvme3n1

-f 会强制覆盖已有的文件系统。

  • 挂载
1
2
mkdir -p /mnt/btrfs
mount /dev/nvme0n1 /mnt/btrfs
  • 查看设备使用情况
1
btrfs device usage /mnt/btrfs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
/dev/nvme0n1, ID: 1
   Data,RAID 10/4:           1.00GiB
   Metadata,RAID 10/4:     256.00MiB

/dev/nvme1n1, ID: 2
   Data,RAID 10/4:           1.00GiB
   Metadata,RAID 10/4:     256.00MiB

/dev/nvme2n1, ID: 3
   Data,RAID 10/4:           1.00GiB
   Metadata,RAID 10/4:     256.00MiB

/dev/nvme3n1, ID: 4
   Data,RAID 10/4:           1.00GiB
   Metadata,RAID 10/4:     256.00MiB
  • 查看空间
1
2
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1    1.5T  3.5M  1.5T   1% /mnt/btrfs

4 块盘下,raid10 为条带+镜像,得盘率 50%。

4.2 单盘替换

  • 清空旧盘
  • 用新盘替换旧盘
1
btrfs replace start /dev/nvme3n1 /dev/nvme4n1 /mnt/btrfs
  • 查看替换进度
1
btrfs replace status /mnt/btrfs

替换期间文件系统可正常使用。完成后旧盘自动移除,若新盘更大,空间自动扩展。

  • 查看设备使用情况
1
btrfs device usage /mnt/btrfs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
/dev/nvme0n1, ID: 1
   Data,RAID 10/4:          27.00GiB
   Metadata,RAID 10/4:     256.00MiB

/dev/nvme1n1, ID: 2
   Data,RAID 10/4:          27.00GiB
   Metadata,RAID 10/4:     256.00MiB

/dev/nvme2n1, ID: 3
   Data,RAID 10/4:          27.00GiB
   Metadata,RAID 10/4:     256.00MiB

/dev/nvme4n1, ID: 4
   Data,RAID 10/4:          27.00GiB
   Metadata,RAID 10/4:     256.00MiB

4.3 加盘扩容

  • 清空新盘
  • 将新盘加入文件系统
1
btrfs device add /dev/nvme5n1 /mnt/btrfs
  • balance 数据到新盘
1
btrfs balance start -dconvert=raid10 -mconvert=raid10 /mnt/btrfs
  • 查看 balance 进度
1
btrfs balance status /mnt/btrfs
  • 查看设备使用情况
1
btrfs device usage /mnt/btrfs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
/dev/nvme0n1, ID: 1
   Data,RAID 10/4:          21.00GiB
   Metadata,RAID 10/4:     512.00MiB

/dev/nvme1n1, ID: 2
   Data,RAID 10/4:          20.00GiB
   Metadata,RAID 10/4:     512.00MiB

/dev/nvme2n1, ID: 3
   Data,RAID 10/4:          20.00GiB
   Metadata,RAID 10/4:     512.00MiB

/dev/nvme4n1, ID: 4
   Data,RAID 10/4:          21.00GiB
   Metadata,RAID 10/4:     512.00MiB

/dev/nvme5n1, ID: 5
   Data,RAID 10/4:          22.00GiB
   Metadata,RAID 10/4:     512.00MiB

4.4 减盘缩容

需要保障移除盘之后,盘的数量不低于 RAID 的最低要求,并且剩余盘空间足够容纳被移走盘上的数据。

  • 移除一块盘
1
btrfs device remove /dev/nvme0n1 /mnt/btrfs
  • 查看设备列表
1
btrfs device usage /mnt/btrfs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
/dev/nvme1n1, ID: 2
   Data,RAID 10/4:          26.00GiB
   Metadata,RAID 10/4:     512.00MiB

/dev/nvme2n1, ID: 3
   Data,RAID 10/4:          26.00GiB
   Metadata,RAID 10/4:     512.00MiB

/dev/nvme4n1, ID: 4
   Data,RAID 10/4:          26.00GiB
   Metadata,RAID 10/4:     512.00MiB

/dev/nvme5n1, ID: 5
   Data,RAID 10/4:          26.00GiB
   Metadata,RAID 10/4:     512.00MiB

5. RAID 6

5.1 创建 Btrfs 文件系统

  • 移除已有的文件系统
  • 创建 RAID 6

至少 4 块盘。

1
mkfs.btrfs -d raid6 -m raid6 -f /dev/nvme0n1 /dev/nvme1n1 /dev/nvme2n1 /dev/nvme3n1
  • 挂载
1
2
mkdir -p /mnt/btrfs
mount /dev/nvme0n1 /mnt/btrfs
  • 查看设备与配置
1
btrfs device usage /mnt/btrfs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
/dev/nvme0n1, ID: 1
   Data,RAID 6/4:            1.00GiB
   Metadata,RAID 6/4:      256.00MiB

/dev/nvme1n1, ID: 2
   Data,RAID 6/4:            1.00GiB
   Metadata,RAID 6/4:      256.00MiB

/dev/nvme2n1, ID: 3
   Data,RAID 6/4:            1.00GiB
   Metadata,RAID 6/4:      256.00MiB

/dev/nvme3n1, ID: 4
   Data,RAID 6/4:            1.00GiB
   Metadata,RAID 6/4:      256.00MiB
  • 查看空间
1
/dev/nvme0n1    3.0T  3.5M  1.5T   1% /mnt/btrfs

4 块盘 RAID 6 得盘率 50%(2 数据 + 2 校验)。

5.2 单盘替换

  • 清空旧盘
  • 用新盘替换旧盘
1
btrfs replace start /dev/nvme3n1 /dev/nvme4n1 /mnt/btrfs
  • 查看进度
1
btrfs replace status /mnt/btrfs

等待完成。

  • 查看设备使用情况
1
btrfs device usage /mnt/btrfs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
/dev/nvme0n1, ID: 1
   Data,RAID 6/4:           26.00GiB
   Metadata,RAID 6/4:      256.00MiB

/dev/nvme1n1, ID: 2
   Data,RAID 6/4:           26.00GiB
   Metadata,RAID 6/4:      256.00MiB

/dev/nvme2n1, ID: 3
   Data,RAID 6/4:           26.00GiB
   Metadata,RAID 6/4:      256.00MiB

/dev/nvme4n1, ID: 4
   Data,RAID 6/4:           26.00GiB
   Metadata,RAID 6/4:      256.00MiB

5.3 加盘扩容

  • 添加新盘
1
btrfs device add -f /dev/nvme5n1 /mnt/btrfs
  • balance 数据到新盘
1
btrfs balance start -dconvert=raid6 -mconvert=raid6 /mnt/btrfs
1
2
3
4
5
6
7
WARNING:

        RAID 5/6 support has known problems and is strongly discouraged
        to be used besides testing or evaluation. It is recommended that
        you use one of the other RAID profiles.
        The operation will continue in 10 seconds.
        Use Ctrl-C to stop.

会出现一个警告,提示 RAID 5/6 不建议用于生产环境,数据不可靠。

  • 查看设备使用情况
1
btrfs device usage /mnt/btrfs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
/dev/nvme0n1, ID: 1
   Data,RAID 6/5:           18.00GiB
   Metadata,RAID 6/5:      352.00MiB

/dev/nvme1n1, ID: 2
   Data,RAID 6/5:           18.00GiB
   Metadata,RAID 6/5:      352.00MiB

/dev/nvme2n1, ID: 3
   Data,RAID 6/5:           18.00GiB
   Metadata,RAID 6/5:      352.00MiB

/dev/nvme4n1, ID: 4
   Data,RAID 6/5:           18.00GiB
   Metadata,RAID 6/5:      352.00MiB

/dev/nvme5n1, ID: 5
   Data,RAID 6/5:           18.00GiB
   Metadata,RAID 6/5:      352.00MiB

5.4 减盘缩容

  • 移除一块盘
1
btrfs device remove /dev/nvme0n1 /mnt/btrfs

移除设备时,没有出现 warning 提示。

  • 查看设备使用情况
1
btrfs device usage /mnt/btrfs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
/dev/nvme1n1, ID: 2
   Data,RAID 6/4:           26.00GiB
   Metadata,RAID 6/4:      512.00MiB

/dev/nvme2n1, ID: 3
   Data,RAID 6/4:           26.00GiB
   Metadata,RAID 6/4:      512.00MiB

/dev/nvme4n1, ID: 4
   Data,RAID 6/4:           26.00GiB
   Metadata,RAID 6/4:      512.00MiB

/dev/nvme5n1, ID: 5
   Data,RAID 6/4:           26.00GiB
   Metadata,RAID 6/4:      512.00MiB

6. 降级与恢复

  • 某块盘故障或被拔出时,文件系统可能处于 degraded 状态,仍可读(甚至可写,视 profile 而定)。
  • 查看状态
1
2
btrfs device usage /mnt/btrfs
btrfs filesystem show /mnt/btrfs
  • 恢复方式:
    • 换盘:用 btrfs replace start 旧盘 新盘 /mnt/btrfs 在线替换。
    • 移除盘:若不再使用该盘,可用 btrfs device remove 缺失设备(需在能识别到“缺失”的情况下,或先 btrfs device add 新盘再 balance/remove)。
  • 替换或 balance 期间建议避免再掉盘,以加快恢复。

7. 备份与恢复

7.1 快照与恢复

  • 创建快照
1
btrfs subvolume snapshot /mnt/btrfs /mnt/btrfs/snap_test

创建的快照只包含元数据。

  • 查看快照文件
1
ls /mnt/btrfs/snap_test

非常易用,快照直接以文件目录的形式可以被访问。

  • 删除快照
1
btrfs subvolume delete /mnt/btrfs/snap_test

7.2 数据校验

  • 校验文件系统数据
1
btrfs scrub start /mnt/btrfs
  • 查看校验进度
1
btrfs scrub status /mnt/btrfs
1
2
Bytes scrubbed:   7.84GiB  (15.62%)
Rate:             1.57GiB/s

建议定期执行校验,发现静默错误(位翻转了而没有被发现)。

8. 生成测试数据

  • 4M 顺序写
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
fio \
  --name=4m_seq_write \
  --rw=write \
  --bs=4M \
  --ioengine=libaio \
  --direct=1 \
  --numjobs=1 \
  --iodepth=8 \
  --size=50G \
  --time_based \
  --runtime=60 \
  --group_reporting \
  --directory=/mnt/btrfs

用于生成测试数据。

  • 计算文件的 MD5 值
1
md5sum /mnt/btrfs/4m_seq_write.0.0

用于校验调整之后文件的完整性。


微信公众号