1 # ZFS
   2 
   3 DRIVES=$(echo /dev/sd{a..j})
   4 
   5 for i in $DRIVES; do
   6     # Clear any existing partition table
   7     echo sudo sgdisk --zap-all $i
   8     echo sudo sgdisk --largest-new=1 $i
   9 done
  10 
  11 # TODO: should give whole disks to ZFS
  12 
  13 DRIVE_PARTITIONS=$(echo /dev/sd{e,d,c,f,h,g,i,j}1)
  14 
  15 NAME=archive
  16 
  17 CACHE_DISKS="nvme-SAMSUNG_MZQL2960HCJR-00A07*-part3"
  18 DATA_DISKS="ata-TOSHIBA_MG08ACA16TEY_*"
  19 
  20 ## create main array
  21 # use ashift=12 for 4K sector disks
  22 sudo zpool create -o ashift=12 -f $NAME raidz /dev/disk/by-id/${DATA_DISKS}
  23 
  24 ## add cache
  25 sudo zpool add -f $NAME cache /dev/disk/by-id/${CACHE_DISKS}
  26 
  27 ## list devices
  28 zpool status -v
  29 
  30 sudo zfs set xattr=sa ${NAME}
  31 sudo zfs set compression=lz4 ${NAME}
  32 sudo zfs set atime=off ${NAME}
  33 sudo zfs set relatime=off ${NAME}
  34 # See https://blog.programster.org/zfs-record-size about setting recordsize
  35 #sudo zfs set recordsize=16K ${NAME}  # For BitTorrent
  36 #sudo zfs set recordsize=1M ${NAME}   # For long-term storage
  37 
  38 
  39 ROOT=/mnt
  40 
  41 mount /dev/md1 /mnt
  42 mount /dev/md0 /mnt/boot
  43 mount -o bind /proc /mnt/proc
  44 mount -o bind /sys /mnt/sys
  45 mount -o bind /run /mnt/run
  46 mount -o bind /dev /mnt/dev
  47 
  48 installimage -n geta -r yes -l 1 -p /boot:ext3:1G,/:xfs:128G -f yes -t yes -d nvme0n1,nvme1n1 -i /root/images/Debian-1101-bullseye-amd64-base.tar.gz

References

https://pthree.org/2012/04/17/install-zfs-on-debian-gnulinux/

https://openzfs.github.io/openzfs-docs/Performance%20and%20Tuning/Workload%20Tuning.html#bit-torrent

ZFS RAIDZ stripe width, or: How I Learned to Stop Worrying and Love RAIDZ: Use RAID-Z. Not too wide. Enable compression.

dRAID, Finally!: Intro to dRAID, ZFS RAID w/ fixed record size to enable faster resilvers.