add links and formatting

This commit is contained in:
openoms
2023-04-01 09:18:24 +02:00
parent 39f8ed6dc6
commit 2b2852c69c

View File

@@ -1,67 +1,52 @@
# Create a ZFS pool to be used as a Raspiblitz disk <!-- omit from toc -->
# Create a ZFS pool to be used as a Raspiblitz data disk
## Documentation - [Install ZFS](#install-zfs)
``` - [Create the encryption key](#create-the-encryption-key)
man zpool create - [Create a pool](#create-a-pool)
man zpool-features - [Examples](#examples)
man zfsprops - [A four disk setup](#a-four-disk-setup)
man zfs-load-key - [Mount to /mnt/hdd](#mount-to-mnthdd)
``` - [Attach a new disk to an existing pool](#attach-a-new-disk-to-an-existing-pool)
- [ZFS encryption key operations](#zfs-encryption-key-operations)
- [Temperature monitoring](#temperature-monitoring)
- [Import an existing ZFS pool](#import-an-existing-zfs-pool)
- [Documentation](#documentation)
## Install ZFS ## Install ZFS
* https://openzfs.github.io/openzfs-docs/Getting%20Started/Debian/index.html#installation * https://openzfs.github.io/openzfs-docs/Getting%20Started/Debian/index.html#installation
``` ```
# work as root # work as root
sudo su - sudo su -
echo "deb http://deb.debian.org/debian bullseye-backports main contrib" | sudo tee -a /etc/apt/sources.list.d/bullseye-backports.list echo "deb http://deb.debian.org/debian bullseye-backports main contrib" | sudo tee -a /etc/apt/sources.list.d/bullseye-backports.list
echo "deb-src http://deb.debian.org/debian bullseye-backports main contrib" | sudo tee -a /etc/apt/sources.list.d/bullseye-backports.list echo "deb-src http://deb.debian.org/debian bullseye-backports main contrib" | sudo tee -a /etc/apt/sources.list.d/bullseye-backports.list
echo "Package: src:zfs-linux" | sudo tee -a /etc/apt/preferences.d/90_zfs echo "Package: src:zfs-linux" | sudo tee -a /etc/apt/preferences.d/90_zfs
echo "Pin: release n=bullseye-backports" | sudo tee -a /etc/apt/preferences.d/90_zfs echo "Pin: release n=bullseye-backports" | sudo tee -a /etc/apt/preferences.d/90_zfs
echo "Pin-Priority: 990" | sudo tee -a /etc/apt/preferences.d/90_zfs echo "Pin-Priority: 990" | sudo tee -a /etc/apt/preferences.d/90_zfs
apt update apt update
apt install -y dpkg-dev linux-headers-generic linux-image-generic apt install -y dpkg-dev linux-headers-generic linux-image-generic
# might need to reboot here if the headers are updated # might need to reboot here if the headers are updated
apt install -y zfs-dkms zfsutils-linux apt install -y zfs-dkms zfsutils-linux
# test # test
zpool status zpool status
``` ```
## Preparation ## Create the encryption key
``` * could use a CLN hsm_secret, see https://twitter.com/openoms/status/1480881081851207683
# create encryption key ```
dd if=/dev/urandom of=/root/.zpoolraw.key bs=32 count=1 dd if=/dev/urandom of=/root/.zpoolraw.key bs=32 count=1
chmod 400 /root/.zpoolraw.key chmod 400 /root/.zpoolraw.key
```
# list physical disks ## Create a pool
lsblk --scsi
# get the IDS
ls -la /dev/disk/by-id
# Working with a four disk setup - need identical sizes in the mirrrors
DISK1="/dev/disk/by-id/ata-name-and-id-of-disk1"
DISK2="/dev/disk/by-id/ata-name-and-id-of-disk2"
DISK3="/dev/disk/by-id/ata-name-and-id-of-disk3"
DISK4="/dev/disk/by-id/ata-name-and-id-of-disk4"
# Clear the partition table:
sgdisk --zap-all $DISK1
sgdisk --zap-all $DISK2
sgdisk --zap-all $DISK1
sgdisk --zap-all $DISK2
# Clean a disk which was previously used with zfs:
wipefs -a $DISK
```
## Creata a pool
* see for the basic options * see for the basic options
``` ```
man zpoolconcepts man zpoolconcepts
``` ```
* [Why you should use mirror vdevs not raidz](https://jrs-s.net/2015/02/06/zfs-you-should-use-mirror-vdevs-not-raid)
### Examples ### Examples
* edit the last line of the `zpool create` command * edit the last line of the `zpool create` command
* the pool is named `fourdiskpool` - can change this * the pool is named `fourdiskpool` - can change this
@@ -78,9 +63,31 @@ man zpoolconcepts
$DISK1 $DISK1
``` ```
### A four disk setup
* needs identical sizes in the mirrors
```
# list physical disks
lsblk --scsi
# get the IDS
ls -la /dev/disk/by-id
``` DISK1="/dev/disk/by-id/ata-name-and-id-of-disk1"
zpool create \ DISK2="/dev/disk/by-id/ata-name-and-id-of-disk2"
DISK3="/dev/disk/by-id/ata-name-and-id-of-disk3"
DISK4="/dev/disk/by-id/ata-name-and-id-of-disk4"
# Clear the partition table:
sgdisk --zap-all $DISK1
sgdisk --zap-all $DISK2
sgdisk --zap-all $DISK1
sgdisk --zap-all $DISK2
# Clean a disk which was previously used with zfs:
wipefs -a $DISK1
```
```
zpool create \
-o cachefile=/etc/zfs/zpool.cache \ -o cachefile=/etc/zfs/zpool.cache \
-o ashift=12 -d \ -o ashift=12 -d \
-o feature@async_destroy=enabled \ -o feature@async_destroy=enabled \
@@ -105,102 +112,115 @@ zpool create \
fourdiskpool \ fourdiskpool \
mirror $DISK1 $DISK3 mirror $DISK2 $DISK4 mirror $DISK1 $DISK3 mirror $DISK2 $DISK4
# check # check
zpool status zpool status
zpool list zpool list
``` ```
### Mount to /mnt/hdd ### Mount to /mnt/hdd
``` * ```
# create a dataset named hdd (so it can be mounted as /mnt/hdd) # create a dataset named hdd (so it can be mounted as /mnt/hdd)
zfs create fourdiskpool/hdd zfs create fourdiskpool/hdd
# mount a ZFS dataset to /mnt/hdd # mount a ZFS dataset to /mnt/hdd
zfs set mountpoint=/mnt fourdiskpool zfs set mountpoint=/mnt fourdiskpool
zfs load-key -a zfs load-key -a
zfs mount -la zfs mount -la
# check # check
zfs list zfs list
df -h df -h
# automount with cron # automount with cron
cronjob="@reboot sudo /sbin/zfs load-key -a; sudo /sbin/zfs mount -la" cronjob="@reboot sudo /sbin/zfs load-key -a; sudo /sbin/zfs mount -la"
( (
crontab -u admin -l crontab -u admin -l
echo "$cronjob" echo "$cronjob"
) | crontab -u admin - ) | crontab -u admin -
# list the active crontab for admin # list the active crontab for admin
crontab -u admin -l crontab -u admin -l
``` ```
## Attach a new disk to an existing pool ## Attach a new disk to an existing pool
* can create a single zfs disk to mirror or a two-way mirror to a three-way mirror * can create a single zfs disk to mirror or a two-way mirror to a three-way mirror
``` ```
# choose the existing disk from: # choose the existing disk from:
zpool status zpool status
EXISTING_DISK=<existing-disk-id> EXISTING_DISK=<existing-disk-id>
# choose the new disk id from: # choose the new disk id from:
lsblk --scsi lsblk --scsi
ls -la /dev/disk/by-id ls -la /dev/disk/by-id
NEW_DISK=/dev/disk/by-id/ata-<new-disk-id> NEW_DISK=/dev/disk/by-id/ata-<new-disk-id>
# attach the new disk # attach the new disk
zpool attach $EXISTING_DISK $NEW_DISK zpool attach $EXISTING_DISK $NEW_DISK
# check - shoudl start to resilver as the new disk is added # check - shoudl start to resilver as the new disk is added
zpool status zpool status
``` ```
## ZFS encryption key operations ## ZFS encryption key operations
``` * ```
# backup the key # backup the key
xxd /root/.zpoolraw.key xxd /root/.zpoolraw.key
00000000: 30cc f221 94e1 7f01 cd54 d68c a1ba f124 0..!.....T.....$ 00000000: 30cc f221 94e1 7f01 cd54 d68c a1ba f124 0..!.....T.....$
00000010: e1f3 1d45 d904 823c 77b7 1e18 fd93 1676 ...E... <w......v 00000010: e1f3 1d45 d904 823c 77b7 1e18 fd93 1676 ...E... <w......v
# recover the key from text # recover the key from text
# https://lightning.readthedocs.io/BACKUP.html#hsm-secret # https://lightning.readthedocs.io/BACKUP.html#hsm-secret
cat >.zpoolraw_hex.txt <<HEX cat >.zpoolraw_hex.txt <<HEX
00: 30cc f221 94e1 7f01 cd54 d68c a1ba f124 00: 30cc f221 94e1 7f01 cd54 d68c a1ba f124
10: e1f3 1d45 d904 823c 77b7 1e18 fd93 1676 10: e1f3 1d45 d904 823c 77b7 1e18 fd93 1676
HEX HEX
xxd -r .zpoolraw_hex.txt >/root/.zpoolraw.key xxd -r .zpoolraw_hex.txt >/root/.zpoolraw.key
chmod 0400 .zpoolraw.key chmod 0400 .zpoolraw.key
srm .zpoolraw_hex.txt srm .zpoolraw_hex.txt
``` ```
## temperature monitoring ## Temperature monitoring
``` * ```
sudo sudo apt install hddtemp nvme-cli sudo sudo apt install hddtemp nvme-cli
sudo hddtemp /dev/sd? sudo hddtemp /dev/sd?
sudo nvme smart-log /dev/nvme0 | grep "^temperature" sudo nvme smart-log /dev/nvme0 | grep "^temperature"
sudo nvme smart-log /dev/nvme1 | grep "^temperature" sudo nvme smart-log /dev/nvme1 | grep "^temperature"
sudo smartctl -d auto -H /dev/nvme0 sudo smartctl -d auto -H /dev/nvme0
sudo smartctl -d auto -H /dev/nvme1 sudo smartctl -d auto -H /dev/nvme1
sudo smartctl -d auto -a /dev/nvme1 sudo smartctl -d auto -a /dev/nvme1
sudo smartctl -d auto -a /dev/nvme1 sudo smartctl -d auto -a /dev/nvme1
``` ```
## import an existing ZFS pool ## Import an existing ZFS pool
* https://openzfs.github.io/openzfs-docs/Getting%20Started/Debian/index.html * https://openzfs.github.io/openzfs-docs/Getting%20Started/Debian/index.html
``` ```
zpool import zpool import
zpool import -a zpool import -a
sudo /sbin/zfs load-key -a sudo /sbin/zfs load-key -a
sudo /sbin/zfs mount -la sudo /sbin/zfs mount -la
# automount with cron # automount with cron
cronjob="@reboot sudo /sbin/zfs load-key -a; sudo /sbin/zfs mount -la" cronjob="@reboot sudo /sbin/zfs load-key -a; sudo /sbin/zfs mount -la"
( (
crontab -u admin -l crontab -u admin -l
echo "$cronjob" echo "$cronjob"
) | crontab -u admin - ) | crontab -u admin -
# list the active crontab for admin # list the active crontab for admin
crontab -u admin -l crontab -u admin -l
``` ```
## Documentation
- [OpenZFS on Debian](https://openzfs.github.io/openzfs-docs/Getting%20Started/Debian/index.html)
- [Capacity calculator](https://wintelguy.com/zfs-calc.pl)
- [Why you should use mirror vdevs not raidz](https://jrs-s.net/2015/02/06/zfs-you-should-use-mirror-vdevs-not-raid)
- [ZFS manager plugin for Cockpit](https://github.com/45Drives/cockpit-zfs-manager)
```
man zpoolconcepts
man zpool create
man zpool-features
man zfsprops
man zfs-load-key
```