Add new disk in FreeBSD and enable compression zfs.

 

 

In this article I will describe how to mount an extra disk for storing files in a FreeBSD operating system with the ZFS file system with data compression enabled. So, after physically mounting the disk, we will first need to create a ZFS partition. To do this we will use gpart.

 

We will look at the existing partition:

 

gpart show ada1

 

If the partition exists you need to delete it:

 

gpart destroy -F ada1

 

and create a new partition table:

 

gpart create -s gpt /dev/ada1

 

If you need an extra swap partition, create one too:

 

gpart add -t freebsd-swap -s 2G /dev/ada1

 

Next we create the file partition itself:

 

gpart add -t freebsd-zfs /dev/ada1

 

Check what happened:

 

gpart show ada1

 

If everything is correct, create a new filesystem:

 

newfs -U /dev/ada1p1

 

To create a ZFS pool, do the following:

 

zpool create -f files /dev/ada1p1

 

zfs create files/files

 

 

 

You can either just enable the default compression=on, or use a compression level between 1 and 9 if you will be using gzip, or you can use lz4 or zstd compression=lz4 and so on.

 

zfs set compression=gzip-9 files/files

 

 

 

If you want to move the whole home directory:

 

cp -rp /home/* /storage/home

rm -rf /home /usr/home

ln -s /storage/home /home

ln -s /storage/home /usr/home

 

View information about the disk, whether compression is enabled, compression level and size:

 

zfs get used,compressratio,compression,logicalused files/files

du -sh files/files

zfs list files/files

Share This Article

Previous Article

May 11, 2022 • 11:30PM

Next Article

June 28, 2022 • 12:53AM

From Our Blog