Know How -- ZFS -- First Steps
Getting started
- zpool list: Show the current ZFS pools available
Create a pool
Note that you will see the pool as /POOLNAME, it is automatically mounted.- zpool create POOLNAME mirror DISK1 DISK2 mirror DISK3 DISK4 ..: Create mirrored devices
- zpool create POOLNAME raidz1 DISK1 DISK2 ..: Create a RAIDZ1 (1 parities)
- zpool create POOLNAME raidz2 DISK1 DISK2 DISK3 ..: Create a RAIDZ2 (2 parities)
- zpool add POOLNAME DISK
Put a filesystem into the pool
There already is a filesystem named after the pool. However it is good practise to create new ones on demand (instead of creating directories), as this improves managability (snapshotting):- zfs create POOLNAME/filesystemname
- zfs get all
- zfs set property=value FSNAME
Re-enable a pool after some crash
Sometimes I have weird errors like an USB hub going out of business. In such a case ZFS cannot continue as it ran out of redundancy. In this case you have to re-enable the disks. The most easy way is to reactivate the pool:- zpool export POOLNAME: This takes a pool offline. This means: Unmount the paths and quiesce all background tasks like scrub. You then can switch of the drives or shuffle them.
- zpool import POOLNAME: This really is a magic command. If scans all drives of a system (yes, really) and locates any pool. It is somewhat slow, not because of ZFS, the scan takes a while until everything has reported back.
- zfs offline POOLNAME device
- zfs online POOLNAME device
Compare NFS: You can have hard and soft mounts. Soft mounts have a timeout, while hard mounts have no timeouts. When NFS fails, the clients then will wait until NFS comes back again.
So it must be possible to take back online any number of faulted devices without interrupting any process. If ZFS cannot do so, ZFS would be badly designed.
Check the pool
Everything is likewise simple:- zpool status
- zpool scrub
Enable compression on all ZFS volumes
- zfs inherit -r compression POOLNAME
- zfs set compression=on POOLNAME
- zfs set compression=on POOLNAME/filesystem
Additional information
Why filesystems?
Filesystems allow you to express quotas. Not quotas as you thought of quotas before, but something more like quotas seen because of a limited drive space. On an FS you can give an upper limit. But different to LVMs you can overcommit ZFS, that is, you can define 10 FS a 1 GB each on a 2 GB ZFS. All will share the maximum available space of 2 GB, but no single FS can eat up all available space itself this way. Think of it. It's really convenient. And you can modify behavior like compression on and the like. This mainly is if you want to partition your storage pool. As you will tend to only have one huge storage pool and ZFS will spread all the FS over this pool. But perhaps you will limit an FS to stay on certain drives, and ZFS will honor this hints then. But most important: You do snapshots on FS level! This is, if you want to backup a /home/ of a user and if you did it right, you just take a snapshot of the home FS of the particuliar user. This takes less than a second (literally!). If you want to ensure a consistent state you can take offline the FS before, take the snapshot and bring it back online. This, too, takes only a second or so. Well, I am, myself, not yet used to this fact, but if you will use it regularily, you will start to use ZFS filesystems like you used directories before.Monitoring
- zpool iostat 3: Like vmstat 3 or iostat 3.
- zfs get all: List all the filesystem properties, like "zfs get compressratio".
- zpool status -x >/dev/null: Check if everything is OK
- zpool history: Show a log