Last active
February 18, 2025 21:48
-
-
Save jhoblitt/cb91d6388dd55f3e3207e9caacf8fa3b to your computer and use it in GitHub Desktop.
chatgpt o1 generated script to cleanup after ceph on drives which have already have the partition table removed by kickstart.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# WARNING: This operation is destructive and will overwrite data on the device. | |
# Ensure you really want to overwrite these drives. | |
for dev in $(lsblk -dn -o NAME | grep '^nvme'); do | |
# Capture parted output (quiet mode) and return code | |
parted_output=$(parted -s "/dev/$dev" print 2>&1) | |
parted_status=$? | |
if [[ $parted_status -ne 0 ]]; then | |
# parted returned an error => no recognized partition table | |
echo "/dev/$dev has NO recognized partition table" | |
echo "Wiping first 1GB of /dev/$dev..." | |
dd if=/dev/zero of="/dev/$dev" bs=1M count=1024 status=progress | |
else | |
# parted succeeded => check if there are zero partitions | |
# Look for lines that start with a digit (e.g. " 1 ") in parted output | |
partitions_count=$(echo "$parted_output" | grep -E '^[[:space:]]*[0-9]+' | wc -l) | |
if [[ $partitions_count -eq 0 ]]; then | |
echo "/dev/$dev has a partition table but NO partitions" | |
echo "Wiping first 1GB of /dev/$dev..." | |
dd if=/dev/zero of="/dev/$dev" bs=1M count=1024 status=progress | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment