Added mount-btrfs script to auto mount/unmount btrfs root volume

This commit is contained in:
Eric Renfro 2024-11-11 11:54:59 -05:00
parent 4a9c6f0894
commit 703d281308
Signed by: psi-jack
SSH key fingerprint: SHA256:1TKB8Z257L8EHK8GWNxKgMhD8a+FAR+f+j3nnlcuNVM

45
scripts/mount-btrfs Executable file
View file

@ -0,0 +1,45 @@
#!/bin/bash
restoreDir="/etc/restore"
scriptPath="$(dirname "$(readlink -f "$0")")"
source "${scriptPath}/functions.sh"
hook_before() {
local btrfsPartition
btrfsPartition="$(findmnt -oSOURCE -rnv /)"
if [[ ! -d "/.btrfs" ]]; then
mkdir /.btrfs
fi
if ! mount | grep '\.btrfs' &>/dev/null; then
mount "$btrfsPartition" -o subvolid=5 /.btrfs || exit 200
fi
}
hook_fail() {
if mount | grep '\.btrfs' &>/dev/null; then
umount /.brtfs || exit 200
fi
}
hook_after() {
:
}
hook_final() {
if mount | grep '\.btrfs' &>/dev/null; then
umount /.brtfs || exit 200
fi
}
case "$1" in
before) hook_before || exit $?;;
after) hook_after || exit $?;;
fail) hook_final || exit $?;;
finally) hook_final || exit $?;;
esac