迁移存储池 & 升级ZFS存储池 & 管理包含引导环境的ZFS池

  1. 为迁移ZFS存储池做准备
  2. 导出存储池
  3. 确定要导入的可用存储池
  4. 导入ZFS存储池
  5. 导入缺少日志设备的池
  6. 以只读模式导入池
  7. 使用特定设备路径导入池
  8. 恢复已销毁的ZFS存储池
  9. 升级ZFS存储池
  10. 管理包含引导环境的ZFS池

迁移存储池

ZFS存储池的迁移是通过“导出export”→“导入import”来完成的。
所谓迁移一般是指在系统之间移动存储池。先断开存储池与原始系统的连接,然后通过物理重新布线或使用多端口设备将它们重新连接到目标系统。

为迁移ZFS存储池做准备
要迁移存储池,必须将其先导出。此操作会将所有未写入的数据刷新到磁盘,然后标记为导出完成,并从系统中删除池的所有信息。
如果没有明确导出池而是手动移除磁盘,仍然可以在另一个系统上导入这个池,但可能会丢失最后几秒的数据事务。此外,由于设备不再存在,池在原始系统上将显示为UNAVAIL
默认情况下,目标系统无法导入尚未明确导出的池,此条件是必要的,以防止意外导入由仍在另一个系统上使用的网络附加存储组成的活动池。
top
导出存储池
使用以下命令导出池:
$ zpool export [option] pool
此命令会首先卸载掉指定池中任何已经挂载的文件系统。如果有文件系统无法卸载,可以使用-f选项强行卸载。
但是即使使用-f选项,池中ZFS卷如果正在使用中,也可能会导出失败。要导出含有ZFS卷的池,首先要确定所有包含的卷都不再处于活动状态。
如果导出时有设备不可用,则无法将设备识别为干净导出。如果这些设备之一后来连接到没有任何其他工作设备的系统,则它看起来可能处于活动状态。
top
确定要导入的可用存储池
ZFS检测任何移动或重命名的设备并适当调整配置。
尽管ZFS可以处理只有部分设备可用的某些情况,但是,迁移的成功取决于所有设备的整体健康状况。
导入池的命令如下:
$ zpool import [option] [pool|ID-number]

要找到可用来导入的池,可以使用zpool import不指定任何池。该命令会显示所有可以用于导入的池。
输出结果中,池由名称和唯一编号标识符标识。如果可供导入的池有相同的名称,则应使用数字标识符导入正确的池。
如果要导入的池存在问题,命令输出还会提供适当的信息来帮助确定要采取的操作。

下面例子中,其中一个设备丢失,但仍可以导入池,因为镜像数据仍然可以访问:
$ zpool import
 pool: system1
    id: 4715259469716913940
 state: DEGRADED
status: One or more devices are unavailable.
action: The pool can be imported despite missing or damaged devices.  The
        fault tolerance of the pool may be compromised if imported.
config:

    system1                         DEGRADED
       mirror-0                     DEGRADED
         c0t5000C500335E106Bd0      ONLINE
         c0t5000C500335FC3E7d0      UNAVAIL  cannot open

device details:

         c0t5000C500335FC3E7d0     UNAVAIL   cannot open
         status: ZFS detected errors on this device.
                The device was missing.		
		
而下面例子中,由于RAID-Z虚拟设备丢失了两个硬盘,没有足够的冗余数据来重建池。由于可用设备不足造成ZFS无法导入池。
$ zpool import
pool: mothership
    id: 3702878663042245922
 state: UNAVAIL
status: One or more devices are unavailable.
action: The pool cannot be imported due to unavailable devices or data.
config:

        mothership     UNAVAIL  insufficient replicas
          raidz1-0     UNAVAIL  insufficient replicas
            c8t0d0     UNAVAIL  cannot open
            c8t1d0     UNAVAIL  cannot open
            c8t2d0     ONLINE
            c8t3d0     ONLINE

device details:

        c8t0d0    UNAVAIL          cannot open
        status: ZFS detected errors on this device.
                The device was missing.

        c8t1d0    UNAVAIL          cannot open
        status: ZFS detected errors on this device.
                The device was missing.		
		
top
导入ZFS存储池
zpool import命令中指定池名称或数字ID可以导入池。另外,可以在导入为池重新命名。例如:
$ zpool import system1 mpool
以上操作将system1导入并改名为mpool
注意,不能直接重命名池。只能在导入或导出时重命名池,这也会将跟数据集重命名为新的池名称。
如果尝试导入一个正在其他系统中使用的池,会收到以下警告:
cannot import 'pool': pool may be in use on another system
use '-f' to import anyway		
		
不要尝试将一个系统上处于活动状态的池导入到另一个系统中。ZFS不是本机群集、分布式或并行文件系统,不能提供来自多个系统的并发访问。
可以使用-R选项在备用根目录下导入池。
top
导入缺少日志设备的池
默认情况下,无法导入缺少日志设备的池。可以使用zpool import -m命令强制导入缺少日志设备的池。
以下示例中,第一次导入池dozer时,提示缺少镜像日志,使用-m选项强制导入:
$ zpool import dozer
The devices below are missing, use '-m' to import the pool anyway:
mirror-1 [log]
c3t3d0
c3t4d0

cannot import 'dozer': one or more devices is currently unavailable

$ zpool import -m dozer
$ zpool status dozer
pool: dozer
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: URL to My Oracle Support knowledge article
scan: scrub repaired 0 in 0h0m with 0 errors on Fri Oct 15 16:51:39 2010
config:

NAME                   STATE     READ  WRITE  CKSUM
dozer                  DEGRADED     0      0      0
   mirror-0            ONLINE       0      0      0
      c3t1d0           ONLINE       0      0      0
      c3t2d0           ONLINE       0      0      0
   logs
   mirror-1                 UNAVAIL      0     0     0  insufficient replicas
      13514061426445294202  UNAVAIL      0     0     0  was c3t3d0
      16839344638582008929  UNAVAIL      0     0     0  was c3t4d0		
		
导入的池保持DEGRADED状态。根据输出建议,附加丢失的日志设备,然后运行zpool clean命令清除池错误。
top
以只读模式导入池
如果池损坏到无法访问的程度,以只读模式导入可能能够恢复池的而数据。例如:
$ zpool import -o readonly=on system1
$ zpool scrub system1
cannot scrub system1: pool is read-only		
		
当以只读模式导入池时,以下条件适用: 可以通过导出然后在导入的方法将池设置会读写模式,例如:
$ zpool export system1
$ zpool import system1
$ zpool scrub system1
		
top
使用特定设备路径导入池
默认情况下,zpool import命令仅在/dev目录中搜索设备。如果设备存在于另一个目录中,或者正在使用由文件组成的池,则必须使用-d选项来搜索备用目录。
例如:
$ zpool create mpool mirror /file/a /file/b
$ zpool export mpool
$ zpool import -d /file
  pool: mpool
    id: 7318163511366751416
 state: ONLINE
action: The pool can be imported using its name or numeric identifier.
config:

        mpool        ONLINE
          mirror-0   ONLINE
            /file/a  ONLINE
            /file/b  ONLINE
$ zpool import -d /file mpool		
		
如果设备存在于多个目录,则可以多次使用-d选项。

下面命令使用指定设备导入mpool池:
$ zpool import -d /dev/etc/c2t3d0 mpool
$ zpool status mpool
pool: mpool
state: ONLINE
scan: resilvered 952K in 0h0m with 0 errors on Fri Jun 29 16:22:06 2012
config:

NAME        STATE     READ WRITE CKSUM
mpool       ONLINE       0     0     0
mirror-0    ONLINE       0     0     0
  c2t3d0    ONLINE       0     0     0
  c2t1d0    ONLINE       0     0     0
		
top
恢复已销毁的ZFS存储池
可以使用zpool import -D命令查看和恢复被销毁的池。 以下例子中,system1被标记为已销毁:
$ zpool import -D
  pool: system1
    id: 5154272182900538157
 state: ONLINE (DESTROYED)
action: The pool can be imported using its name or numeric identifier.
config:

        system1     ONLINE
          mirror-0  ONLINE
            c1t0d0  ONLINE
            c1t1d0  ONLINE		
		
以下例子恢复被销毁的池:
$ zpool import -D system1
$ zpool status system1
  pool: system1
 state: ONLINE
 scrub: none requested
config:

        NAME        STATE     READ WRITE CKSUM
        system1     ONLINE       0     0     0
          mirror-0  ONLINE       0     0     0
            c1t0d0  ONLINE       0     0     0
            c1t1d0  ONLINE       0     0     0

errors: No known data errors
		
如果被销毁的池中有一个设备无法访问,可以使用-f选项恢复被销毁的池。恢复后的池会被标记为DESTROYED。例如:
$ zpool import -D
  pool: dozer
    id: 4107023015970708695
 state: DEGRADED (DESTROYED)
status: One or more devices are unavailable.
action: The pool can be imported despite missing or damaged devices.  The
        fault tolerance of the pool may be compromised if imported.
config:

        dozer              DEGRADED
          raidz2-0         DEGRADED
            c8t0d0         ONLINE
            c8t1d0         ONLINE
            c8t2d0         ONLINE
            c8t3d0         UNAVAIL  cannot open
            c8t4d0         ONLINE

device details:

        c8t3d0    UNAVAIL          cannot open
        status: ZFS detected errors on this device.
                The device was missing.
$ zpool import -Df dozer
$ zpool status -x
  pool: dozer
 state: DEGRADED
status: One or more devices are unavailable in response to persistent errors.
        Sufficient replicas exist for the pool to continue functioning in a
        degraded state.
action: Determine if the device needs to be replaced, and clear the errors
        using 'zpool clear' or 'fmadm repaired', or replace the device
        with 'zpool replace'.
        Run 'zpool status -v' to see device specific details.
  scan: none requested
config:

        NAME                     STATE     READ WRITE CKSUM
        dozer                    DEGRADED     0     0     0
          raidz2-0               DEGRADED     0     0     0
            c8t0d0               ONLINE       0     0     0
            c8t1d0               ONLINE       0     0     0
            c8t2d0               ONLINE       0     0     0
            4881130428504041127  UNAVAIL      0     0     0
            c8t4d0               ONLINE       0     0     0

errors: No known data errors
$ zpool online dozer c8t3d0
$ zpool status -x
all pools are healthy		
		
top

升级ZFS存储池

使用zpool upgrade命令可以将ZFS存储池升级到最新版。
在使用该命令前,应使用zpool status命令检查池是否配置了早于系统上当前版本的ZFS版本。此外,应考虑使用-v选项在系统上显示当前ZFS版本的功能。
如下所示:
$ zpool upgrade -v

使用-a选项升级池并启用最新功能:
$ zpool upgrade -a

升级池后,在运行早期ZFS版本的系统上将无法再访问它们。

例16 升级ZFS池
$ zpool status
  pool: system1
 state: ONLINE
status: The pool is formatted using an older on-disk format.  The pool can
        still be used, but some features are unavailable.
action: Upgrade the pool using 'zpool upgrade'.  Once this is done, the
        pool will no longer be accessible on older software versions.
 scrub: none requested
config:
        NAME        STATE     READ WRITE CKSUM
        system1     ONLINE       0     0     0
          mirror-0  ONLINE       0     0     0
            c1t0d0  ONLINE       0     0     0
            c1t1d0  ONLINE       0     0     0
errors: No known data errors

$ zpool upgrade -v
This system is currently running ZFS pool version version-number.

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
5   Compression using the gzip algorithm
.
.
Additional features

$ zpool upgrade -a				
		
top

管理包含引导环境的ZFS池

本节中使用beadm命令在FreeBSD系统中需要额外安装
beadm——boot environment adm——用来管理启动环境,可以比较zpool和zfs模块池版本,并在池升级会使相关BE无法启动以及BE激活失败时通知管理员。

例17 升级包含引导环境的zpool的池版本
以下命令尝试将zpool的版本升级到最高可用版本,该版本与系统(zfs模块)池版本47相同。该命令还确定rpool池版本是44,已经过期。
# zpool upgrade
This system is currently running ZFS pool version 47.

The following pools are out of date, and can be upgraded.  After being
upgraded, these pools will no longer be accessible by older software versions.

VER  POOL
---  ------------
44   rpool

Use 'zpool upgrade -v' for a list of available versions and their associated
features.

# zpool upgrade rpool
This system is currently running ZFS pool version 47.

rpool is on version 44 and will not upgrade without making BEs un-bootable

# zpool upgrade -n -V 47 rpool
This system is currently running ZFS pool version 47.

Upgrading to version 47 will make these BEs un-bootable
FMRI           Pool Version
-------------- ------------
be://rpool/BE1 44          
be://rpool/BE2 45          
be://rpool/BE3 46          
use "zpool upgrade -f -V 47 rpool" to force the upgrade.

# zpool upgrade -V 45 rpool
This system is currently running ZFS pool version 47.

Upgrading to version 45 will make this BE un-bootable
FMRI           Pool Version
-------------- ------------
be://rpool/BE1 44          
use "zpool upgrade -f -V 45 rpool" to force the upgrade.

# zpool upgrade -f -V 45 rpool
This system is currently running ZFS pool version 47.

Upgrading to version 45 will make this BE un-bootable
FMRI           Pool Version
-------------- ------------
be://rpool/BE1 44          
Pool 'rpool' upgraded from version 44 to version 45
		
		
以上作业当zpool版本大于BE支持的版本时,该BE将无法启动且无法再激活。该beadm列表输出显示一个感叹号(!),在无法启动的BE标志列。
以下命令尝试激活BE1并指出BE由于版本不匹配而不再可引导。
# beadm activate BE1
Unable to activate BE BE1:
BE BE1 supports version 44, pool version is 45

# beadm activate BE2

# beadm list -o name,pool_version,flags
BE Name          Pool Version Flags 
---------------- ------------ ----- 
BE1              44           !     
BE2              45           R     
BE3              46           -     
beadm            47           N     
solaris          47           -     
solaris-backup-1 47           -

# zpool upgrade -V 46 rpool
This system is currently running ZFS pool version 47.

Upgrading to pool version 46 would make the active on boot BE 'BE2' un-bootable

# zpool upgrade -V 46 -f rpool
This system is currently running ZFS pool version 47.

Upgrading to pool version 46 would make the active on boot BE 'BE2' un-bootable

# zpool upgrade -V 46 rpool2
This system is currently running ZFS pool version 47.

Upgrading to version 46 will make these BEs un-bootable
FMRI             Pool Version
---------------- ------------
TestBE           45
use "zpool upgrade -f -V 46 rpool2" to force the upgrade.

# beadm destroy -F TestBE
Warning: BE to be destroyed is the active on boot BE.  Making current active BE, be://rpool/beadm, to be the active on boot BE.

# zpool upgrade -V 46 rpool2
This system is currently running ZFS pool version 47.

Pool 'rpool2' upgraded from version 45 to version 46

# zpool upgrade rpool2
This system is currently running ZFS pool version 47.

rpool2 is on version 46 and will not upgrade without making more BEs un-bootable
		
		
此节似乎不适用于FreeBSD
top

2021/12/14