Creating Storage Pools
The zpool create command allows creating mirrored configurations using multiple drives:
zpool create [pool_name] mirror [device1] [device2] ...
Multiple mirror groups can be established by repeating the mirror keyword:
[root@server ~]# zpool create -f datapool mirror sdc sdd mirror sde sdf
[root@server ~]# zpool status
pool: datapool
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
datapool ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
sdc ONLINE 0 0 0
sdd ONLINE 0 0 0
mirror-1 ONLINE 0 0 0
sde ONLINE 0 0 0
sdf ONLINE 0 0 0
errors: No known data errors
RAID-Z configurations can also be created:
[root@server ~]# zpool create -f storagepool raidz sdc sdd sde sdf
[root@server ~]# zpool status
pool: storagepool
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
storagepool ONLINE 0 0 0
raidz1-0 ONLINE 0 0 0
sdc ONLINE 0 0 0
sdd ONLINE 0 0 0
sde ONLINE 0 0 0
sdf ONLINE 0 0 0
errors: No known data errors
Pool Device Management
After creating a pool, hot spares and cache devices can be added or removed. Devices can be attached to or detached from mirror configurations, but redundant and RAID-Z devices cannot be removed from the pool.
Creating a basic pool and adding additional devices:
[root@server ~]# zpool create -f workpool sdc sdd
[root@server ~]# zpool add workpool sde
[root@server ~]# zpool status
pool: workpool
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
workpool ONLINE 0 0 0
sdc ONLINE 0 0 0
sdd ONLINE 0 0 0
sde ONLINE 0 0 0
errors: No known data errors
Attempting to remove non-redundant devices fails:
[root@server ~]# zpool remove workpool sde
cannot remove sde: only inactive hot spares, cache, top-level, or log devices can be removed
However, spare disks can be added and subsequently removed:
[root@server ~]# zpool add workpool spare sdf
[root@server ~]# zpool status
pool: workpool
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
workpool ONLINE 0 0 0
sdc ONLINE 0 0 0
sdd ONLINE 0 0 0
sde ONLINE 0 0 0
spares
sdf AVAIL
errors: No known data errors
[root@server ~]# zpool remove workpool sdf
Device attachment and detachment commands:
zpool attach [pool] [target_device] [new_device]
zpool detach [pool] [device]
For failed devices, replacement is accomplished with:
zpool replace [pool] [old_device] [new_device]
Testing device failure in mirror configuration:
[root@server ~]# zpool create -f workpool mirror sdd sde
Simulating disk corruption:
[root@server ~]# dd if=/dev/zero of=/dev/sdd
dd: writing to '/dev/sdd': No space left on device
2048001+0 records in
2048000+0 records out
1048576000 bytes (1.0 GB) copied, 22.4804 s, 46.6 MB/s
Using scrub to detect corruption:
[root@server ~]# zpool scrub workpool
[root@server ~]# zpool status
pool: workpool
state: ONLINE
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'.
config:
NAME STATE READ WRITE CKSUM
workpool ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
sdd UNAVAIL 0 0 0 corrupted data
sde ONLINE 0 0 0
errors: No known data errors
Replacing the corrupted device:
[root@server ~]# zpool replace workpool sdd sdc
[root@server ~]# zpool status
pool: workpool
state: ONLINE
scan: resilvered 83.5K in 0h0m with 0 errors
config:
NAME STATE READ WRITE CKSUM
workpool ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
sdc ONLINE 0 0 0
sde ONLINE 0 0 0
errors: No known data errors
Pool Migration
Pools can be migrated between hosts using export and import commands:
[root@server ~]# zpool export workpool
[root@server ~]# zpool status
no pools available
Listing available pools for import:
[root@destination ~]# zpool import
pool: workpool
id: 3823664125009563520
state: ONLINE
action: The pool can be imported using its name or numeric identifier.
config:
workpool ONLINE
sdc ONLINE
sdd ONLINE
sde ONLINE
Importing the pool:
[root@destination ~]# zpool import workpool
I/O Statistics
Monitoring I/O performance:
[root@server ~]# zpool iostat -v workpool
capacity operations bandwidth
pool alloc free read write read write
---------- ----- ----- ----- ----- ----- -----
workpool 1.80M 2.86G 22 27 470K 417K
sdc 598K 975M 8 9 200K 139K
sdd 636K 975M 7 9 135K 139K
sde 610K 975M 6 9 135K 139K
---------- ----- ----- ----- ----- ----- -----
ZFS File System Operations
Creating and Destroying File Systems
Creating file systems within pools:
zfs create [pool]/[dataset]
[root@server ~]# zfs create workpool/users
[root@server ~]# zfs create workpool/projects
[root@server ~]# df -h
Filesystem Size Used Avail Use% Mounted on
workpool 2.8G 0 2.8G 0% /workpool
workpool/users 2.8G 0 2.8G 0% /workpool/users
workpool/projects 2.8G 0 2.8G 0% /workpool/projects
Listing file systems:
[root@server ~]# zfs list
NAME USED AVAIL REFER MOUNTPOINT
workpool 100M 2.67G 19K /workpool
workpool/projects 31K 1024M 20.5K /workpool/projects
workpool/users 1.57M 98.4M 1.57M /workpool/users
Destroying file systems:
zfs destroy [pool]/[dataset]
Compression
Enabling compression on file systems:
zfs set compression=[algorithm] [dataset]
[root@server ~]# zfs set compression=lz4 workpool/users
Verifying compression ratio:
[root@server ~]# cp /var/log/messages /workpool/users/
[root@server ~]# zfs get compressratio workpool
NAME PROPERTY VALUE SOURCE
workpool compressratio 8.75x
Quotas and Reservations
Setting quotas to limit disk usage:
zfs set quota=[size] [dataset]
zfs set reservation=[size] [dataset]
[root@server ~]# zfs set quota=100M workpool/users
[root@server ~]# zfs set reservation=100M workpool/users
[root@server ~]# zfs set quota=1G workpool/projects
Snapshots
Snapshots provide point-in-time read-only copies of file systems with out consuming extra space initially.
Creating sample files:
[root@server ~]# cd /workpool/projects/
[root@server projects]# mkdir engineering research development
[root@server projects]# echo "Project specifications" > specs.txt
Creating snapshots:
zfs snapshot [dataset]@[snapshot_name]
[root@server projects]# zfs snapshot workpool/projects@backup-032016
[root@server projects]# zfs list -t snapshot
NAME USED AVAIL REFER MOUNTPOINT
workpool/projects@backup-032016 0 - 20.5K
Recovering files from snapshots:
[root@server projects]# rm specs.txt
[root@server projects]# ls
engineering research development
[root@server projects]# cd .zfs/snapshot/backup-032016/
[root@server backup-032016]# ls
engineering research development specs.txt
[root@server backup-032016]# cp specs.txt /workpool/projects/
Listing all snapshots:
[root@server ~]# zfs list -t snapshot
NAME USED AVAIL REFER MOUNTPOINT
workpool/projects@backup-032016 10.5K - 20.5K -