Skip to content

Instantly share code, notes, and snippets.

@priyadarshan
Last active May 31, 2020 09:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save priyadarshan/7101cfb608e92771bdf17370d4a9583d to your computer and use it in GitHub Desktop.
Save priyadarshan/7101cfb608e92771bdf17370d4a9583d to your computer and use it in GitHub Desktop.
illumos/OmniOS - Wipe disks in order to re-use them from previous zpool
#!/usr/bin/ksh93
# This script only wipe same-sized disks for now
SIZE="10000831348736"
LAST_PART=`echo "($SIZE / 1024 / 1024) - 10" | /usr/bin/bc`
# List of disks to wipe
DRIVES="c0t5000CCA26BD0CAFAd0p0 c0t5000CCA26BD116ACd0p0 c0t5000CCA26BD59F6Dd0p0 c0t5000CCA26BD5AAC5d0p0
c0t5000CCA26BD6960Ed0p0 c0t5000CCA26BD6B9CCd0p0 c0t5000CCA26BD6C6D4d0p0 c0t5000CCA26BD6E59Cd0p0"
verifydrives()
{
for DRIVE in $DRIVES
do
if [ `/bin/ls -1 /dev/rdsk/$DRIVE` ]
then
echo "Drive $DRIVE verified."
else
echo "Drive /dev/rdsk/$DRIVE does not exists. Aborting"
exit
fi
done
}
verifydrives
cleandrives()
{
for DRIVE in $DRIVES
do
echo "Wiping disk /dev/rdsk/$DRIVE"
echo ""
echo "Wipe beginning of disk"
dd if=/dev/zero of=/dev/rdsk/${DRIVE} bs=1M count=10 #>/dev/null 2>&1
echo ""
echo "Wipe last part of disk"
dd if=/dev/zero of=/dev/rdsk/${DRIVE} bs=1M count=10 seek=$LAST_PART
echo "$DRIVE done"
echo ""
done
}
echo ""
echo "This will irreversibly destroy partition- and filesystem data on drive(s):"
echo "$DRIVES"
echo ""
echo "USE WITH EXTREME CAUTION!"
echo Do you confirm "yes/no":
read choice
case "$choice" in
yes|Yes|y) cleandrives $DRIVES
echo ""
echo "Drive(s) cleaned." ;;
no) echo ""
echo "Cleaning cancelled."; break ;;
*) echo ""
echo "Cleaning cancelled."; break ;;
esac
@priyadarshan
Copy link
Author

If we need to re-use ZFS disks on same or another OS, experience has shown that it is better to wipe clean first and last part of each disk.

For example, if we bring in disks from FreeBSD, which may or may not end up on a FreeBSD server once again, it is important to erase not only the initial 1M block, but also the last one, since that contains a backup copy of the initial partition.

So, we need to wipe first and last few sectors clean, since they may be labeled in different ways, which could cause issues later on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment