Browse Source

really really clean a disk

master
Coesens Bert 11 months ago
parent
commit
ec073aac0e
1 changed files with 30 additions and 0 deletions
  1. +30
    -0
      reallycleandisk.sh

+ 30
- 0
reallycleandisk.sh View File

@@ -0,0 +1,30 @@
#!/usr/bin/bash
set -x

DISK=${1:-nodisk}

if [ "x${DISK}" = "xnodisk" ]; then
echo "What disk ? (sda, sdb, nvme0n1,...)"
exit 1
fi

SIZE=$(sudo blockdev --getsz /dev/${DISK})
PBSZ=$(sudo blockdev --getpbsz /dev/${DISK})
SEEK=$(($SIZE - 256 * 1024 * 2 / $PBSZ))
LEN=$((256 *2 *1024 /$PBSZ))
# SEEK=$(( $(sudo blockdev --getsz "/dev/sdX1") - 256 * 1024 * 2 / $(sudo blockdev --getpbsz "/dev/sdX1")))
echo $SIZE $PBSZ $SEEK $LEN
for i in 1 2 3 4 ; do
TOWIPE=${DISK}${i}
if [ -b /dev/$TOWIPE ] ; then
sudo wipefs -a -f /dev/${TOWIPE}
sudo dd if=/dev/zero of=/dev/${TOWIPE} bs=$PBSZ count=$LEN
sudo dd if=/dev/zero of=/dev/${TOWIPE} seek=$SEEK bs=$PBSZ count=$LEN
fi
done



sudo wipefs -a -f /dev/${DISK}
sudo dd if=/dev/zero of=/dev/${DISK} bs=$PBSZ count=$LEN
sudo dd if=/dev/zero of=/dev/${DISK} seek=$SEEK bs=$PBSZ count=$LEN

Loading…
Cancel
Save