Improved ZFS-related knowledge base and scripts

This commit is contained in:
Michele Cereda
2022-06-06 22:39:08 +02:00
parent 6f9e2c3073
commit 95c50af0d6
4 changed files with 68 additions and 7 deletions

View File

@@ -5,9 +5,12 @@
: "${MOUNT_OPTIONS:=compress-force=zstd}"
: "${MOUNT_POINT:=/mnt/$LABEL}"
: "${USERNAME:=root}"
: "${GROUPNAME:=root}"
: "${CLOSE_WHEN_DONE:=true}"
[[ $EUID -eq 0 ]] || (echo "Please rerun this script with root privileges" && exit 1)
[[ -f "$DEVICE" ]] || echo "${DEVICE} not found"
[[ $EUID -eq 0 ]] || (echo "Re-run this script with root privileges" >&2 && exit 1)
[[ -b "$DEVICE" ]] || (echo "${DEVICE} not found" >&2 && exit 1)
cryptsetup luksFormat "$DEVICE"
cryptsetup open "$DEVICE" "$LABEL"
@@ -21,5 +24,8 @@ btrfs subvolume create "$MOUNT_POINT/data"
chown "$USER":"$USER" "$MOUNT_POINT/data"
umount "/mnt/${LABEL}"
cryptsetup close "$DEVICE"
if [[ "$CLOSE_WHEN_DONE" ]]
then
umount "/mnt/${LABEL}"
cryptsetup close "$DEVICE"
fi

View File

@@ -0,0 +1,26 @@
#!/usr/bin/env sh
: ${DEVICE:?not set}
: ${POOL_NAME:?not set}
: "${DATASET:=data}"
: "${MOUNT_POINT:=/mnt/${POOL_NAME}}"
: "${USERNAME:=root}"
: "${GROUPNAME:=root}"
: "${UNMOUNT_WHEN_DONE:=true}"
[[ $EUID -eq 0 ]] || (echo "Re-run this script with root privileges" >&2 && exit 1)
[[ -b "$DEVICE" ]] || (echo "${DEVICE} not found" >&2 && exit 1)
zpool create \
-o feature@encryption=enabled \
-O mountpoint="$MOUNT_POINT" \
-O encryption=on -O keyformat=passphrase \
-O compression=zstd \
"$POOL_NAME" \
"$DEVICE"
zfs create "${POOL_NAME}/${DATASET_NAME}"
chown "$USERNAME":"$GROUPNAME" "${MOUNT_POINT}/${DATASET_NAME}"
[[ "$UNMOUNT_WHEN_DONE" ]] && zfs unmount "${POOL_NAME}/${DATASET_NAME}"

View File

@@ -0,0 +1,15 @@
#!/usr/bin/env sh
# sources:
# - https://openzfs.github.io/openzfs-docs/Getting%20Started/Fedora/index.html
# needs to be installed before zsf
sudo dnf install -y kernel-devel
# the repo's package is not maintained
sudo rpm -e --nodeps zfs-fuse
sudo dnf install -y https://zfsonlinux.org/fedora/zfs-release$(rpm -E %dist).noarch.rpm
sudo dnf install -y zfs
echo zfs | sudo tee /etc/modules-load.d/zfs.conf
sudo modprobe zfs