How to list/set ZFS props → zfs get|set pool/fs
How to List and Set ZFS Properties: Complete Guide to `zfs get` and `zfs set` Commands
Table of Contents
1. [Introduction](#introduction)
2. [Prerequisites](#prerequisites)
3. [Understanding ZFS Properties](#understanding-zfs-properties)
4. [Listing ZFS Properties with `zfs get`](#listing-zfs-properties-with-zfs-get)
5. [Setting ZFS Properties with `zfs set`](#setting-zfs-properties-with-zfs-set)
6. [Common ZFS Properties and Use Cases](#common-zfs-properties-and-use-cases)
7. [Advanced Property Management](#advanced-property-management)
8. [Troubleshooting Common Issues](#troubleshooting-common-issues)
9. [Best Practices](#best-practices)
10. [Conclusion](#conclusion)
Introduction
ZFS (Zettabyte File System) is a powerful, enterprise-grade file system that offers advanced features through configurable properties. These properties control everything from compression and deduplication to quotas and snapshots. Understanding how to effectively list and modify ZFS properties using the `zfs get` and `zfs set` commands is essential for any system administrator working with ZFS storage systems.
This comprehensive guide will teach you how to view current property settings, modify them to optimize performance and functionality, and troubleshoot common issues that arise during property management. Whether you're managing a single pool or multiple complex datasets, mastering these commands will significantly enhance your ZFS administration capabilities.
Prerequisites
Before diving into ZFS property management, ensure you have:
System Requirements
- A system with ZFS installed (Solaris, FreeBSD, Linux with ZFS, or illumos-based OS)
- Administrative privileges (root or sudo access)
- At least one ZFS pool and dataset created
- Basic understanding of ZFS concepts (pools, datasets, filesystems)
Command Line Access
- Terminal or SSH access to the ZFS system
- Familiarity with basic command-line operations
Verification Steps
Verify your ZFS installation and available pools:
```bash
Check ZFS version
zfs version
List available pools
zpool list
List datasets
zfs list
```
Understanding ZFS Properties
ZFS properties are configuration settings that control the behavior and characteristics of pools, filesystems, volumes, and snapshots. These properties fall into several categories:
Property Types
Native Properties: Built into ZFS and cannot be removed
- Examples: `compression`, `dedup`, `quota`, `recordsize`
User Properties: Custom properties defined by administrators
- Format: `namespace:property_name`
- Example: `myorg:backup_policy`
Inherited Properties: Properties passed down from parent datasets
- Child datasets inherit unless explicitly overridden
Property Sources
Properties can originate from different sources:
- local: Set directly on the dataset
- inherited: Inherited from parent dataset
- default: ZFS default value
- temporary: Set temporarily (lost on reboot)
- received: Set through `zfs receive` operation
Listing ZFS Properties with `zfs get`
The `zfs get` command retrieves property values from ZFS datasets. Its flexibility allows you to query specific properties, multiple properties, or all properties across various datasets.
Basic Syntax
```bash
zfs get [-r] [-H] [-p] [-s source] [-t type] property[,property...] [filesystem|volume|snapshot]...
```
Common Options
- `-r`: Recursively display properties for all children
- `-H`: Scripted mode (no headers, tab-separated)
- `-p`: Display exact values (no human-readable formatting)
- `-s source`: Display properties from specific sources only
- `-t type`: Limit to specific dataset types
Basic Property Retrieval
Get a single property:
```bash
Get compression setting for a specific dataset
zfs get compression mypool/data
Output example:
NAME PROPERTY VALUE SOURCE
mypool/data compression lz4 local
```
Get multiple properties:
```bash
Get multiple properties separated by commas
zfs get compression,dedup,quota mypool/data
```
Get all properties:
```bash
Display all properties for a dataset
zfs get all mypool/data
```
Recursive Property Listing
List properties for all child datasets:
```bash
Recursively show compression for all datasets under mypool
zfs get -r compression mypool
```
Filter by property source:
```bash
Show only locally set properties
zfs get -s local -r all mypool
Show inherited properties
zfs get -s inherited -r all mypool
```
Scripted Output Format
For automation and scripting, use the `-H` flag:
```bash
Machine-readable output
zfs get -H compression mypool/data
Output: mypool/data compression lz4 local
```
Advanced Filtering Examples
Get properties for specific dataset types:
```bash
Only filesystems
zfs get -t filesystem compression mypool
Only snapshots
zfs get -t snapshot used mypool
```
Multiple datasets and properties:
```bash
Get quota and used space for multiple datasets
zfs get quota,used mypool/data mypool/backup mypool/logs
```
Setting ZFS Properties with `zfs set`
The `zfs set` command modifies ZFS properties. Changes take effect immediately and persist across reboots unless specified as temporary.
Basic Syntax
```bash
zfs set property=value [property=value...] filesystem|volume|snapshot
```
Setting Single Properties
Enable compression:
```bash
Set LZ4 compression
zfs set compression=lz4 mypool/data
Verify the change
zfs get compression mypool/data
```
Set quotas:
```bash
Set 100GB quota
zfs set quota=100G mypool/data
Set reservation
zfs set reservation=50G mypool/data
```
Setting Multiple Properties
Configure multiple properties simultaneously:
```bash
Set compression, dedup, and quota in one command
zfs set compression=gzip dedup=on quota=500G mypool/data
```
Property Inheritance
Inherit from parent dataset:
```bash
Remove local setting and inherit from parent
zfs inherit compression mypool/data/subdataset
Verify inheritance
zfs get -s inherited compression mypool/data/subdataset
```
Set properties that children will inherit:
```bash
Set compression on parent - children will inherit
zfs set compression=lz4 mypool/data
Create child dataset - automatically inherits compression
zfs create mypool/data/child
zfs get compression mypool/data/child
```
Common ZFS Properties and Use Cases
Compression Properties
Available compression algorithms:
```bash
View available compression options
zfs get -o property,value compression mypool
Common compression settings
zfs set compression=off mypool/data # Disable compression
zfs set compression=lz4 mypool/data # Fast compression
zfs set compression=gzip mypool/data # High compression
zfs set compression=gzip-9 mypool/data # Maximum compression
```
Compression level examples:
```bash
For databases (fast access, moderate compression)
zfs set compression=lz4 mypool/database
For archives (maximum compression)
zfs set compression=gzip-9 mypool/archive
For temporary data (no compression overhead)
zfs set compression=off mypool/temp
```
Quota and Space Management
Setting quotas:
```bash
Dataset quota (limits total space)
zfs set quota=1T mypool/users
Reference quota (limits non-snapshot space)
zfs set refquota=500G mypool/users
User quota (per-user limits)
zfs set userquota@john=100G mypool/users
zfs set userquota@jane=50G mypool/users
```
Space reservations:
```bash
Guarantee space availability
zfs set reservation=100G mypool/critical
Reference reservation
zfs set refreservation=50G mypool/critical
```
Performance Tuning Properties
Record size optimization:
```bash
For databases (small random I/O)
zfs set recordsize=8K mypool/database
For large sequential files
zfs set recordsize=1M mypool/media
Default record size
zfs set recordsize=128K mypool/general
```
Caching properties:
```bash
Disable ARC caching for infrequently accessed data
zfs set primarycache=none mypool/archive
Enable all caching
zfs set primarycache=all secondarycache=all mypool/active
```
Data Integrity Properties
Deduplication:
```bash
Enable deduplication (use carefully - high memory usage)
zfs set dedup=on mypool/data
Verify deduplication
zfs set dedup=verify mypool/data
Disable deduplication
zfs set dedup=off mypool/data
```
Checksums:
```bash
Set checksum algorithm
zfs set checksum=sha256 mypool/important
For performance-critical applications
zfs set checksum=fletcher4 mypool/performance
```
Snapshot Properties
Automatic snapshots:
```bash
Configure snapshot retention
zfs set com.sun:auto-snapshot=true mypool/data
zfs set com.sun:auto-snapshot:hourly=24 mypool/data
zfs set com.sun:auto-snapshot:daily=7 mypool/data
```
Advanced Property Management
User-Defined Properties
Creating custom properties:
```bash
Set custom properties with namespace
zfs set myorg:backup_schedule="daily" mypool/data
zfs set myorg:owner="database_team" mypool/database
zfs set myorg:environment="production" mypool/prod
Retrieve custom properties
zfs get myorg:backup_schedule mypool/data
```
Conditional Property Setting
Using shell scripting for conditional settings:
```bash
#!/bin/bash
Set compression based on dataset size
DATASET="mypool/data"
SIZE=$(zfs get -Hp used $DATASET | awk '{print $3}')
if [ $SIZE -gt 107374182400 ]; then # 100GB
zfs set compression=gzip-6 $DATASET
echo "Set high compression for large dataset"
else
zfs set compression=lz4 $DATASET
echo "Set fast compression for smaller dataset"
fi
```
Batch Property Operations
Setting properties across multiple datasets:
```bash
#!/bin/bash
Apply compression to all user datasets
for dataset in $(zfs list -H -o name | grep "mypool/users/"); do
zfs set compression=lz4 quota=100G $dataset
echo "Configured $dataset"
done
```
Property Templates
Creating property configuration templates:
```bash
#!/bin/bash
Database optimization template
apply_database_template() {
local dataset=$1
zfs set recordsize=8K $dataset
zfs set compression=lz4 $dataset
zfs set checksum=fletcher4 $dataset
zfs set logbias=throughput $dataset
zfs set primarycache=metadata $dataset
echo "Applied database template to $dataset"
}
Usage
apply_database_template mypool/database
```
Troubleshooting Common Issues
Permission Errors
Problem: "Permission denied" when setting properties
```bash
Error example
zfs set compression=lz4 mypool/data
cannot set property for 'mypool/data': permission denied
```
Solutions:
```bash
Use sudo
sudo zfs set compression=lz4 mypool/data
Check user permissions
zfs allow mypool/data
Grant specific permissions
zfs allow user compression,quota mypool/data
```
Property Setting Failures
Problem: Property cannot be set due to constraints
```bash
Error example
zfs set quota=50G mypool/data
cannot set property for 'mypool/data': size is greater than available space
```
Solutions:
```bash
Check current usage
zfs get used,available mypool/data
Check space availability in pool
zpool list mypool
Adjust quota to realistic value
zfs set quota=200G mypool/data
```
Inheritance Issues
Problem: Properties not inheriting as expected
```bash
Check inheritance chain
zfs get -s inherited compression mypool/data/child
Force inheritance
zfs inherit compression mypool/data/child
Verify source
zfs get -o name,property,value,source compression mypool/data/child
```
Performance Impact
Problem: Property changes causing performance issues
```bash
Deduplication causing high memory usage
zfs get dedup,dedupratio mypool/data
Solution: Disable dedup and monitor
zfs set dedup=off mypool/data
Check compression overhead
zfs get compressratio mypool/data
```
Invalid Property Values
Problem: Setting invalid property values
```bash
Check valid values for a property
zfs get -o property,value compression
Common valid values:
compression: off, lz4, gzip, gzip-1 through gzip-9, zle
checksum: on, off, fletcher2, fletcher4, sha256
dedup: on, off, verify, sha256, verify,sha256
```
Best Practices
Performance Optimization
Choose appropriate compression:
```bash
For general use (good balance)
zfs set compression=lz4
For write-heavy workloads
zfs set compression=off
For archival data
zfs set compression=gzip-6
```
Optimize record sizes:
```bash
Match application I/O patterns
Database: 8K-16K
zfs set recordsize=8K mypool/database
Virtual machines: 64K
zfs set recordsize=64K mypool/vms
Large files: 1M
zfs set recordsize=1M mypool/media
```
Space Management
Implement quota strategies:
```bash
Set quotas before datasets grow large
zfs set quota=1T mypool/users
Use refquotas for snapshot-heavy datasets
zfs set refquota=500G mypool/development
Monitor quota usage regularly
zfs get quota,used,available mypool/users
```
Monitoring and Maintenance
Regular property auditing:
```bash
#!/bin/bash
Audit script for ZFS properties
echo "=== ZFS Property Audit ==="
echo "Datasets without compression:"
zfs get -r -H compression | awk '$3=="off" {print $1}'
echo "Datasets with dedup enabled:"
zfs get -r -H dedup | awk '$3!="off" {print $1}'
echo "Quota utilization > 80%:"
zfs list -o name,quota,used | awk 'NR>1 && $2!="none" {
gsub(/[KMGT]/, "", $2); gsub(/[KMGT]/, "", $3);
if ($3/$2 > 0.8) print $1, ($3/$2)*100"%"
}'
```
Security Considerations
Property delegation:
```bash
Grant limited property permissions
zfs allow user compression,quota,reservation mypool/userdata
Review permissions regularly
zfs allow mypool
Revoke unnecessary permissions
zfs unallow user compression mypool/userdata
```
Documentation and Change Management
Document property changes:
```bash
Create change log
echo "$(date): Set compression=lz4 on mypool/data - Performance optimization" >> /var/log/zfs-changes.log
Before making changes, document current state
zfs get all mypool/data > /tmp/zfs-properties-before.txt
```
Automation Best Practices
Use configuration management:
```bash
Example Ansible task
- name: Configure ZFS properties
zfs:
name: "{{ item.name }}"
state: present
compression: "{{ item.compression | default('lz4') }}"
quota: "{{ item.quota | default('none') }}"
loop: "{{ zfs_datasets }}"
```
Implement monitoring:
```bash
Monitor property changes
#!/bin/bash
LOGFILE="/var/log/zfs-property-monitor.log"
BASELINE="/etc/zfs/property-baseline.txt"
zfs get -r all mypool > /tmp/current-properties.txt
if ! diff -q $BASELINE /tmp/current-properties.txt >/dev/null; then
echo "$(date): ZFS properties changed" >> $LOGFILE
diff $BASELINE /tmp/current-properties.txt >> $LOGFILE
cp /tmp/current-properties.txt $BASELINE
fi
```
Conclusion
Mastering ZFS property management through the `zfs get` and `zfs set` commands is crucial for effective ZFS administration. These tools provide powerful capabilities for optimizing performance, managing space, and maintaining data integrity across your storage infrastructure.
Key takeaways from this guide:
1. Property Viewing: Use `zfs get` with various options to efficiently query and monitor ZFS properties across your datasets
2. Property Setting: Leverage `zfs set` to configure compression, quotas, performance settings, and custom properties
3. Inheritance: Understand how property inheritance works to efficiently manage large dataset hierarchies
4. Performance: Choose appropriate property values based on your workload characteristics and requirements
5. Troubleshooting: Apply systematic approaches to diagnose and resolve property-related issues
6. Best Practices: Implement monitoring, documentation, and change management processes for production environments
Next Steps
To further enhance your ZFS expertise:
- Explore advanced features like encryption properties and special device classes
- Implement automated monitoring and alerting for property changes
- Study ZFS performance tuning for specific applications
- Practice disaster recovery scenarios involving property restoration
- Consider ZFS delegation for multi-tenant environments
Regular practice with these commands in test environments will build the confidence needed to effectively manage ZFS properties in production systems. Remember that property changes can significantly impact performance and behavior, so always test thoroughly before applying changes to critical datasets.
The flexibility and power of ZFS properties make them an essential tool for storage administrators seeking to optimize their infrastructure for reliability, performance, and efficiency. By following the guidance in this comprehensive guide, you'll be well-equipped to leverage these capabilities effectively in your own ZFS deployments.