sh/sh/fs.sh

122 lines
2.1 KiB
Bash
Raw Normal View History

2024-11-12 21:38:38 +00:00
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
}
2024-11-12 21:52:21 +00:00
fs_make_btrfs_swap() {
local path="${1}"
local size="${2}"
local uuid="${3}"
if [ -n "${path}" ]; then
2024-11-13 12:14:58 +00:00
set -- filesystem mkswapfile
2024-11-12 21:52:21 +00:00
if [ -n "${size}" ]; then
set -- "${@}" \
--size "${size}"
fi
if [ -n "${uuid}" ]; then
set -- "${@}" \
--uuid "${uuid}"
fi
btrfs "${@}" "${path}"
fi
}
2024-11-12 19:03:47 +00:00
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
}
2024-11-12 19:13:32 +00:00
2024-11-13 13:30:50 +00:00
fs_raid_create() {
if [ -n "${4}" ]; then
local name="${1}"
local uuid="${2}"
shift 2
mdadm \
--create "/dev/md/${name}" \
--level 0 \
--metadata 1 \
--name "md:${name}" \
--raid-devices ${#} \
--uuid "${uuid}" \
"${@}"
fi
}
2024-11-12 19:13:32 +00:00
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 -- "${@}" \
2024-11-13 10:43:12 +00:00
count="${count}"
2024-11-12 19:13:32 +00:00
fi
dd "${@}"
fi
}
2024-11-12 22:13:45 +00:00
luks_format() {
2024-11-12 22:27:19 +00:00
local passphrase="${1}"
local device="${2}"
local label="${3}"
local uuid="${4}"
2024-11-12 22:13:45 +00:00
if [ -b "${device}" ]; then
2024-11-12 22:32:14 +00:00
set -- \
--batch-mode \
--cipher "aes-xts-plain64" \
--hash "sha512" \
--iter-time 4096 \
--key-size 512 \
--pbkdf "argon2id" \
--type "luks2" \
--use-random \
--verbose
if [ -n "${label}" ]; then
set -- "${@}" --label "${label}"
fi
if [ -n "${uuid}" ]; then
2024-11-12 22:32:36 +00:00
set -- "${@}" --uuid "${uuid}"
2024-11-12 22:32:14 +00:00
fi
2024-11-12 22:13:45 +00:00
echo "${passphrase}" |
2024-11-12 22:32:14 +00:00
cryptsetup "${@}" luksFormat "${device}"
2024-11-12 22:13:45 +00:00
fi
}