Practical ZFS On FreeBSD

freebsd zfs storage

FreeBSD supports ZFS natively and all you have do is to add this line to “/etc/rc.conf” manually:

zfs_enable="YES"  

Or with:
# echo ‘zfs_enable=“YES”’ » /etc/rc.conf

Then start the service:
# service zfs start
A minimum of 4GB of RAM is required for comfortable usage, but individual workloads can vary widely.

Create First ZFS Pool

ZFS can work directly with device node but you can also create your own disk with truncate:

# truncate -s 2G disk_1
# truncate -s 2G disk_2
# truncate -s 2G disk_3
# truncate -s 2G disk_4
Then create your own pool and name it storage:
# zpool create storage /root/disk_1 /root/disk_2 /root/disk_3 /root/disk_4
# zpool list
As you can see we have 7.94G storage. this pool is not taking advantage of any ZFS features. To create a dataset on this pool with compression enabled:

Compression Property

# zfs create storage/myfolder
# zfs set compression=gzip storage/myfolder
It is now possible to see the data and space utilization by issuing:

# df -h

storage 7.7G 23K 7.7G 0% /storage  
storage/myfolder 7.7G 23K 7.7G 0% /storage/myfolder  

you can disable compression by:
# zfs set compression=off storage/myfolder

Copies Property

If you something important you can keep more copies of it:

# zfs create storage/archive
# zfs set copies=2 storage/archive

To destroy the file systems and then destroy the pool as it is no longer needed:
# zfs destroy storage/myfolder
# zfs destroy storage/archive
# zpool destroy storage
# zpool set autoexpand=on mypool

RaidZ, Snapshot, and Rollback

A variation on RAID-5 that allows for better distribution of parity and eliminates the “RAID-5” write hole (in which data and parity become inconsistent after a power loss). Data and parity are striped across all disks within a raidz group.

Try creating a file system snapshot which can be rolled back later:
# zfs snapshot storage/myfolder@now
You can restore to the created snapshot with:

# zfs rollback storage/myfolder@now
Also, you can list all ZFS datasets and snapshots:
# zfs list -t all

You can get full edition at:
https://contents.meetbsd.ir/ebook/zfs_bsdmag.pdf
Or:
https://bsdmag.org/download/debugging-applications/


enter image description here