How to remove a GPT label in Red Hat Enterprise Linux?

Solution Unverified - Updated

Environment

  • Red Hat Enterprise Linux (RHEL) 7 and higher versions.

Issue

  • Need to remove the GPT label present on-disk

Resolution

To remove a GPT label from disk in Red Hat Enterprise Linux 7 and above versions, use the wipefs command.

  1. View the label(s) via parted, fdisk, and hexdump commands:

        # parted /dev/sdN u s p
        Model: QEMU QEMU HARDDISK (scsi)
        Disk /dev/sdN: 4194304s
        Sector size (logical/physical): 512B/512B
        Partition Table: gpt <---
        Disk Flags: 
        Number  Start  End       Size      File system  Name     Flags
         1      2048s  4192255s  4190208s               primary
    
        
        # fdisk -l /dev/sdN
        WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
        Disk /dev/sdN: 2147 MB, 2147483648 bytes, 4194304 sectors
        Units = sectors of 1 * 512 = 512 bytes
        Sector size (logical/physical): 512 bytes / 512 bytes
        I/O size (minimum/optimal): 512 bytes / 512 bytes
        Disk label type: gpt <---
        Disk identifier: FAC330FF-E081-4A82-90A0-E0A397D4064E
        
        #         Start          End    Size  Type            Name
         1         2048      4192255      2G  Microsoft basic primary
    
        
        # hexdump -C /dev/sdN | grep 'EFI PART'
        00000200  45 46 49 20 50 41 52 54  00 00 01 00 5c 00 00 00  |EFI PART....\...| <---
        7ffffe00  45 46 49 20 50 41 52 54  00 00 01 00 5c 00 00 00  |EFI PART....\...| <---
    

    Note the Primary GPT label at offset 0x00000200 bytes and backup at 0x7ffffe00.

  2. Print the location of the label using the wipefs tool:

    # wipefs /dev/sdN
    offset               type
    ----------------------------------------------------------------
    0x200 <---           gpt   [partition table]
    
  3. Specifying the offset found, remove the label with the wipefs command:

    # wipefs -o 0x200 /dev/sdN
    /dev/sdN: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54
    /dev/sdN: calling ioclt to re-read partition table: Success
    
  4. In case, the backup GPT table has to be cleared off, use wipefs:

    # wipefs -a -t gpt /dev/sdN
    /dev/sdN: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54
    /dev/sdN: 8 bytes were erased at offset 0x7ffffe00 (gpt): 45 46 49 20 50 41 52 54
    /dev/sdN: calling ioclt to re-read partition table: Success
    
  5. Verify the label has been removed. At this point, the disk should be ready for use:

    # parted /dev/sdN u s p
    Error: /dev/sdN: unrecognised disk label
    Model: QEMU QEMU HARDDISK (scsi)                                          
    Disk /dev/sdN: 4194304s
    Sector size (logical/physical): 512B/512B
    Partition Table: unknown <---
    Disk Flags: 
    

Important

  • Please note that fdisk will still pick up the partition table even after wiping the primary GPT label with wipefs, because PMBR will still be present on the disk.
  • The wipefs -a -t gpt,PMBR /dev/sdN command can be used to remove the PMBR and GPT label at the same time.
  • Currently, the wipefs -a -t gpt /dev/sdN will remove the PMBR, but a bug exists and is mentioned later in this solution.
  • The wipefs -a /dev/sdN command can be used, but please note that this will erase every label on the disk and should be used with care.

  1. If there is a need to manually clear the marker for the PMBR, check the offset first:

    # hexdump -C /dev/sdN | grep '55 aa'
    000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
    

    The offset in the example above is 0x000001f0, which converted to decimal is 496. Each 00 represents 1 byte, so add 14 places(bytes) to get to the front of the two-byte 55 aa. That gives an offset of 510.

  2. Manually wipe the 55 aa using the dd tool:

    # dd if=/dev/zero of=/dev/sdN ibs=1 obs=1 seek=510 count=2
    2+0 records in
    2+0 records out
    2 bytes (2 B) copied, 0.00080767 s, 2.5 kB/s
    
  3. Verify fdisk no longer prints the table

    # fdisk -l /dev/sdN
    Disk /dev/sdN: 2147 MB, 2147483648 bytes, 4194304 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    
SBR
Category
Tags

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.