When doing labs / playing with ZFS on Linux, ZFS pool may creates a few partitions on each drive, we may want to erase all the playground partition table to start from scratch again(though it may not be required), if we have many drives like more than 10, and we want to erase them all, it’ll take a while to finish the job.
Here is a rapid method to do it, using the non-interactive command sgdisk
from package gdisk – the GPT fdisk text-mode partitioning tool, with parameter -Z
or -o
(both work in my case):
$ sudo sgdisk -Z /dev/sda
GPT data structures destroyed! You may now partition the disk using fdisk or other utilities.
$ sudo sgdisk -o /dev/sdb
The operation has completed successfully.
According to the help message, by specifing parameters -Z
, it’ll zap (destroy) the GPT and MBR data structures and exit, and by specifing parameters -o
, it’ll clear out all partition data. This includes GPT header data, all partition definitions, and the protective MBR.
Because the command sgdisk
is non-interactive, so we can simply integrate the whole massive partition clean up job with shell scripts, for example:
#!/bin/bash
sudo sgdisk -Z /dev/sda &
sudo sgdisk -Z /dev/sdb &
sudo sgdisk -Z /dev/sdc &
sudo sgdisk -Z /dev/sdd &
sudo sgdisk -Z /dev/sde &
sudo sgdisk -Z /dev/sdf &
sudo sgdisk -Z /dev/sdg &
That’s it! Happy hacking!