fs_make_btrfs() { local device="${1}" local label="${2}" local uuid="${3}" if [ -b "${device}" ]; then set -- \ --force \ --checksum "sha256" if [ -n "${label}" ]; then set -- "${@}" \ --label "${label}" fi if [ -n "${uuid}" ]; then set -- "${@}" \ --uuid "${uuid}" fi mkfs.btrfs "${@}" "${device}" fi } fs_make_btrfs_swap() { local path="${1}" local size="${2}" local uuid="${3}" if [ -n "${path}" ]; then set filesystem mkswapfile if [ -n "${size}" ]; then set -- "${@}" \ --size "${size}" fi if [ -n "${uuid}" ]; then set -- "${@}" \ --uuid "${uuid}" fi btrfs "${@}" "${path}" fi } fs_make_fat() { local device="${1}" local name="${2}" local volid="${3}" if [ -b "${device}" ]; then set -- \ -F 32 \ -S 4096 if [ -n "${name}" ]; then set -- "${@}" \ -n "${name}" fi if [ -n "${volid}" ]; then set -- "${@}" \ -i "${volid}" fi mkfs.fat "${@}" "${device}" fi } fs_wipe() { local device="${1}" local buffer="${2}" local count="${3}" if [ -b "${device}" ]; then set -- \ status="progress" \ if="/dev/zero" \ of="${device}" if [ -n "${buffer}" ]; then set -- "${@}" \ bs="${buffer}" fi if [ -n "${count}" ]; then set -- "${@}" \ count=${count} fi dd "${@}" fi } luks_format() { local device="${1}" local passphrase="${2}" if [ -b "${device}" ]; then echo "${passphrase}" | cryptsetup \ --verbose \ --batch-mode \ --type "luks2" \ --pbkdf "argon2id" \ --cipher "aes-xts-plain64" \ --iter-time 4096 \ --key-size 512 \ --hash "sha512" \ --use-random \ luksFormat \ "${device}" fi }