How to Create ZFS Filesystems and Enable Compression on Linux
This guide walks through creating a ZFS filesystem from a pool, setting quotas and reservations, configuring an alternate mount point, enabling compression, and verifying compression effectiveness, helping Linux users save disk space with ZFS.
Abstract: ZFS file system is gaining recognition on Linux. In ZFS you can enable compression at the filesystem level, saving disk space. This article explains how to create a ZFS filesystem from a pool and enable compression.
Creating a ZFS Filesystem
First, list existing ZFS filesystems with zfs list. Example output shows a pool named mypool and an existing filesystem mypool/fs1.
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
mypool 170K 5.84G 30K /mypool
mypool/fs1 30K 5.84G 30K /mypool/fs1Then create a new filesystem and set a quota of 1 GB:
# zfs set quota=1G mypool/fs1The new filesystem appears in the list:
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
mypool 170K 5.84G 30K /mypool
mypool/fs1 30K 5.84G 30K /mypool/fs1Setting ZFS Quota and Reservation
By default a ZFS filesystem can consume all space in the pool, so you must set a quota and a reservation. The quota is set with zfs set quota=1G mypool/fs1. The reservation reserves 256 M so that space cannot be used by others, while still allowing growth up to the quota.
# zfs set reservation=256M mypool/fs1
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
mypool 256M 5.59G 32.5K /mypool
mypool/fs1 30K 1024M 30K /mypool/fs1Creating an Alternate Mountpoint
You can assign any mountpoint name to the filesystem. For example, set the mountpoint to /testmnt instead of the default mypool/fs1:
# zfs set mountpoint=/testmnt mypool/fs1The zfs list output shows the new mountpoint, and the df -h command confirms it:
# df -h
Filesystem Size Used Avail Use% Mounted on
...
mypool 5.6G 128K 5.6G 1% /mypool
mypool/fs1 1.0G 128K 1.0G 1% /testmntEnabling Compression on a ZFS Dataset
Enable compression by setting the compression property, e.g., lzjb. Valid values are on, off, lzjb, gzip, gzip[1-9], and zle.
# zfs set compression=lzjb mypool/fs1Compression applies to new and modified data; existing data remains uncompressed.
Verifying ZFS Compression
Copy a 61 M tar file to the mounted dataset and check space usage. The zfs list shows only 20.9 M used, confirming compression.
# ls -lh /testmnt/test.tar
-rw-r--r-- 1 root root 61M Nov 11 09:44 /testmnt/test.tar
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
mypool 256M 5.59G 32.5K /mypool
mypool/fs1 20.9M 1003M 20.9M /testmntRetrieve the compression ratio:
# zfs get compressratio mypool/fs1
NAME PROPERTY VALUE SOURCE
mypool/fs1 compressratio 2.90x -The article notes that ZFS also offers advanced features such as clones and snapshots, which will be covered in the next installment.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
