浏览代码

really really clean a disk

master
Coesens Bert 10 个月前
父节点
当前提交
ec073aac0e
共有 1 个文件被更改,包括 30 次插入0 次删除
  1. +30
    -0
      reallycleandisk.sh

+ 30
- 0
reallycleandisk.sh 查看文件

@@ -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

正在加载...
取消
保存