Changed deprecated calls to tempfile to mktemp instead
[zfs-ubuntu/.git] / zfs-labelclear
1 #!/bin/bash
2 # Wipes the ZFS labels off of a disk
3 # The metadata of zfs is stored in the first and last two 256kB of each disk involved in zfs.
4
5 DISK=$1
6
7 if [[ -z "$1" ]]; then
8   echo "Usage: $0 <disk>"
9   exit 1
10 fi
11
12 # List the labels
13 echo "-> About to clear these labels off of this disk: $DISK" 
14 blkid "$DISK"
15 lsblk --output NAME,FSTYPE,MODEL,LABEL,PTTYPE,SIZE -e 7 "$DISK"
16 echo "-> Are you sure you want to continue? (y/n)"
17 read input && if [ "$input" != "y" ]; then exit 1; fi
18
19 # Wipe all partitions and MBR and GPT labels
20 sudo sgdisk -Z "$DISK"
21
22 # Wipe the metadata off the front of the disk
23 sudo dd if=/dev/zero of="$DISK" bs=512k count=10
24
25 # Wipe the metadata off the back of the disk
26 sudo dd if=/dev/zero of="$DISK" bs=512k seek=$(( $(blockdev --getsz "$DISK") - 4096 )) count=1M
27
28 # List the labels
29 echo "-> Labels now on the disk"
30 blkid "$DISK"
31 lsblk --output NAME,FSTYPE,MODEL,LABEL,PTTYPE,SIZE -e 7 "$DISK"