How to format a disk from MBR to GPT.
Here’s how to do it with fdisk:
Install Required Tools: If you don’t have
gdisk, you can usefdiskinstead. It should be already installed on most Arch Linux systems. If you prefer a more user-friendly interface, you can also usecfdisk.Identify the Disk: Use the
lsblkcommand to identify the disk you want to convert. Make sure you note down the device name (e.g.,/dev/sda) of the disk you want to convert.Unmount Partitions: If any partitions on the disk are mounted, unmount them using the
umountcommand.Run fdisk: Launch
fdiskwith the device name of the disk you want to convert:
sudo fdisk /dev/sdX
Replace /dev/sdX with the device name of your disk.
Convert to GPT: Once in
fdisk, typegto create a new empty GPT partition table.Write Changes: After creating the GPT partition table, type
wto write the changes to the disk.Confirm: Confirm the action when prompted.
Recreate Partitions (if necessary): You may need to recreate partitions on the disk using
fdisk,cfdisk, or any other partitioning tool you prefer.
Remember, converting the disk from MBR to GPT will erase all data on it, so make sure to back up any important data before proceeding. Also, be very careful when selecting the correct disk to avoid accidentally overwriting data on the wrong disk.
Reformatting a disk from MBR (Master Boot Record) to GPT (GUID Partition Table) involves several steps, and it will erase all data on the disk. Be sure to back up any important data before proceeding.
Steps to Reformat a Disk from MBR to GPT
Identify the Disk Use
lsblkorfdisk -lto identify the disk you want to convert. Let’s assume the disk is/dev/sdx.lsblkBackup Important Data Ensure that any important data on the disk is backed up, as the conversion process will erase all data on the disk.
Delete Existing Partitions Use
fdiskto delete all existing partitions on the disk.fdisk /dev/sdxInside
fdisk, use the following commands:pto print the current partition table.dto delete a partition (repeat this for each partition).wto write the changes and exit.
Convert the Disk to GPT Using
gdiskUsegdiskto convert the disk to GPT.gdiskis a GPT-aware partitioning tool.gdisk /dev/sdxInside
gdisk, use the following commands:oto create a new empty GUID partition table (GPT).wto write the new GPT partition table to the disk and exit.
Example:
Command (? for help): o This option deletes all partitions and creates a new protective MBR. Proceed? (Y/N): y Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): yCreate New Partitions Using
gdiskYou can now create new partitions on the GPT disk usinggdisk.gdisk /dev/sdxInside
gdisk, use the following commands to create partitions:nto create a new partition.- Specify the partition number, start sector, and size.
- Set the partition type (e.g.,
8300for Linux filesystem).
Example:
Command (? for help): n Partition number (1-128, default 1): 1 First sector (34-234441614, default = 2048) or {+-}size{KMGTP}: <press Enter for default> Last sector (2048-234441614, default = 234441614) or {+-}size{KMGTP}: +512M Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): ef00 Changed type of partition to 'EFI System' Command (? for help): n Partition number (1-128, default 2): 2 First sector (34-234441614, default = 1050624) or {+-}size{KMGTP}: <press Enter for default> Last sector (1050624-234441614, default = 234441614) or {+-}size{KMGTP}: +16G Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): 8200 Changed type of partition to 'Linux swap' Command (? for help): n Partition number (1-128, default 3): 3 First sector (34-234441614, default = 34603008) or {+-}size{KMGTP}: <press Enter for default> Last sector (34603008-234441614, default = 234441614) or {+-}size{KMGTP}: <press Enter for default> Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): 8300wto write the new partition table to the disk and exit.
Command (? for help): wFormat the New Partitions Format the new partitions with the desired filesystem. For example, to format the EFI System Partition (ESP) as FAT32 and the Linux filesystem partition as ext4:
mkfs.fat -F32 /dev/sdx1 mkfs.ext4 /dev/sdx3 mkswap /dev/sdx2
Summary of Commands
- Identify the disk:
lsblkorfdisk -l - Delete existing partitions:
fdisk /dev/sdx - Convert to GPT:
gdisk /dev/sdx - Create new partitions:
gdisk /dev/sdx - Format the new partitions:
mkfs.fat -F32 /dev/sdx1,mkfs.ext4 /dev/sdx3,mkswap /dev/sdx2
By following these steps, you will have successfully converted your disk from MBR to GPT and created new partitions on the GPT disk.