ZFS Guide
ZFS (Zettabyte File System) represents a revolutionary approach to storage management, combining a filesystem with a volume manager. Unlike traditional filesystems, ZFS provides end-to-end data integrity verification, automatic repair capabilities, efficient snapshots, and native RAID support—all while eliminating the complexity of separate volume management.
Core Concepts
Section titled “Core Concepts”Storage Pools (zpools) Storage pools form the foundation of ZFS storage management. Think of a pool as a dynamic storage container that:
- Combines multiple physical storage devices into a unified storage resource
- Manages physical storage allocation automatically
- Provides built-in redundancy through RAID-like configurations
- Allows all filesystems in the pool to share space dynamically
- Eliminates the need for traditional volume management
- Handles device failures and repairs automatically
Datasets Datasets are the fundamental building blocks for organizing data in ZFS. They offer:
- Flexible organization through filesystem hierarchies
- Independent property management (compression, quotas, etc.)
- Dynamic space sharing from the pool without pre-allocation
- Four main types:
- Filesystems: Standard filesystems for general data storage
- Volumes (zvols): Block devices for applications needing raw devices
- Snapshots: Point-in-time copies of filesystems or volumes
- Clones: Writable copies of snapshots
Snapshots Snapshots provide powerful data protection and recovery capabilities:
- Create instantaneous, read-only copies of filesystems or volumes
- Initially consume no additional space
- Store only changed blocks from the active dataset
- Enable quick recovery from mistakes or unwanted changes
- Support efficient backups and rollbacks
- Accessible through the hidden .zfs/snapshot directory
Basic Pool Operations
Section titled “Basic Pool Operations”Creating Storage Pools Storage pools can be configured in various RAID-like configurations to balance redundancy, performance, and storage capacity:
# Simple pool with single disk (not recommended for important data)zpool create tank /dev/sda
# Mirrored pool (RAID-1) - Best for 2-drive configurationszpool create tank mirror /dev/sda /dev/sdb
# RAID-Z1 pool (Single parity, similar to RAID-5) - Minimum 3 driveszpool create tank raidz1 /dev/sda /dev/sdb /dev/sdc
# RAID-Z2 pool (Double parity, similar to RAID-6) - Minimum 4 driveszpool create tank raidz2 /dev/sda /dev/sdb /dev/sdc /dev/sdd
# Create pool with specific sector size alignment (recommended for modern drives)zpool create -o ashift=12 tank mirror /dev/sda /dev/sdbPool Management Regular pool maintenance and monitoring are essential for data integrity:
# Check pool status and healthzpool status tank
# List all pools and their basic informationzpool list
# Start pool scrub (verifies all data against checksums)zpool scrub tank
# Import/export pools (for moving between systems)zpool export tankzpool import tank
# Destroy pool (permanent and irreversible)zpool destroy tankDataset Operations
Section titled “Dataset Operations”Creating and Managing Filesystems Datasets provide flexible data organization with inheritable properties:
# Create new filesystemzfs create tank/data
# Create nested filesystemzfs create tank/data/documents
# Set custom mount pointzfs set mountpoint=/mnt/data tank/data
# Enable compression (recommended for most use cases)zfs set compression=lz4 tank/data
# Set quota to limit space usagezfs set quota=100G tank/dataDataset Destruction and Management Safe dataset removal requires understanding the implications:
# Remove dataset and all descendantszfs destroy -r tank/data
# Dry run - show what would be destroyedzfs destroy -r -n tank/data
# Remove specific snapshotzfs destroy tank/data@snapshot1
# Remove all snapshots of a datasetzfs destroy tank/data@%
# Remove snapshots matching patternzfs destroy tank/data@backup-2023*Snapshot Management
Section titled “Snapshot Management”Snapshots are crucial for data protection and provide a safety net for system administration:
# Create snapshot with timestampzfs snapshot tank/data@$(date +%Y-%m-%d-%H%M)
# Create recursive snapshot of dataset and all descendantszfs snapshot -r tank@backup-2025-01-03
# List all snapshotszfs list -t snapshot
# Rollback to snapshot (destroys newer snapshots)zfs rollback tank/data@backup-2025-01-03
# Create writable clone from snapshotzfs clone tank/data@backup-2025-01-03 tank/data_cloneAdvanced Features
Section titled “Advanced Features”Data Transfer and Backup ZFS provides powerful tools for data replication and backup:
# Full backup: Send snapshot to filezfs send tank/data@backup-2025-01-03 > backup.zfs
# Remote backup: Send to another systemzfs send tank/data@backup-2025-01-03 | ssh remote_host zfs recv backup/data
# Incremental backup: Send only changes between snapshotszfs send -i tank/data@old tank/data@new | ssh backup_host zfs recv tank/backup
# Send with properties and resume supportzfs send -p tank/data@backup | gzip > backup.gzzfs send -Rv tank/data@backupPool Device Management ZFS allows dynamic modification of storage pools:
# Add read cache device (L2ARC)zpool add tank cache /dev/sdd
# Add write log device (ZIL)zpool add tank log /dev/sde
# Remove device (only for some device types)zpool remove tank /dev/sdd
# Take device offline for maintenancezpool offline tank /dev/sdazpool online tank /dev/sdaDataset Properties ZFS provides extensive property management:
# View all propertieszfs get all tank/data
# Set multiple properties at oncezfs set quota=100G compression=lz4 tank/data
# Inherit property from parent datasetzfs inherit compression tank/data
# Set property recursively on all descendantszfs set compression=lz4 -r tank
# View specific propertieszfs get compression,compressratio,used,available tank/dataPerformance Monitoring Regular monitoring helps maintain optimal performance:
# Monitor IO statistics in real-timezpool iostat -v tank 5
# Check compression efficiencyzfs get compressratio tank/data
# Monitor space usagezfs list -o name,used,available,referenced tank
# View detailed pool performancezpool iostat -v tank 1Advanced Maintenance
Section titled “Advanced Maintenance”Health Monitoring Regular health checks are crucial for data integrity:
# Detailed pool health statuszpool status -v tank
# View command historyzpool history tank
# Check for errors across all poolszpool status -x
# Clear transient device errorszpool clear tankData Recovery ZFS provides various recovery options for different failure scenarios:
# Force import potentially damaged poolzpool import -f tank
# Import pool with different namezpool import oldtank newtank
# Recovery mode import (may lose recent transactions)zpool import -F tank
# Replace failed drivezpool replace tank /dev/sda /dev/sdcPerformance Tuning Optimize ZFS for specific workloads:
# Optimize for databaseszfs set recordsize=8K tank/databasezfs set logbias=throughput tank/databasezfs set primarycache=metadata tank/database
# Enable deduplication (requires significant RAM)zfs set dedup=on tank/data
# Configure cache behaviorzfs set primarycache=all tank/datazfs set secondarycache=all tank/dataBest Practices
Section titled “Best Practices”Pool Design
- Use
ashift=12for modern drives (4K sectors) - Choose appropriate RAID levels:
- Mirror (RAID-1): Best for 2 drives, highest performance
- RAID-Z1: Minimum 3 drives, single drive failure tolerance
- RAID-Z2: Minimum 4 drives, two drive failure tolerance
- Maintain 10-20% free space for optimal performance
- Use whole disks instead of partitions
- Consider separate log devices for sync-heavy workloads
Dataset Organization
- Create separate datasets for different types of data
- Use consistent naming conventions:
tank/├── home/│ └── users/├── vm/│ └── images/├── backup/└── shared/
- Set appropriate properties per dataset type:
- Databases: smaller recordsize, no compression
- Virtual machines: larger recordsize, compression
- User data: default recordsize, compression enabled
Backup Strategy
- Implement 3-2-1 backup rule:
- 3 copies of data
- 2 different media types
- 1 off-site copy
- Regular snapshot schedule:
Terminal window # Hourly snapshots retained for 24 hours# Daily snapshots retained for 30 days# Weekly snapshots retained for 6 months - Test backup restoration regularly
- Use incremental replication for efficiency
Maintenance Schedule
- Daily Tasks:
- Monitor pool status
- Check for errors
- Verify backup completion
- Weekly Tasks:
- Run scrub operations
- Review snapshot usage
- Check compression ratios
- Monthly Tasks:
- Review storage utilization
- Clean up old snapshots
- Verify backup integrity
- Quarterly Tasks:
- Test disaster recovery procedures
- Review performance metrics
- Update documentation
Prerequisites and Requirements
Section titled “Prerequisites and Requirements”Hardware Considerations
- Memory Requirements:
- Minimum: 2GB RAM for basic usage
- Recommended: 1GB RAM per 1TB storage for general use
- Deduplication: 5GB RAM per 1TB of deduplicated data
- Storage Devices:
- Enterprise-grade drives recommended for production
- SSDs for ZIL (write cache) and L2ARC (read cache)
- ECC RAM highly recommended for data integrity
- Network (for replication):
- Gigabit or faster network for efficient backups
- Dedicated network for replication traffic recommended
Software Requirements
- Operating System:
- 64-bit OS required
- Kernel with ZFS support
- Compatible ZFS version across systems for replication
- Packages:
Terminal window # Ubuntu/Debianapt install zfsutils-linux# RHEL/CentOSdnf install zfs# FreeBSDZFS included by default
Common Issues and Solutions
Section titled “Common Issues and Solutions”Pool Problems
Degraded Pool
# Check detailed statuszpool status -x
# Identify failed devicezpool status tank
# Replace failed devicezpool replace tank /dev/sda /dev/sdc
# Clear errors after resolutionzpool clear tankImport Issues
# Scan for importable poolszpool import
# Force import potentially damaged poolzpool import -f tank
# Import pool with missing devicezpool import -m tankSpace Management
Finding Space Usage
# List large filesystemszfs list -o name,used,referenced -s used
# Find snapshot space usagezfs list -t snapshot -o name,used,referenced
# Show space usage by typezfs list -o name,used,usedbysnapshots,usedbydatasetRecovering Space
# Remove old snapshotszfs destroy tank/data@old-snapshot
# Destroy all snapshots of a datasetzfs destroy tank/data@%
# Set compression to reduce space usagezfs set compression=lz4 tankPerformance Issues
Slow Performance
# Check IO statisticszpool iostat -v tank 1
# Monitor cache hit ratioarc_summary
# Check device latencyzpool iostat -w tankFragmentation
# Check fragmentation levelzpool list -v tank
# Scrub pool to optimizezpool scrub tankAdvanced Troubleshooting
Section titled “Advanced Troubleshooting”Data Recovery Scenarios
Corrupted Data
# Check for checksum errorszpool status -v tank
# Attempt automatic repairzpool scrub tank
# Clear transient errorszpool clear tankSnapshot Recovery
# List all snapshots including hidden oneszfs list -t snapshot -r tank
# Mount snapshot for file recoverymkdir /mnt/recovermount -t zfs tank/data@snapshot /mnt/recoverSystem Integration
Boot Environment Management
# Create boot environment snapshotzfs snapshot rpool/ROOT/default@before_upgrade
# Clone boot environmentzfs clone rpool/ROOT/default@before_upgrade rpool/ROOT/new_bePerformance Monitoring Integration
# Monitor ZFS performance metricszpool iostat -v 5
# Archive performance datazpool iostat -v 5 | tee /var/log/zfs/perf.logRemember that ZFS is a powerful but complex system. Always:
- Test changes in a non-production environment first
- Maintain current backups before major operations
- Document all configuration changes
- Monitor system resources regularly
- Keep ZFS software updated
- Verify data integrity periodically
This comprehensive guide covers most common ZFS operations and maintenance tasks. However, specific environments may require additional tuning and configuration.