ZFS

๐Ÿ“š ZFS Installation and RAID Z2 Setup Guide

๐Ÿ”„ Update system packages

sudo apt update

๐Ÿ› ๏ธ Install ZFS

sudo apt install zfsutils-linux

๐Ÿ“Š Check available disks

lsblk

๐Ÿ—๏ธ Create a ZFS pool with RAID Z2

sudo zpool create EVA01 raidz2 /dev/sdX /dev/sdY /dev/sdZ

๐Ÿ“ Check the pool status

sudo zpool status EVA01

โš™๏ธ Set the record size to 1M.

sudo zfs set recordsize=1M EVA01

๐Ÿ—œ๏ธ Enable compression LZ4

sudo zfs set compression=lz4 EVA01

๐Ÿงฝ Schedule regular maintenance

# Launch a scrub to check and repair errors.
sudo zpool scrub EVA01
# Add a monthly scrub to the crontab.
echo "0 0 1 * * /usr/sbin/zpool scrub EVA01" | sudo tee -a /etc/crontab

๐Ÿ“‚ Create a dataset for Series

sudo zfs create EVA01/Series

๐Ÿ–‡๏ธ Set a custom mount point

sudo zfs set mountpoint=/Series EVA01/Series

๐Ÿ” Enable deduplication

sudo zfs set dedup=on EVA01

๐Ÿ“ธ Set snapshot limits to 10

sudo zfs set snapshot_limit=10 EVA01

๐Ÿ—ƒ๏ธ Optimize cache

#Configure the primary cache to only store metadata.
sudo zfs set primarycache=metadata EVA01

๐Ÿ”„ Actualizar los paquetes del sistema

sudo apt update
sudo apt install zfsutils-linux

Delete RAID

๐Ÿšซ Export the ZFS pool

#Prepare the ZFS pool for removal by exporting it.
sudo zpool export nombre_del_pool

๐Ÿงจ Destroy the ZFS pool

sudo zpool destroy nombre_del_pool

๐Ÿ“ List current ZFS pools

#Verify that the pool has been destroyed.
sudo zpool list

๐Ÿ”ง Wipe filesystem signatures from the first disk

sudo wipefs -a /dev/sda
sudo wipefs -a /dev/sdb
sudo wipefs -a /dev/sdc
sudo wipefs -a /dev/sdd

Snapshot

sudo zfs snapshot EVA01@snapshot
sudo zfs list -t snapshot
NAME                USED  AVAIL     REFER  MOUNTPOINT
EVA01@snapshot     0B      -     1023M  -
#!/bin/bash
# Create a new snapshot with the current date and time
zfs snapshot EVA01@$(date +"%Y-%m-%d_%H-%M-%S")

# Check if the number of snapshots exceeds the limit and delete the oldest one if necessary
snapshots=$(zfs list -H -o name -t snapshot | grep 'EVA01' | wc -l)
if [ "$snapshots" -gt 10 ]; then
    oldest_snapshot=$(zfs list -H -o name -t snapshot | grep 'EVA01' | head -n 1)
    zfs destroy "$oldest_snapshot"
fi
# Crontab
0 0 1 * * /snapshot.sh

๐Ÿ”„ Safe Reboot Procedure and Start for ZFS System

๐Ÿ”ฝ Unmount all ZFS filesystems

sudo zfs unmount -a

๐Ÿ“ฆ Export the ZFS pool

sudo zpool export EVA01

๐Ÿ“ List all ZFS pools

sudo zpool list

๐Ÿ”ƒ After reboot - Import the ZFS pool

sudo zpool import EVA01
zfs list
df -kh

zectl Usage Guide ๐Ÿš€

zectl is a tool for managing boot environments on operating systems that use ZFS.

๐Ÿ“ฆ Installation

sudo pacman -S zectl

๐ŸŒŸ Creating a Boot Environment

sudo zectl create my-new-be

๐Ÿ“ƒ Listing Boot Environments

sudo zectl list

๐Ÿ”„ Activating a Boot Environment

sudo zectl activate my-new-be
sudo reboot

๐Ÿ—‘๏ธ Deleting a Boot Environment

sudo zectl destroy my-old-be

Automating Boot Environments with zectl ๐Ÿš€

Creation of Boot Environments

#!/bin/bash
# This script creates a new boot environment every week. These boot environments act as restore points that you can use to revert your system to a previous state.
# Create a new boot environment weekly with zectl
# Name of the BE, including the date for easy identification
be_name="be_$(date +%Y-%m-%d)"
# Create the boot environment
sudo zectl create $be_name
echo "New boot environment created: $be_name"

Schedule with Cron

# To run this script every Sunday at 3:00 AM
0 3 * * 0 /path/to/create_be.sh

Deletion of Old Boot Environments

#!/bin/bash
# This script deletes boot environments that are more than 30 days old. It's good practice to free up space and keep the system tidy.
# Delete old boot environments that are more than 30 days old
# List and filter old BEs
old_bes=$(sudo zectl list --columns=name,creation | awk -v date="$(date --date='-30 days' +%s)" '$2 < date {print $1}')
for be in $old_bes; do
    sudo zectl destroy $be
    echo "Boot environment deleted: $be"
done

Schedule with Cron

# To run this script on the first day of each month at 4:00 AM
0 4 1 * * /path/to/delete_old_bes.sh

Useful

๐Ÿง View all ZFS configurations

zfs get all