[new_device]
#/mnt> zpool replace poolname c3t2d0 c3t0d0
#/mnt> zpool status
pool: poolname
state: ONLINE
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.
scrub: resilver in progress, 6.71% done, 0h3m to go
config:
NAME STATE READ WRITE CKSUM
poolname ONLINE 0 0 0
raidz1 ONLINE 0 0 0
replacing ONLINE 0 0 0
c3t2d0 ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
errors: No known data errors
#/mnt> zpool status
pool: poolname
state: ONLINE
scrub: resilver completed with 0 errors on Wed Oct 8 13:16:35 2008
config:
NAME STATE READ WRITE CKSUM
poolname ONLINE 0 0 0
raidz1 ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
errors: No known data errors
添加磁盘空间的时候可以对添加的硬盘进行数据保护,如mirror和raidz
#/mnt> zpool add -n -f poolname raidz2 c3t1d0 c3t2d0 c3t5d0
would update 'poolname' to the following configuration:
poolname
raidz1
c3t0d0
c3t3d0
c3t4d0
raidz2
c3t1d0
c3t2d0
c3t5d0
例子:raidz出现坏盘的解决
在本例中,我把poolname中的c3t0d0号盘offline之后将其拆卸出3310。
#/mnt> zpool offline poolname c3t0d0
Bringing device c3t0d0 offline
#/mnt> zpool status
pool: poolname
state: DEGRADED
status: One or more devices has been taken offline by the administrator.
Sufficient replicas exist for the pool to continue functioning in a
degraded state.
action: Online the device using 'zpool online' or replace the device with
'zpool replace'.
scrub: resilver completed with 0 errors on Wed Oct 8 13:16:35 2008
config:
NAME STATE READ WRITE CKSUM
poolname DEGRADED 0 0 0
raidz1 DEGRADED 0 0 0
c3t0d0 OFFLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
errors: No known data errors
这样在执行zpool offline后,拆除该硬盘,并执行online操作,这时会发现pool中的硬盘状态为FAULTED。这时候由于raidz的校验功能,可以通过replace对硬盘进行更换并恢复数据到新盘上。
#/mnt> zpool status
pool: poolname
state: DEGRADED
status: One or more devices could not be used because the label is missing or
invalid. Sufficient replicas exist for the pool to continue
functioning in a degraded state.
action: Replace the device using 'zpool replace'.
see:
scrub: resilver completed with 0 errors on Wed Oct 8 14:03:47 2008
config:
NAME STATE READ WRITE CKSUM
poolname DEGRADED 0 0 0
raidz1 DEGRADED 0 0 0
c3t0d0 FAULTED 0 0 0 corrupted data
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
errors: No known data errors
#/mnt> zpool replace poolname c3t0d0 c3t2d0
#/mnt> zpool status
pool: poolname
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.
scrub: resilver in progress, 2.97% done, 0h3m to go
config:
NAME STATE READ WRITE CKSUM
poolname DEGRADED 0 0 0
raidz1 DEGRADED 0 0 0
replacing DEGRADED 0 0 0
c3t0d0 FAULTED 0 0 0 corrupted data
c3t2d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
errors: No known data errors
# zpool status
pool: poolname
state: ONLINE
scrub: resilver completed with 0 errors on Wed Oct 8 14:10:02 2008
config:
NAME STATE READ WRITE CKSUM
poolname ONLINE 0 0 0
raidz1 ONLINE 0 0 0
c3t2d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
如果是在原来的槽位上更换过硬盘以后再同步,直接输入:
zpool replace poolname c3t0d0
# zpool replace poolname c3t2d0
# zpool status
pool: poolname
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.
scrub: resilver in progress, 3.75% done, 0h2m to go
config:
NAME STATE READ WRITE CKSUM
poolname DEGRADED 0 0 0
raidz1 DEGRADED 0 0 0
replacing DEGRADED 0 0 0
c3t2d0s0/o UNAVAIL 0 0 0 cannot open
c3t2d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
errors: No known data errors
1.5 zpool的迁移
迁移zpool的时候需要确认zpool中所有的文件系统没有被使用,如果需要不顾一切的去迁移,可以加上-f参数。
# zpool export poolname
# zpool status
no pools available
#
# zpool import
pool: poolname
id: 10727618928512001646
state: ONLINE
action: The pool can be imported using its name or numeric identifier.
config:
poolname ONLINE
raidz1 ONLINE
c3t2d0 ONLINE
c3t3d0 ONLINE
c3t4d0 ONLINE
# zpool status
no pools available
# zpool import 10727618928512001646 使用pool的id和name都可以
# zpool status
pool: poolname
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
poolname ONLINE 0 0 0
raidz1 ONLINE 0 0 0
c3t2d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
1.6 恢复销毁的zpool
zpool 被destroy后,可以通过zpool import –D命令来查看上一个被销毁的zpool是否可以被恢复。
#/zzz> cp -r /opt /zzz
^C
#/zzz> ls
opt
#/zzz> du -sh .
3.6G .
#/zzz> cd
# zpool destroy zzz
# zpool import -D
pool: zzz
id: 7148440739272373876
state: ONLINE (DESTROYED)
action: The pool can be imported using its name or numeric identifier.
config:
zzz ONLINE
c3t0d0 ONLINE
c3t1d0 ONLINE
# zpool import -Df zzz
# zpool status
pool: zzz
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
zzz ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t1d0 ONLINE 0 0 0
errors: No known data errors
# cd /zzz
#/zzz> ls
opt
#/zzz> du –sh .
3.6G .
如果通过import –D看到的pool的状态不是online的话,那么这个pool就不可恢复了。
#/zzz> cd
# zpool destroy zzz
# zpool create zzz c3t0d0
# zpool import -D
pool: zzz
id: 7148440739272373876
state: FAULTED (DESTROYED)
status: One or more devices are missing from the system.
action: The pool cannot be imported. Attach the missing
devices and try again.
see:
config:
zzz UNAVAIL missing device
c3t1d0 ONLINE
Additional devices are known to be part of this pool, though their
exact configuration cannot be determined.
# zpool destroy zzz
# zpool import -D
pool: zzz
id: 7148440739272373876
state: FAULTED (DESTROYED)
status: One or more devices are missing from the system.
action: The pool cannot be imported. Attach the missing
devices and try again.
see:
config:
zzz UNAVAIL missing device
c3t1d0 ONLINE
Additional devices are known to be part of this pool, though their
exact configuration cannot be determined.
pool: zzz
id: 6600816109531139366
state: ONLINE (DESTROYED)
action: The pool can be imported using its name or numeric identifier.
config:
zzz ONLINE
c3t0d0 ONLINE
# zpool import -Df 7148440739272373876
cannot import 'zzz': one or more devices is currently unavailable
1.7 zpool的版本升级
如果将低版本操作系统下建立的zpool迁移到了高版本,则需要对zpool进行升级
使用zpool upgrade –v子命令来查看ZFS版本,使用zpool upgrade –a子命令来升级之前版本创建的zpool。
# zpool upgrade -a
This system is currently running ZFS version 4.
All pools are formatted using this version.
# zpool upgrade -v
This system is currently running ZFS version 4.
The following versions are supported:
VER DESCRIPTION
--- --------------------------------------------------------
1 Initial ZFS version
2 Ditto blocks (replicated metadata)
3 Hot spares and double parity RAID-Z
4 zpool history
For more information on a particular version, including supported releases, see:
Where 'N' is the version number.
Note:如果将池升级到最新版本,则在运行较早ZFS 版本的系统中将无法访问这些池。
迁移ZFS 存储池