From b03278ac860311dfe43242c98302491d7b414e9b Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Wed, 12 Mar 2025 11:30:58 +0100 Subject: [PATCH] feat: add device usage check before preparing ZFS datasets --- prepare-zfs-datasets.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/prepare-zfs-datasets.sh b/prepare-zfs-datasets.sh index 04e95b8..ecd021e 100755 --- a/prepare-zfs-datasets.sh +++ b/prepare-zfs-datasets.sh @@ -9,6 +9,12 @@ echo "" echo "Enter the device to use for the ZFS pool (e.g., /dev/sdb):" read device +# Confirm the device is not in use +if mount | grep "$device"; then + echo "Error: $device is already mounted. Exiting..." + exit 1 +fi + # Ask for confirmation, since this script will destroy all data on the device echo "This script will destroy all data on $device. Are you sure you want to continue? (y/n)" read confirm