#!/bin/bash # Wipes the ZFS labels off of a disk # The metadata of zfs is stored in the first and last two 256kB of each disk involved in zfs. DISK=$1 if [[ -z "$1" ]]; then echo "Usage: $0 " exit 1 fi # List the labels echo "-> About to clear these labels off of this disk: $DISK" blkid "$DISK" lsblk --output NAME,FSTYPE,MODEL,LABEL,PTTYPE,SIZE -e 7 "$DISK" echo "-> Are you sure you want to continue? (y/n)" read input && if [ "$input" != "y" ]; then exit 1; fi # Wipe all partitions and MBR and GPT labels sudo sgdisk -Z "$DISK" # Wipe the metadata off the front of the disk sudo dd if=/dev/zero of="$DISK" bs=512k count=10 # Wipe the metadata off the back of the disk sudo dd if=/dev/zero of="$DISK" bs=512k seek=$(( $(blockdev --getsz "$DISK") - 4096 )) count=1M # List the labels echo "-> Labels now on the disk" blkid "$DISK" lsblk --output NAME,FSTYPE,MODEL,LABEL,PTTYPE,SIZE -e 7 "$DISK"