Private Paste

Untitled paste

text · created 2026-09-01 19:00:56 · views 53
Raw
Script: 

#!/usr/bin/env bash
set -euo pipefail

DEV="${1:-}"

if [[ -z "$DEV" || ! -b "$DEV" ]]; then
    echo "Usage: sudo $0 /dev/sdX"
    exit 1
fi

if [[ "$DEV" =~ [0-9]$ ]]; then
    echo "Refusing to operate on a partition. Use the whole device, e.g. /dev/sdX."
    exit 1
fi

echo "About to permanently erase: $DEV"
lsblk -o NAME,SIZE,MODEL,SERIAL "$DEV"
read -r -p "Type ERASE to continue: " confirm

[[ "$confirm" == "ERASE" ]] || {
    echo "Cancelled."
    exit 1
}

# Unmount any mounted partitions belonging to the drive.
while read -r part; do
    sudo umount "$part" 2>/dev/null || true
done < <(lsblk -lnpo NAME "$DEV" | tail -n +2)

# One full-device pass using cryptographically secure random data.
sudo dd if=/dev/urandom of="$DEV" bs=16M status=progress conv=fsync

sync
echo "Completed."

Command: 
sudo ./erase-random.sh /dev/sdX