From 703d2813082c6e6b95d2e7ad91cc66f526dc6983 Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Mon, 11 Nov 2024 11:54:59 -0500 Subject: [PATCH] Added mount-btrfs script to auto mount/unmount btrfs root volume --- scripts/mount-btrfs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 scripts/mount-btrfs diff --git a/scripts/mount-btrfs b/scripts/mount-btrfs new file mode 100755 index 0000000..54563a0 --- /dev/null +++ b/scripts/mount-btrfs @@ -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