How to remove a GPT label in Red Hat Enterprise Linux?
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.
-
View the label(s) via
parted,fdisk, andhexdumpcommands:# 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
0x00000200bytes and backup at0x7ffffe00. -
Print the location of the label using the
wipefstool:# wipefs /dev/sdN offset type ---------------------------------------------------------------- 0x200 <--- gpt [partition table] -
Specifying the offset found, remove the label with the
wipefscommand:# 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 -
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 -
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
fdiskwill still pick up the partition table even after wiping the primary GPT label withwipefs, becausePMBRwill still be present on the disk. - The
wipefs -a -t gpt,PMBR /dev/sdNcommand can be used to remove thePMBRandGPTlabel at the same time. - Currently, the
wipefs -a -t gpt /dev/sdNwill remove the PMBR, but a bug exists and is mentioned later in this solution. - The
wipefs -a /dev/sdNcommand can be used, but please note that this will erase every label on the disk and should be used with care.
-
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 is496. Each00represents 1 byte, so add 14 places(bytes) to get to the front of the two-byte55 aa. That gives an offset of510. -
Manually wipe the
55 aausing theddtool:# 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 -
Verify
fdiskno 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
-
Note: Two bugs have been opened to get clarification on
fdiskprinting the table even after label clearing and duplicate line printing:
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.