ZFS文件系统下POOL的创建和删除详细过程分享
ZFS可从根本上改变文件系统的管理方式,并具有目前面市的其他任何文件系统所没有的功能和优点。ZFS 强健可靠、可伸缩、易于管理。ZFS文件系统是建立在存储池pool的基础上,所以要建立文件系统必须先建立底层的pool。
创建单边zpool
zpool create yz c3t0d0 c3t0d1
# zpool create First c3t2d0 c3t4d0
invalid vdev specification
use '-f' to override the following errors:
/dev/dsk/c3t2d0s2 contains a ufs filesystem.
/dev/dsk/c3t2d0s7 contains a ufs filesystem.
加入pool的硬盘可以是整块盘,也可以是某个分区,条件允许的时候建议使用整块盘,这样便于pool对硬盘的管理。由于加入pool的磁盘之前曾经使用过ufs,所以在创建过程中需要使用-f选项来忽视ufs文件格式将硬盘强制加入pool中。
Note:加入pool的硬盘的原来数据会被破坏。
# zpool create –f first c3t2d0 c3t3d0 创建两块盘组成的pool
# zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
first 136G 90K 136G 0% ONLINE -
# zpool status
pool: first
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
first ONLINE 0 0 0
c3t2d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
errors: No known data errors
创建mirror pool
# zpool create –f yz mirror c3t0d0 c3t1d0
# zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
first 136G 90K 136G 0% ONLINE -
yz 68G 6.08G 61.9G 8% ONLINE -
# zpool status
pool: yz
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
yz ONLINE 0 0 0
mirror ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t1d0 ONLINE 0 0 0
errors: No known data errors
创建镜像盘组成的pool,如果加入的硬盘为多个的话,则默认的raid类型为raid1+0,下例中,镜像为3份,单盘为68G,而pool总量为136G。
chinastor-root/yztest/2> zpool create xxx mirror c3t0d0 c3t1d0 c3t2d0 mirror c3t3d0 c3t4d0 c3t5d0
chinastor-root/yztest/2> zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
xxx 136G 90K 136G 0% ONLINE -
chinastor-root/yztest/2> zpool status
pool: xxx
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
xxx ONLINE 0 0 0
mirror ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t1d0 ONLINE 0 0 0
c3t2d0 ONLINE 0 0 0
mirror ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
c3t5d0 ONLINE 0 0 0
errors: No known data errors
# zpool status -x
all pools are healthy
# df -h
Filesystem size used avail capacity Mounted on
first 134G 24K 134G 1% /first
创建raidz zpool
zpool支持的raidz有raidz1和raidz2两种,类似于传统的raid5,raidz至少需要3个devices来实现对数据的校验。raidz也就是raidz1会消耗一块盘的空间,raidz2消耗凉快盘的空间。
# zpool create yz raidz1 c3t0d0 c3t1d0 c3t2d0 c3t3d0
# zpool status
pool: yz
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
yz ONLINE 0 0 0
raidz1 ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t1d0 ONLINE 0 0 0
c3t2d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
errors: No known data errors
# zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
yz 272G 147K 272G 0% ONLINE -
# df -h
Filesystem size used avail capacity Mounted on
yz 200G 36K 200G 1% /yz
# zpool create yz raidz2 c3t0d0 c3t1d0 c3t2d0 c3t3d0
# zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
yz 272G 226K 272G 0% ONLINE -
# df -h
Filesystem size used avail capacity Mounted on
yz 133G 36K 133G 1% /yz
# zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
yz 272G 226K 272G 0% ONLINE -
# zpool status
pool: yz
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
yz ONLINE 0 0 0
raidz2 ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t1d0 ONLINE 0 0 0
c3t2d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
errors: No known data errors
Note:同样是四块盘的raidz, raidz2消耗掉两块盘的空间,raidz1消耗一块盘的空间。raidz2的数据校验性应当是更强的。
删除zpool
zpool destroy poolname
如果zpool正在使用会提示设备正忙,强制删除pool使用-f参数。
chinastor-root/yztest/2> zpool destroy yz
cannot unmount '/yztest/2': Device busy
could not destroy 'yz': could not unmount datasets
chinastor-root/yztest/2> zpool destroy -f yz