mirror of
https://github.com/openoms/bitcoin-tutorials.git
synced 2025-12-19 04:54:18 +01:00
extend zfs docs
This commit is contained in:
@@ -23,10 +23,13 @@ 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
|
||||||
apt install -y zfs-dkms zfsutils-linux
|
apt install -y zfs-dkms zfsutils-linux
|
||||||
|
# test
|
||||||
|
zpool status
|
||||||
```
|
```
|
||||||
|
|
||||||
## Create a pool
|
## Preparation
|
||||||
```
|
```
|
||||||
# create encryption key
|
# 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
|
||||||
@@ -50,8 +53,33 @@ sgdisk --zap-all $DISK2
|
|||||||
sgdisk --zap-all $DISK1
|
sgdisk --zap-all $DISK1
|
||||||
sgdisk --zap-all $DISK2
|
sgdisk --zap-all $DISK2
|
||||||
|
|
||||||
# create pool with two disk pair mirrored, see the last line and edit to your setup:
|
# Clean a disk which was previously used with zfs:
|
||||||
# mirror $DISK1 $DISK3 mirror $DISK2 $DISK4
|
wipefs -a $DISK
|
||||||
|
```
|
||||||
|
|
||||||
|
## Creata a pool
|
||||||
|
* see for the basic options
|
||||||
|
```
|
||||||
|
man zpoolconcepts
|
||||||
|
```
|
||||||
|
### Examples
|
||||||
|
* edit the last line of the `zpool create` command
|
||||||
|
* the pool is named `fourdiskpool` - can change this
|
||||||
|
* for 4 disks - 2 pairs mirrored:
|
||||||
|
```
|
||||||
|
mirror $DISK1 $DISK3 mirror $DISK2 $DISK4
|
||||||
|
```
|
||||||
|
* for 2 disks - 1 pair mirrored:
|
||||||
|
```
|
||||||
|
mirror $DISK1 $DISK2
|
||||||
|
```
|
||||||
|
* for single data disk (can be extended to be a mirror later with `zpool attach`)
|
||||||
|
```
|
||||||
|
$DISK1
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
zpool create \
|
zpool create \
|
||||||
-o cachefile=/etc/zfs/zpool.cache \
|
-o cachefile=/etc/zfs/zpool.cache \
|
||||||
-o ashift=12 -d \
|
-o ashift=12 -d \
|
||||||
@@ -72,44 +100,61 @@ zpool create \
|
|||||||
-o feature@zpool_checkpoint=enabled \
|
-o feature@zpool_checkpoint=enabled \
|
||||||
-O acltype=posixacl -O canmount=off -O compression=lz4 \
|
-O acltype=posixacl -O canmount=off -O compression=lz4 \
|
||||||
-O devices=off -O normalization=formD -O relatime=on -O xattr=sa \
|
-O devices=off -O normalization=formD -O relatime=on -O xattr=sa \
|
||||||
-O mountpoint=/mnt \
|
|
||||||
-O encryption=on \
|
-O encryption=on \
|
||||||
-O keyformat=raw -O keylocation=file:///root/.zpoolraw.key \
|
-O keyformat=raw -O keylocation=file:///root/.zpoolraw.key \
|
||||||
mirrorpool mirror $DISK1 $DISK3 # mirror $DISK2 $DISK4
|
fourdiskpool \
|
||||||
|
mirror $DISK1 $DISK3 mirror $DISK2 $DISK4
|
||||||
|
|
||||||
# check
|
# check
|
||||||
zpool status
|
zpool status
|
||||||
zpool list
|
zpool list
|
||||||
|
```
|
||||||
|
|
||||||
|
### Mount to /mnt/hdd
|
||||||
|
```
|
||||||
|
# create a dataset named hdd (so it can be mounted as /mnt/hdd)
|
||||||
|
zfs create fourdiskpool/hdd
|
||||||
|
|
||||||
|
# mount a ZFS dataset to /mnt/hdd
|
||||||
|
zfs set mountpoint=/mnt fourdiskpool
|
||||||
|
zfs load-key -a
|
||||||
|
zfs mount -la
|
||||||
|
|
||||||
# create a dataset name hdd (so it can be mounted as /mnt/hdd)
|
|
||||||
zfs create zpool/hdd
|
|
||||||
# check
|
# check
|
||||||
zfs list
|
zfs list
|
||||||
df -h
|
df -h
|
||||||
|
|
||||||
# Mount a ZFS dataset to `/mnt/hdd`:
|
# automount with cron
|
||||||
zfs create zpool/hdd
|
|
||||||
zfs mount zpool/hdd /mnt
|
|
||||||
|
|
||||||
#or change an existing mountpoint for a whole pool:
|
|
||||||
sudo zfs set mountpoint=/mnt/hdd POOL1
|
|
||||||
|
|
||||||
# to automount:
|
|
||||||
echo "\
|
|
||||||
[Service]
|
|
||||||
ExecStartPre=/sbin/zfs load-key -a
|
|
||||||
ExecStartPre=/sbin/zfs mount -la
|
|
||||||
" | sudo tee /etc/systemd/system/bootstrap.service.d/zfsautomount.conf
|
|
||||||
|
|
||||||
# or in 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
|
||||||
|
crontab -u admin -l
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## 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
|
||||||
|
```
|
||||||
|
# choose the existing disk from:
|
||||||
|
zpool status
|
||||||
|
EXISTING_DISK=<existing-disk-id>
|
||||||
|
|
||||||
|
# choose the new disk id from:
|
||||||
|
lsblk --scsi
|
||||||
|
ls -la /dev/disk/by-id
|
||||||
|
NEW_DISK=/dev/disk/by-id/ata-<new-disk-id>
|
||||||
|
|
||||||
|
# attach the new disk
|
||||||
|
zpool attach $EXISTING_DISK $NEW_DISK
|
||||||
|
|
||||||
|
# check - shoudl start to resilver as the new disk is added
|
||||||
|
zpool status
|
||||||
|
```
|
||||||
|
|
||||||
## ZFS encryption key operations
|
## ZFS encryption key operations
|
||||||
```
|
```
|
||||||
# backup the key
|
# backup the key
|
||||||
@@ -150,9 +195,12 @@ 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
|
||||||
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
|
||||||
|
crontab -u admin -l
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user