summaryrefslogtreecommitdiff
path: root/wipedisk
blob: 0c08c72c939255a1a9b831c26f0a933694cb3e17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env bash
# Craig Jennings <c@cjennings.net>
# identify disk and erase 

all_disk_ids=( $(ls /dev/disk/by-id/) )
echo ""; echo "Select the disk id to use. All data will be erased."
select disk_id in "${all_disk_ids[@]}"; do
    # ensure valid selection
    if [[ -n $disk_id ]]; then
        selection=$disk_id
        break
    else
        echo "Invalid. Try again."
    fi
done

# Confirm the selected disk
read -p "Confirm: '$selection' [y/n]? " choice
if [[ "$choice" != "y" ]]; then
    echo "Exiting..."
    exit 1
fi

DISK="/dev/disk/by-id/$selection"
echo ""; echo "### Erasing Disk"
blkdiscard -f "${DISK}" || true    # discard all sectors on flash-based storage
sgdisk --zap-all "${DISK}"         # clear the disk

echo ""
echo "Disk erased."