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:
In Linux, UUID(Universally Unique Identifier) can identify media more accurately and reliable, identify media via /dev/hdxy or /dev/sdxy is not a good method because the order may be different between boots, so it was no longer preferred any more, especially in fstab or grub config.