7

I've seen some disk formatting/partitioning discussions that mention destroying existing GPT/MBR data structures as a first step:

sgdisk --zap-all /dev/nvme0n1

I wasn't previously aware of this, and when I've set up a disk, I've generally used:

parted --script --align optimal  \
    /dev/nvme0n1 --              \
    mklabel gpt                  \
    mkpart ESP fat32 1MiB 512MiB \
    set 1 boot on                \
    name 1 boot                  \
    mkpart primary 512MiB 100%   \
    set 2 lvm on                 \
    name 2 primary

Should I have cleared things out (e.g. sgdisk --zap-all) first? What are the downsides to not having done that?

ivan
  • 1,858
  • 2
  • 19
  • 37

1 Answers1

13

This advice is from the time when other tools didn't properly support GPT and were not removing all the pieces of the GPT metadata. From sgdisk man page for the --zap/--zap-all option:

Use this option if you want to repartition a GPT disk using fdisk or some other GPT-unaware program.

That's no longer true. Both fdisk and parted support GPT now and if you create a new partition table, they will remove both the two GPT headers (GPT has a backup header at the end of the disk that can cause problems when not removed) and the Protective MBR header.

That being said, it is generally not a bad idea to properly remove all headers/signatures when removing a preexisting storage layout. I personally use wipefs to remove signatures from all devices before removing them just to make sure there nothing left that could be unexpectedly discovered later -- I've been in situations where a newly created MD array or LVM logical volume suddenly has a filesystem on it just because it was created on the same (or close enough) offset where a previous device was. Storage tools usually try to detect filesystem signatures when creating a new partition/device and can wipe them for you, but doing that manually never hurts.

Vojtech Trefny
  • 16,922
  • 6
  • 24
  • 48
  • Thanks, this was very helpful. Using wipefs (`sudo wipefs --output TYPE,OFFSET /dev/nvme0n1`) to list the signatures on a machine I installed linux on, I see two gpt signatures and a PMBR signature. I thought there would be just one signature, gpt, so I'm wondering if the PMBR and one of the gpt signatures are residue from before I got my hands on this machine? – ivan May 20 '23 at 19:11
  • 2
    That's normal: One GPT signature at the beginning of the disk, one at the end of the disk (that's a backup copy of the first one) and PMBR for backwards compatibility with systems without GPT support (it's a simple MBR/DOS partition table with one "fake" partition spanning the entire disk -- systems that don't understand GPT will see that partition instead of "empty" disk). – Vojtech Trefny May 20 '23 at 19:27