Files
LUKS-Lock-und-Unlock-per-Bash/lock_and_unmount.sh
2025-07-31 10:15:36 +00:00

50 lines
1.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# === KONFIGURATION ===
declare -A DRIVES
# Format: [Mapper-Name]="/srv/dev-disk-by-uuid-<UUID>"
DRIVES[media]="/srv/dev-disk-by-uuid-cdd3de56-0b4f-48cf-aec0-abf441a759b5"
DRIVES[eintb]="/srv/dev-disk-by-uuid-97a953c1-2796-48d6-878b-083d4553bcf4"
DRIVES[kleine]="/srv/dev-disk-by-uuid-e8faffbf-7ba0-4fc3-876e-107f7c6a429d"
for MAPPER in "${!DRIVES[@]}"; do
MOUNTPOINT="${DRIVES[$MAPPER]}"
echo ">>> Verarbeite $MAPPER (Mountpoint: $MOUNTPOINT)"
if mountpoint -q "$MOUNTPOINT"; then
echo " 📢 Mountpoint ist eingehängt."
# Blockierende Prozesse anzeigen
echo " 🔎 Blockierende Prozesse:"
sudo fuser -vm "$MOUNTPOINT" || echo " Keine Prozesse gefunden."
# Normal aushängen versuchen
echo " 🚪 Versuche normales Aushängen..."
if sudo umount "$MOUNTPOINT"; then
echo " ✅ Erfolgreich ausgehängt."
else
echo " ⚠ Normales Aushängen fehlgeschlagen."
echo " 💤 Versuche Lazy Unmount..."
if sudo umount -l "$MOUNTPOINT"; then
echo " ✅ Lazy Unmount erfolgreich."
else
echo " ❌ Lazy Unmount ebenfalls fehlgeschlagen. Bitte prüfen!"
continue
fi
fi
else
echo " Mountpoint ist nicht eingehängt."
fi
# LUKS schließen
echo " 🔒 Schließe LUKS-Mapper /dev/mapper/$MAPPER ..."
if sudo cryptsetup close "$MAPPER"; then
echo " ✅ Mapper $MAPPER geschlossen."
else
echo " ⚠ Mapper $MAPPER konnte nicht geschlossen werden (evtl. noch in Benutzung)."
fi
echo
done