Using zfs on a separate partition
I have a machine with root on an ext4 partition and I want to use ZFS on a second partition.
Install ZFS
Enable apt backports:
vi /etc/apt/sources.list.d/bookworm-backports.list
deb http://deb.debian.org/debian bookworm-backports main contrib
deb-src http://deb.debian.org/debian bookworm-backports main contrib
Set high priority for zfs packages:
vi /etc/apt/preferences.d/90_zfs
Package: src:zfs-linux
Pin: release n=bookworm-backports
Pin-Priority: 990
Install ZFS:
apt update
apt install dpkg-dev linux-headers-generic linux-image-generic
apt install zfs-dkms zfsutils-linux
Load the kernel module and test:
modprobe zfs
zfs version
Setup the partition
My partition is /dev/sda3 and I set the partition type with fdisk.
In fdisk, for gpt partition table, use partition type:
67 Solaris /usr & Apple ZFS 6A898CC3-1DD2-11B2-99A6-080020736631
For dos partition table, use partition type:
bf Solaris
Setup ZFS on the partition
The sda3 partition has id /dev/disk/by-id/wwn-0x50014ee258b39ae4-part3, I use this id to create the zfs pool:
# create pool mypool
zpool create -O atime=off mypool /dev/disk/by-id/wwn-0x50014ee258b39ae4-part3
# create `data` dataset
zfs create mypool/data
zfs set copies=3 snapdir=visible mypool/data
zfs mountpoint=/mnt/data mypool/data
Setup a systemd timer to scrub the pool regularly:
systemctl enable zfs-scrub-weekly@rpool.timer --now
systemctl list-timers
Send a mail when scrub finds an issue:
vi /etc/zfs/zed.d/zed.rc
ZED_EMAIL_ADDR="myemail@example.com"
ZED_EMAIL_PROG="mutt"
Alternatively, setup a cronjob:
crontab -e
0 1 * * 4 /root/bin/scrub.sh
scrub.sh is this command:
zpool scrub mypool
When scrub finds an error, use zpool to get more information:
zpool status mypool
# details with -v, it lists the files are errors
zpool status -v mypool
# clear the error with
zpool clear mypool