From ccf2d2ac72411c84c6cd2c173b56bfb8aefe1ccb Mon Sep 17 00:00:00 2001 From: hax Date: Fri, 2 May 2025 22:20:22 +0000 Subject: [PATCH] =?UTF-8?q?unload-chroot.sh=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hax --- unload-chroot.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 unload-chroot.sh diff --git a/unload-chroot.sh b/unload-chroot.sh new file mode 100644 index 0000000..10ed83e --- /dev/null +++ b/unload-chroot.sh @@ -0,0 +1,47 @@ +#!/bin/bash +set -euxo pipefail + +# Path to the variables log file +VARIABLES_LOG="/rescue/variables.log" + +# Check if variables log file exists +if [ ! -f "$VARIABLES_LOG" ]; then + echo "❌ No variables log file found. Aborting unmount." + exit 1 +fi + +# Read the variables from the log file and convert them to shell format +partition=$(sed -n 's/^partition="\([^"]*\)"/\1/p' "$VARIABLES_LOG") +efi=$(sed -n 's/^efi="\([^"]*\)"/\1/p' "$VARIABLES_LOG") +home=$(sed -n 's/^home="\([^"]*\)"/\1/p' "$VARIABLES_LOG") + +# Check if necessary variables are loaded +if [ -z "$partition" ] || [ -z "$efi" ] || [ -z "$home" ]; then + echo "❌ Missing variables. Please ensure the script was run previously with valid variables." + exit 1 +fi + +# Unmount the partitions and resources in reverse order of mounting + +echo "Unmounting /rescue/run..." +umount /rescue/run || true +echo "Unmounting /rescue/dev/pts..." +umount /rescue/dev/pts || true +echo "Unmounting /rescue/dev..." +umount /rescue/dev || true +echo "Unmounting /rescue/sys..." +umount /rescue/sys || true +echo "Unmounting /rescue/proc..." +umount /rescue/proc || true +echo "Unmounting /rescue/home..." +umount /rescue/home || true +echo "Unmounting /rescue/boot..." +umount /rescue/boot || true +echo "Unmounting /rescue..." +umount /rescue || true + +# Optional: clean up the /rescue directory after unmounting +echo "Removing /rescue directory (if needed)..." +rmdir /rescue || true + +echo "✅ All partitions and resources have been unmounted and cleaned up."