The following is the GNU All-permissive License as recommended in https://www.gnu.org/licenses/license-recommendations.en.html

Copyright (C) 2024 Free Software Foundation sysadmin@fsf.org

Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty.

Contributions are welcome. See https://savannah.gnu.org/maintenance/fsf/.

Set up a self-mounting, encrypted partition

KEYFILE=/boot/key-$1
pwgen 128 -s -1 | xargs echo -n > $KEYFILE
echo YES | cryptsetup luksFormat -y --cipher aes-xts-plain64 --hash sha256 --use-urandom --key-size 256  /dev/$1 --key-file=$KEYFILE
echo "$HOSTNAME-crypt-$1 /dev/$1 /boot/key-$1 luks,discard,nofail" >> /etc/crypttab