Change GPT Partition Type Code
Why change the type code of a hard disk partition? Here’s how it all started.
Ventoy is an open source tool to create bootable USB drive for ISO/WIM/IMG/VHD(x)/EFI files. There is a problem, when it create an EFI partition.
But there’s a problem, Ventoy creates an EFI partition, formatted as FAT16, and the partition type code is 0700
(correctly it should be EF00
). On macOS, since the EFI partition is automatically mounted, if two USB flash drives are inserted at the same time, the second one will not be mounted correctly.
After doing some searching, I chose GPT fdisk. It is open source software (GPL) and cross-platform, supporting Linux, macOS, Windows.
Preparation Tools
For macOS, download gdisk-1.0.10.pkg. Once installed, you can use gdisk
with root
privileges.
# /dev/disk2 is the target disk
sudo gdisk /dev/disk2
Command ?
for help.
Command (? for help): ?
b back up GPT data to a file
c change a partition's name
d delete a partition
i show detailed information on a partition
l list known partition types
n add a new partition
o create a new empty GUID partition table (GPT)
p print the partition table
q quit without saving changes
r recovery and transformation options (experts only)
s sort partitions
t change a partition's type code
v verify disk
w write table to disk and exit
x extra functionality (experts only)
? print this menu
Change Disk Partition Type Code
The specific steps are as follows.
p
print the partition table (To confirm you have select the right disk)t
change a partition’s type code.- Enter
2
. It needs to be entered as appropriate. - Enter partition type code
ef00
. ef00 is for EFI,enterL
to list partition types. p
print the partition table (Make sure the changes are correct).w
write table to disk and exit.y
Confirm to proceed.
The modification is completed.
An example of the operation is shown below.
sudo gdisk /dev/disk2
Command (? for help): p
Number Start (sector) End (sector) Size Code Name
1 2048 976707591 465.7 GiB 0700 Ventoy
2 976707592 976773127 32.0 MiB 0700 VTOYEFI
Command (? for help): t
Partition number (1-2): 2
Current type is 700 (Microsoft basic data)
Hex code or GUID (L to show codes, Enter = 700): ef00
Changed type of partition to 'EFI system partition'
Command (? for help): p
Number Start (sector) End (sector) Size Code Name
1 2048 976707591 465.7 GiB 0700 Ventoy
2 976707592 976773127 32.0 MiB EF00 VTOYEFI
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/disk2.
Hard Disk Selection Methods for Operating Systems
# N for disk number
# macOS
gdisk /dev/diskN
# Windows
# Terminal needs to be executed in administrator mode.
# PhysicalDriveN,N for disk number,start from 0.
gdisk64.exe \\.\PhysicalDriveN
# Linux
gdisk /dev/sdN
# FreeBSD
# adN or daN
gdisk /dev/adN