$ zpool list
NAME SIZE ALLOC FREE CKPOINT EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT
zroot 228G 16.8G 211G - - 12% 7% 1.00x ONLINE -
zvol0 1.81T 1.49T 333G - - 5% 82% 1.00x DEGRADED -
$
$ zpool status zvol0
pool: zvol0
state: DEGRADED
status: One or more devices could not be opened. Sufficient replicas exist for
the pool to continue functioning in a degraded state.
action: Attach the missing device and online it using 'zpool online'.
see: https://openzfs.github.io/openzfs-docs/msg/ZFS-8000-2Q
scan: scrub repaired 0B in 05:36:58 with 0 errors on Tue Jan 17 08:40:57 2023
config:
NAME STATE READ WRITE CKSUM
zvol0 DEGRADED 0 0 0
mirror-0 DEGRADED 0 0 0
12897545936258916783 UNAVAIL 0 0 0 was /dev/gpt/ndisk2
gpt/ndisk1 ONLINE 0 0 0
errors: No known data errors
$
此时,虽然硬盘是镜像配置,但由于一侧的 gpt/ndisk2 缺失,状态变为 DEGRADED(降级)。在 zpool status 的输出中,config: 部分显示 gpt/ndisk2 不再出现,而是用一个 ID(12897545936258916783)代替,并且行尾标记为 "was /dev/gpt/ndisk2"。这个 ID 后续将会用到。
创建交换分区
为了准备更换用的硬盘,我们首先需要对其进行 GPT 初始化,并为 ZFS 创建一个分区。
首先,我们使用 GPT 初始化硬盘:
$ gpart show ada1
gpart: No such geom: ada1.
$ gpart create -s gpt ada1
ada1 created
$ gpart show ada1
=> 40 11721045088 ada1 GPT (5.5T)
40 11721045088 - free - (5.5T)
$
同步过程将在后台进行,并且正如之前提到的,在此期间,服务器可以正常使用。由于数据量大约为 1.5TB,所需的同步时间会比较长。不过,ZFS 可以通过 zpool status 来查看同步的进度,这样我们就能得到一个结束时间的大致估算。
$ zpool status zvol0
pool: zvol0
state: DEGRADED
status: One or more devices is currently being resilvered. The pool will
continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
scan: resilver in progress since Sat Jan 28 14:25:44 2023
12.8G scanned at 596M/s, 600K issued at 27.3K/s, 1.49T total
0B resilvered, 0.00% done, no estimated completion time
config:
NAME STATE READ WRITE CKSUM
zvol0 DEGRADED 0 0 0
mirror-0 DEGRADED 0 0 0
replacing-0 DEGRADED 0 0 0
12897545936258916783 UNAVAIL 0 0 0 was /dev/gpt/ndisk2
gpt/sdisk1 ONLINE 0 0 0
gpt/ndisk1 ONLINE 0 0 0
errors: No known data errors
$
在 zpool status 中,你会看到 One or more devices is currently being resilvered[3],这表明正在进行 resilver 操作(即同步)。在 action 部分,系统会指示你等待 resilver 操作完成。同时,scan 部分显示了处理的进度和预计完成时间,但在同步开始时,通常会看到 no estimated completion time,这意味着系统无法立即估算预计时间。
稍等片刻,预计时间会逐渐显示,但根据经验,这个估算并不总是准确的。
例如,刚开始时,你可能会看到类似下面的输出:
$ zpool status zvol0
===== <省略> =====
scan: resilver in progress since Sat Jan 28 14:25:44 2023
265G scanned at 664M/s, 6.51G issued at 16.3M/s, 1.49T total
6.51G resilvered, 0.43% done, 1 days 02:27:43 to go
===== <省略> =====
$
过了一段时间,预计完成时间可能会变为:
$ zpool status zvol0
===== <省略> =====
scan: resilver in progress since Sat Jan 28 14:25:44 2023
289G scanned at 488M/s, 18.6G issued at 31.4M/s, 1.49T total
18.6G resilvered, 1.22% done, 13:38:30 to go
===== <省略> =====
$
$ zpool status zvol0
pool: zvol0
state: ONLINE
scan: resilvered 1.49T in 15:34:45 with 0 errors on Sun Jan 29 06:00:29 2023
config:
NAME STATE READ WRITE CKSUM
zvol0 ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
gpt/sdisk1 ONLINE 0 0 0
gpt/ndisk1 ONLINE 0 0 0
errors: No known data errors
$
HEALTH 和 STATE 都显示为 ONLINE,且没有出现任何错误,可以确认第一台硬盘的同步已经顺利完成。
第二台硬盘的同步
第二台硬盘的更换和同步步骤与第一台完全相同,因此这里只展示相关命令的执行和结果。
更换第二台硬盘并启动后。
$ zpool status zvol0
pool: zvol0
state: DEGRADED
status: One or more devices could not be opened. Sufficient replicas exist for
the pool to continue functioning in a degraded state.
action: Attach the missing device and online it using 'zpool online'.
see: https://openzfs.github.io/openzfs-docs/msg/ZFS-8000-2Q
scan: resilvered 1.49T in 15:34:45 with 0 errors on Sun Jan 29 06:00:29 2023
config:
NAME STATE READ WRITE CKSUM
zvol0 DEGRADED 0 0 0
mirror-0 DEGRADED 0 0 0
gpt/sdisk1 ONLINE 0 0 0
13953654332474917058 UNAVAIL 0 0 0 was /dev/gpt/ndisk1
errors: No known data errors
$
$ zpool replace zvol0 13953654332474917058 gpt/sdisk2
$ zpool status zvol0
pool: zvol0
state: DEGRADED
status: One or more devices is currently being resilvered. The pool will
continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
scan: resilver in progress since Sun Jan 29 13:38:15 2023
12.8G scanned at 692M/s, 492K issued at 25.9K/s, 1.49T total
0B resilvered, 0.00% done, no estimated completion time
config:
NAME STATE READ WRITE CKSUM
zvol0 DEGRADED 0 0 0
mirror-0 DEGRADED 0 0 0
gpt/sdisk1 ONLINE 0 0 0
replacing-1 DEGRADED 0 0 0
13953654332474917058 UNAVAIL 0 0 0 was /dev/gpt/ndisk1
gpt/sdisk2 ONLINE 0 0 0
errors: No known data errors
第二台的同步大约用了 14 个小时。
$ zpool status zvol0
pool: zvol0
state: ONLINE
scan: resilvered 1.49T in 14:11:00 with 0 errors on Mon Jan 30 03:49:15 2023
config:
NAME STATE READ WRITE CKSUM
zvol0 ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
gpt/sdisk1 ONLINE 0 0 0
gpt/sdisk2 ONLINE 0 0 0
errors: No known data errors
$