Convert MBR Partition in CentOS/RHEL/AlmaLinux 8

By default when installing CentOS 8, the BIOS will be MBR. This can be changed while installing by adding the inst.gpt to the vmlinuz line during the installing process.  However, if you forget to do so, it is not too late.  For fun, I followed this process that I found online and it worked without damaging the virtual machine.  I would rather restart the installation process, but this should work in a bind.

vmlinuz initrd=initrd.img inst.stage2=hd:LABEL=CentOS->8-BaseOS-x86_64 rd.live.check quiet inst.gpt

The process was painless.  The commands.

gdisk /dev/sda
# print
p
# new
n
# Create a new bootable partition. As the first sector, enter 34 and the last sector is 2047. Partition code is ef02.
# save changes
w
# do you want to proceed
y
partprobe
grub2-install /dev/sda
gdisk /dev/sda
# see if takes
reboot

The commands with output

[root@localhost ~]# gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.3

Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************


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

Command (? for help): p
Disk /dev/sda: 67108864 sectors, 32.0 GiB
Model: Virtual disk
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): E5B166D3-3135-47F0-A140-42A4A41E545D
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 67108830
Partitions will be aligned on 2048-sector boundaries
Total free space is 14659517 sectors (7.0 GiB)

Number Start (sector) End (sector) Size Code Name
1 2048 6143 2.0 MiB 8300 Linux filesystem
2 6144 2103295 1024.0 MiB 8300 Linux filesystem
3 2103296 52451327 24.0 GiB 8E00 Linux LVM

Command (? for help): n
Partition number (4-128, default 4): 34
First sector (34-67108830, default = 52451328) or {+-}size{KMGTP}: 2047
Last sector (2047-2047, default = 2047) or {+-}size{KMGTP}: ^C
[root@localhost ~]# gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.3

Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************


Command (? for help): p
Disk /dev/sda: 67108864 sectors, 32.0 GiB
Model: Virtual disk
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): C2C9ED82-14B1-4AAE-B1C2-0E60D4DDB0DD
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 67108830
Partitions will be aligned on 2048-sector boundaries
Total free space is 14659517 sectors (7.0 GiB)

Number Start (sector) End (sector) Size Code Name
1 2048 6143 2.0 MiB 8300 Linux filesystem
2 6144 2103295 1024.0 MiB 8300 Linux filesystem
3 2103296 52451327 24.0 GiB 8E00 Linux LVM

Command (? for help): n
Partition number (4-128, default 4):
First sector (34-67108830, default = 52451328) or {+-}size{KMGTP}: 34
Last sector (34-2047, default = 2047) or {+-}size{KMGTP}: 2047
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): ef02
Changed type of partition to 'BIOS boot partition'

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/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
[root@localhost ~]# partprobe
[root@localhost ~]# grub2-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.
[root@localhost ~]# gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.3

Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): ^C
[root@localhost ~]# reboot now

After the reboot, I decided to clean this up a little by using the unused space /dev/sda1 as GPT and deleting the new partition /dev/sda4. Here’s what I did after the reboot.

gdisk /dev/sda 
# print 
p 
# delete /dev/sda1. Make note of the start and end sector
d
1
## Create a new bootable partition. As the first sector, enter 2048 and the last sector is 6143. Partition code is ef02. 
# create /dev/sda1 using same start and end sector
n
1
2048
6143
ef02
# Delete /dev/sda4
d
4clear
# save changes 
w 
# do you want to proceed 
y 

partprobe 
grub2-install /dev/sda 
gdisk /dev/sda 

# see if takes 
reboot

It works.

[root@localhost ~]# gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.3

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/sda: 67108864 sectors, 32.0 GiB
Model: Virtual disk
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): C2C9ED82-14B1-4AAE-B1C2-0E60D4DDB0DD
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 67108830
Partitions will be aligned on 2048-sector boundaries
Total free space is 14659517 sectors (7.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048            6143   2.0 MiB     EF02  BIOS boot partition
   2            6144         2103295   1024.0 MiB  8300  Linux filesystem
   3         2103296        52451327   24.0 GiB    8E00  Linux LVM

Command (? for help):

Source(s)

  • https://techjogging.com/convert-mbr-partition-into-gpt-in-centosrhel-7.html