Abstract: The ZFS file system has gained wider recognition on Linux. In ZFS, you can enable compression at the file system level. This will store data in a compressed format, saving a significant amount of disk space. In this article, we will explain how to create a file system from a ZFS storage pool and enable compression on ZFS.
The ZFS file system has gained wider recognition on Linux.
In ZFS, you can enable compression at the file system level. This will store data in a compressed format, saving a significant amount of disk space.
In this article, we will explain how to create a file system from a ZFS storage pool and enable compression on ZFS.
In the first part of this series, we explained the basics of ZFS and how to install ZFS on Linux. We also created a ZFS pool.
Creating a ZFS File System
First, use the zfs list
command to view all current ZFS file systems, as shown below. In this example, we currently have one ZFS file system.
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
mypool 170K 5.84G 30K /mypool
mypool/fs1 30K 5.84G 30K /mypool/fs1
Now, use the zfs create
command to create a new ZFS file system.
# zfs set quota=1G mypool/fs1
As shown below, the new ZFS file system has been successfully created.
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
mypool 170K 5.84G 30K /mypool
mypool/fs1 30K 5.84G 30K /mypool/fs1
Setting ZFS Quota and Reservation
When creating a ZFS file system, it will, by default, consume all space in the pool. Therefore, you must specify a quota and reservation for the file system.
To set the quota, use the zfs set
command as shown below. Here, we specify the quota for this file system as 1GB.
# zfs set quota=1G mypool/fs1
Next, set the reservation for the file system. In this example, fs1
has reserved 256M out of 5.59G, so no one can use this space, and it can expand to 1G based on the quota we set if there is available space.
# 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/fs1
Creating an Alternative Mount Point for ZFS
In addition to using the name mypool/fs1
to mount it, you can set an alternative mount point with any name you wish for the file system.
For example, the following command sets the mount point to /testmnt
instead of mypool/fs1
.
# zfs set mountpoint=/testmnt mypool/fs1
As we can see from the output below, the first column NAME
indicates the real name of the ZFS file system. The last column MOUNTPOINT
indicates the alternative mount point we created above.
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
mypool 256M 5.59G 32.5K /mypool
mypool/fs1 30K 1024M 30K /testmnt
When you execute the df
command, you will see the alternative mount point as shown below.
# 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% /testmnt
Enabling Compression on the ZFS File System
To set compression on a ZFS dataset, you can set the compression property as shown below. Once this property is set, all large files stored on this ZFS file system will be compressed.
# zfs set compression=lzjb mypool/fs1
The following are valid compression properties:
-
on
-
off
-
lzjb
-
gzip
-
gzip[1-9]
-
zle
You can also enable compression on an existing file system. In this case, compression will only apply to new and modified data; any existing data will remain uncompressed.
Verifying ZFS Compression
In the following example, we have copied a 61M tar file to the ZFS file system mypool/fs1
mounted at /testmnt
.
# ls -lh /testmnt/test.tar
-rw-r--r--. 1 root root 61M Nov 11 09:44 /testmnt/test.tar
If you check the total size of the USED space from the zfs list
command, you will see that only 20.9M of space is consumed, indicating that compression is enabled and working.
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
mypool 256M 5.59G 32.5K /mypool
mypool/fs1 20.9M 1003M 20.9M /testmnt
You can also use the following command to get the compression ratio.
# zfs get compressratio mypool/fs1
NAME PROPERTY VALUE SOURCE
mypool/fs1 compressratio 2.90x -
In addition to compression, the ZFS file system has several advanced features. In the next article of the ZFS series, we will discuss how to obtain ZFS clones and snapshots.
Link: https://bbs.huaweicloud.com/blogs/379559
(Copyright belongs to Huawei Cloud Community All rights reserved, infringement will be deleted)
WeChat Group
WeChat group
To facilitate better communication on operation and maintenance and related technical issues, a WeChat group has been created. Friends who need to join the group can scan the QR code below to add me as a friend (note: join the group).
Blog
Guest
Blog
CSDN Blog: https://blog.csdn.net/qq_25599925
Juejin Blog: https://juejin.cn/user/4262187909781751
Long press to recognize the QR code to visit the blog website for more quality original content.