Translate

Archives

Fedora 16 MBR GRUB Legacy to GPT GRUB2

This post discusses how to upgrade your Fedora 16 system from a MBR partitioned boot disk booted using GRUB Legacy to a GPT partitioned disk booted using GRUB2 and a BIOS Boot partition.

For the purpose of this post I set up a 8Gb SPICE guest, installed Fedora 15 and then upgraded the guest to Fedora 16 Beta using the following commands:

# rpm --import https://fedoraproject.org/static/A82BA4B7.txt
# yum -y update yum
# yum clean all
# yum -y --releasever=16 --disableplugin=presto distro-sync

Here is what the boot disk looks like after the upgrade from Fedora 15 to Fedora 16 Beta had completed:

# cd /boot
# ls grub grub2
grub:
device.map     grub.conf         minix_stage1_5     stage2
e2fs_stage1_5  iso9660_stage1_5  reiserfs_stage1_5  ufs2_stage1_5
fat_stage1_5   jfs_stage1_5      splash.xpm.gz      vstafs_stage1_5
ffs_stage1_5   menu.lst          stage1             xfs_stage1_5

grub2:
grub.cfg

# df
Filesystem                  1K-blocks    Used Available Use% Mounted on
rootfs                        5644224 3659344   1698160  69% /
devtmpfs                       500680       0    500680   0% /dev
tmpfs                          510516     224    510292   1% /dev/shm
tmpfs                          510516   46304    464212  10% /run
/dev/mapper/vg_test-lv_root   5644224 3659344   1698160  69% /
tmpfs                          510516   46304    464212  10% /run
tmpfs                          510516       0    510516   0% /sys/fs/cgroup
tmpfs                          510516       0    510516   0% /media
/dev/vda1                      495844   54740    415504  12% /boot

# fdisk /dev/vda

Command (m for help): p

Disk /dev/vda: 8589 MB, 8589934592 bytes
16 heads, 63 sectors/track, 16644 cylinders, total 16777216 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 identifier: 0x000248c1

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1026047      512000   83  Linux
/dev/vda2         1026048    16777215     7875584   8e  Linux LVM

Command (m for help): 


As you can see the disk is MBR and there are two partitions, with /dev/vda1 being the boot partition, /dev/vda2 being used by LVM and the boot loader is GRUB Legacy.

The GRUB2 package is installed as part of the upgrade but is not operational. You can use rpm -ql grub2 to list all the GRUB2 files and their location.

# rpm -ql grub2
/boot/grub2
/boot/grub2/grub.cfg
/etc/bash_completion.d/grub
/etc/default/grub
/etc/grub.d
/etc/grub.d/00_header
/etc/grub.d/10_linux
/etc/grub.d/20_linux_xen
/etc/grub.d/30_os-prober
/etc/grub.d/40_custom
/etc/grub.d/41_custom
/etc/grub.d/90_persistent
/etc/grub.d/README
/etc/grub2.cfg
/sbin/grub2-install
/sbin/grub2-mkconfig
/sbin/grub2-mkdevicemap
/sbin/grub2-mknetdir
/sbin/grub2-probe
/sbin/grub2-reboot
/sbin/grub2-set-default
/sbin/grub2-setup
/usr/bin/grub2-bin2h
/usr/bin/grub2-editenv
/usr/bin/grub2-fstest
/usr/bin/grub2-kbdcomp
/usr/bin/grub2-menulst2cfg
/usr/bin/grub2-mkfont
/usr/bin/grub2-mkimage
/usr/bin/grub2-mklayout
/usr/bin/grub2-mkpasswd-pbkdf2
/usr/bin/grub2-mkrelpath
/usr/bin/grub2-mkrescue
/usr/bin/grub2-script-check
/usr/lib/grub
/usr/lib/grub/grub-mkconfig_lib
/usr/lib/grub/update-grub_lib
/usr/lib/grub2
/usr/lib/grub2/i386-pc
/usr/lib/grub2/i386-pc/acpi.mod
/usr/lib/grub2/i386-pc/affs.mod
/usr/lib/grub2/i386-pc/afs.mod
/usr/lib/grub2/i386-pc/afs_be.mod
/usr/lib/grub2/i386-pc/aout.mod
/usr/lib/grub2/i386-pc/at_keyboard.mod
/usr/lib/grub2/i386-pc/ata.mod
/usr/lib/grub2/i386-pc/ata_pthru.mod
/usr/lib/grub2/i386-pc/befs.mod
/usr/lib/grub2/i386-pc/befs_be.mod
/usr/lib/grub2/i386-pc/biosdisk.mod
/usr/lib/grub2/i386-pc/bitmap.mod
/usr/lib/grub2/i386-pc/bitmap_scale.mod
/usr/lib/grub2/i386-pc/blocklist.mod
/usr/lib/grub2/i386-pc/boot.img
/usr/lib/grub2/i386-pc/boot.mod
/usr/lib/grub2/i386-pc/bsd.mod
/usr/lib/grub2/i386-pc/btrfs.mod
/usr/lib/grub2/i386-pc/bufio.mod
/usr/lib/grub2/i386-pc/cat.mod
/usr/lib/grub2/i386-pc/cdboot.img
/usr/lib/grub2/i386-pc/chain.mod
/usr/lib/grub2/i386-pc/cmostest.mod
/usr/lib/grub2/i386-pc/cmp.mod
/usr/lib/grub2/i386-pc/command.lst
/usr/lib/grub2/i386-pc/config.h
/usr/lib/grub2/i386-pc/configfile.mod
/usr/lib/grub2/i386-pc/cpio.mod
/usr/lib/grub2/i386-pc/cpuid.mod
/usr/lib/grub2/i386-pc/crypto.lst
/usr/lib/grub2/i386-pc/crypto.mod
/usr/lib/grub2/i386-pc/cs5536.mod
/usr/lib/grub2/i386-pc/date.mod
/usr/lib/grub2/i386-pc/datehook.mod
/usr/lib/grub2/i386-pc/datetime.mod
/usr/lib/grub2/i386-pc/diskboot.img
/usr/lib/grub2/i386-pc/dm_nv.mod
/usr/lib/grub2/i386-pc/drivemap.mod
/usr/lib/grub2/i386-pc/echo.mod
/usr/lib/grub2/i386-pc/efiemu.mod
/usr/lib/grub2/i386-pc/efiemu32.o
/usr/lib/grub2/i386-pc/efiemu64.o
/usr/lib/grub2/i386-pc/elf.mod
/usr/lib/grub2/i386-pc/example_functional_test.mod
/usr/lib/grub2/i386-pc/ext2.mod
/usr/lib/grub2/i386-pc/extcmd.mod
/usr/lib/grub2/i386-pc/fat.mod
/usr/lib/grub2/i386-pc/font.mod
/usr/lib/grub2/i386-pc/fs.lst
/usr/lib/grub2/i386-pc/fshelp.mod
/usr/lib/grub2/i386-pc/functional_test.mod
/usr/lib/grub2/i386-pc/gcry_arcfour.mod
/usr/lib/grub2/i386-pc/gcry_blowfish.mod
/usr/lib/grub2/i386-pc/gcry_camellia.mod
/usr/lib/grub2/i386-pc/gcry_cast5.mod
/usr/lib/grub2/i386-pc/gcry_crc.mod
/usr/lib/grub2/i386-pc/gcry_des.mod
/usr/lib/grub2/i386-pc/gcry_md4.mod
/usr/lib/grub2/i386-pc/gcry_md5.mod
/usr/lib/grub2/i386-pc/gcry_rfc2268.mod
/usr/lib/grub2/i386-pc/gcry_rijndael.mod
/usr/lib/grub2/i386-pc/gcry_rmd160.mod
/usr/lib/grub2/i386-pc/gcry_seed.mod
/usr/lib/grub2/i386-pc/gcry_serpent.mod
/usr/lib/grub2/i386-pc/gcry_sha1.mod
/usr/lib/grub2/i386-pc/gcry_sha256.mod
/usr/lib/grub2/i386-pc/gcry_sha512.mod
/usr/lib/grub2/i386-pc/gcry_tiger.mod
/usr/lib/grub2/i386-pc/gcry_twofish.mod
/usr/lib/grub2/i386-pc/gcry_whirlpool.mod
/usr/lib/grub2/i386-pc/gettext.mod
/usr/lib/grub2/i386-pc/gfxmenu.mod
/usr/lib/grub2/i386-pc/gfxterm.mod
/usr/lib/grub2/i386-pc/gptsync.mod
/usr/lib/grub2/i386-pc/gzio.mod
/usr/lib/grub2/i386-pc/halt.mod
/usr/lib/grub2/i386-pc/hashsum.mod
/usr/lib/grub2/i386-pc/hdparm.mod
/usr/lib/grub2/i386-pc/hello.mod
/usr/lib/grub2/i386-pc/help.mod
/usr/lib/grub2/i386-pc/hexdump.mod
/usr/lib/grub2/i386-pc/hfs.mod
/usr/lib/grub2/i386-pc/hfsplus.mod
/usr/lib/grub2/i386-pc/iorw.mod
/usr/lib/grub2/i386-pc/iso9660.mod
/usr/lib/grub2/i386-pc/jfs.mod
/usr/lib/grub2/i386-pc/jpeg.mod
/usr/lib/grub2/i386-pc/kernel.img
/usr/lib/grub2/i386-pc/keylayouts.mod
/usr/lib/grub2/i386-pc/keystatus.mod
/usr/lib/grub2/i386-pc/legacycfg.mod
/usr/lib/grub2/i386-pc/linux.mod
/usr/lib/grub2/i386-pc/linux16.mod
/usr/lib/grub2/i386-pc/lnxboot.img
/usr/lib/grub2/i386-pc/loadenv.mod
/usr/lib/grub2/i386-pc/loopback.mod
/usr/lib/grub2/i386-pc/ls.mod
/usr/lib/grub2/i386-pc/lsacpi.mod
/usr/lib/grub2/i386-pc/lsapm.mod
/usr/lib/grub2/i386-pc/lsmmap.mod
/usr/lib/grub2/i386-pc/lspci.mod
/usr/lib/grub2/i386-pc/lvm.mod
/usr/lib/grub2/i386-pc/mdraid09.mod
/usr/lib/grub2/i386-pc/mdraid1x.mod
/usr/lib/grub2/i386-pc/memdisk.mod
/usr/lib/grub2/i386-pc/memrw.mod
/usr/lib/grub2/i386-pc/minicmd.mod
/usr/lib/grub2/i386-pc/minix.mod
/usr/lib/grub2/i386-pc/minix2.mod
/usr/lib/grub2/i386-pc/mmap.mod
/usr/lib/grub2/i386-pc/moddep.lst
/usr/lib/grub2/i386-pc/msdospart.mod
/usr/lib/grub2/i386-pc/multiboot.mod
/usr/lib/grub2/i386-pc/multiboot2.mod
/usr/lib/grub2/i386-pc/nilfs2.mod
/usr/lib/grub2/i386-pc/normal.mod
/usr/lib/grub2/i386-pc/ntfs.mod
/usr/lib/grub2/i386-pc/ntfscomp.mod
/usr/lib/grub2/i386-pc/ntldr.mod
/usr/lib/grub2/i386-pc/ohci.mod
/usr/lib/grub2/i386-pc/part_acorn.mod
/usr/lib/grub2/i386-pc/part_amiga.mod
/usr/lib/grub2/i386-pc/part_apple.mod
/usr/lib/grub2/i386-pc/part_bsd.mod
/usr/lib/grub2/i386-pc/part_gpt.mod
/usr/lib/grub2/i386-pc/part_msdos.mod
/usr/lib/grub2/i386-pc/part_sun.mod
/usr/lib/grub2/i386-pc/part_sunpc.mod
/usr/lib/grub2/i386-pc/partmap.lst
/usr/lib/grub2/i386-pc/parttool.lst
/usr/lib/grub2/i386-pc/parttool.mod
/usr/lib/grub2/i386-pc/password.mod
/usr/lib/grub2/i386-pc/password_pbkdf2.mod
/usr/lib/grub2/i386-pc/pbkdf2.mod
/usr/lib/grub2/i386-pc/pci.mod
/usr/lib/grub2/i386-pc/play.mod
/usr/lib/grub2/i386-pc/png.mod
/usr/lib/grub2/i386-pc/probe.mod
/usr/lib/grub2/i386-pc/pxe.mod
/usr/lib/grub2/i386-pc/pxeboot.img
/usr/lib/grub2/i386-pc/pxecmd.mod
/usr/lib/grub2/i386-pc/raid.mod
/usr/lib/grub2/i386-pc/raid5rec.mod
/usr/lib/grub2/i386-pc/raid6rec.mod
/usr/lib/grub2/i386-pc/read.mod
/usr/lib/grub2/i386-pc/reboot.mod
/usr/lib/grub2/i386-pc/regexp.mod
/usr/lib/grub2/i386-pc/reiserfs.mod
/usr/lib/grub2/i386-pc/relocator.mod
/usr/lib/grub2/i386-pc/scsi.mod
/usr/lib/grub2/i386-pc/search.mod
/usr/lib/grub2/i386-pc/search_fs_file.mod
/usr/lib/grub2/i386-pc/search_fs_uuid.mod
/usr/lib/grub2/i386-pc/search_label.mod
/usr/lib/grub2/i386-pc/sendkey.mod
/usr/lib/grub2/i386-pc/serial.mod
/usr/lib/grub2/i386-pc/setjmp.mod
/usr/lib/grub2/i386-pc/setpci.mod
/usr/lib/grub2/i386-pc/sfs.mod
/usr/lib/grub2/i386-pc/sleep.mod
/usr/lib/grub2/i386-pc/tar.mod
/usr/lib/grub2/i386-pc/terminal.lst
/usr/lib/grub2/i386-pc/terminal.mod
/usr/lib/grub2/i386-pc/terminfo.mod
/usr/lib/grub2/i386-pc/test.mod
/usr/lib/grub2/i386-pc/test_blockarg.mod
/usr/lib/grub2/i386-pc/testload.mod
/usr/lib/grub2/i386-pc/tga.mod
/usr/lib/grub2/i386-pc/trig.mod
/usr/lib/grub2/i386-pc/true.mod
/usr/lib/grub2/i386-pc/udf.mod
/usr/lib/grub2/i386-pc/ufs1.mod
/usr/lib/grub2/i386-pc/ufs2.mod
/usr/lib/grub2/i386-pc/uhci.mod
/usr/lib/grub2/i386-pc/usb.mod
/usr/lib/grub2/i386-pc/usb_keyboard.mod
/usr/lib/grub2/i386-pc/usbms.mod
/usr/lib/grub2/i386-pc/usbserial_common.mod
/usr/lib/grub2/i386-pc/usbserial_ftdi.mod
/usr/lib/grub2/i386-pc/usbserial_pl2303.mod
/usr/lib/grub2/i386-pc/usbtest.mod
/usr/lib/grub2/i386-pc/vbe.mod
/usr/lib/grub2/i386-pc/vga.mod
/usr/lib/grub2/i386-pc/vga_text.mod
/usr/lib/grub2/i386-pc/video.lst
/usr/lib/grub2/i386-pc/video.mod
/usr/lib/grub2/i386-pc/video_bochs.mod
/usr/lib/grub2/i386-pc/video_cirrus.mod
/usr/lib/grub2/i386-pc/video_fb.mod
/usr/lib/grub2/i386-pc/videoinfo.mod
/usr/lib/grub2/i386-pc/videotest.mod
/usr/lib/grub2/i386-pc/xfs.mod
/usr/lib/grub2/i386-pc/xnu.mod
/usr/lib/grub2/i386-pc/xnu_uuid.mod
/usr/lib/grub2/i386-pc/xzio.mod
/usr/lib/grub2/i386-pc/zfs.mod
/usr/lib/grub2/i386-pc/zfsinfo.mod
/usr/share/doc/grub2-1.99
/usr/share/doc/grub2-1.99/COPYING
/usr/share/doc/grub2-1.99/ChangeLog
/usr/share/doc/grub2-1.99/INSTALL
/usr/share/doc/grub2-1.99/NEWS
/usr/share/doc/grub2-1.99/README
/usr/share/doc/grub2-1.99/README.Fedora
/usr/share/doc/grub2-1.99/THANKS
/usr/share/doc/grub2-1.99/TODO
/usr/share/info/grub2-dev.info.gz
/usr/share/info/grub2.info.gz
# 


All you can see, GRUB2 has lots of files. You do not need all of them for a particular system. The files that you need depend on your hardware and filesystems. The .mod files are loadable modules.

So how do you convert your boot disk from MBR to GPT and how to you convert your bootloader from GRUB Legacy to GRUB2?

Let us tackle the conversion of the boot disk from MBR to GPT first. The conversion is actually quite easy – Rod Smith’s excellent gdisk utility does it all for you. If you have not used gdisk before, you will probably have to use yum to install it. The problem is that unless you had unused blocks at the end of your boot disk, you are going to get the following message when you invoke gdisk:

# gdisk /dev/vda
GPT fdisk (gdisk) version 0.8.1

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.
THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if
you don't want to convert your MBR partitions to GPT format!
***************************************************************


Warning! Secondary partition table overlaps the last partition by
33 blocks!
You will need to delete this partition or resize it in another utility.

Command (? for help): p
Disk /dev/vda: 16777216 sectors, 8.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 2E73A3C9-A7D6-4D05-A550-60792A46A3DD
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 16777182
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1026047   500.0 MiB   8300  Linux filesystem
   2         1026048        16777215   7.5 GiB     8E00  Linux LVM

Command (? for help): q
#


The gdisk utility does not allow you to write out the new GPT label when this message is displayed. What does the warning message mean? It means that there is no space at the end of the disk to store the backup (AKA secondary) GPT. The backup GPT is located at LBA z – 33 to LBA z where LBA z is the last LBA of the boot disk. The backup GPT fields are reversed.

From Chapter 5 of the UEFI 2.3 specification:

GPT layout

Note that the gdisk utility stated that it was short 33 blocks – not sectors. Depending on your disk geometry a block may be anything from 512 bytes to 4K bytes. Typically it is 1K, i.e. 2 sectors. However some modern disks now use 4K blocks. Make sure that you know the block size of the boot disk before trying to free up space for the backup GPT!

So how do you free up the needed blocks? In our example, we know that we have to free up the last 33 blocks in /dev/vda2. However this partition has a logical volume on it and on top of the logical volume is the /dev/mapper/vg_test-lv_root filesystem.

You have to perform a number of operations in the following order to free up the needed space.

  • Use resize2fs to reduce the size of the /dev/mapper/vg_test-lv_root filesystem.
  • Use lvreduce to reduce the size of the logical volume vg_test/lv_root.
  • Use fdisk to reduce the size of partition number 2 (/dev/vda2).

There are plenty of tutorials available on the Internet which provide step-by-step guides on how to perform the above operations so I am not going to describe these steps in detail. Generally you will have to boot in rescue mode to reduce the root filesystem. If you are using a VM, you can use the virt-rescue utility to access the VM in rescue mode. Be very careful performing these operations. Any mistake can cause data loss or even cause your system to become unbootable.

Once you have freed up sufficient space for the backup GPT, you can use the gdisk utility to convert the MBR to GPT.

# gdisk /dev/vda
GPT fdisk (gdisk) version 0.8.1

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.
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): 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).
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
#


Next, you need to make space for a BIOS Boot partition. This partition is required by GRUB2. This post explains the BIOS Boot Partition in detail. The easiest space to free up is /dev/vda1 which is used by the /boot filesystem. By default it is 500Mb but most of that space is not actually used by Fedora. You only need approximately 37Kb for the BIOS Boot partition but it is easier to allocate a megabyte or two of space. One megabyte is recommended.

# umount /boot
# e2fsck -f /dev/vda1
e2fsck 1.41.14 (22-Dec-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vda1: 43/128016 files (2.3% non-contiguous), 70896/512000 blocks
# resize2fs /dev/vda1 450M
resize2fs 1.41.14 (22-Dec-2010)
Resizing the filesystem on /dev/vda1 to 460800 (1k) blocks.
The filesystem on /dev/vda1 is now 460800 blocks long.
#


Now use the gdisk utility to reduce the size of the /dev/vda1 partition, add a third partition and set its type to EF02, i.e. BIOS Boot partition, and change the type of /dev/vda1 (/boot) to EF00 (EFI System).

# gdisk /dev/vda
GPT fdisk (gdisk) version 0.8.1

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/vda: 16777216 sectors, 8.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 3F5119FF-EB9C-44AB-A707-31F9ACBFAFF3
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 16777182
Partitions will be aligned on 2048-sector boundaries
Total free space is 103093 sectors (50.3 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          925000   450.7 MiB   8300  Linux filesystem
   2         1026048        16777150   7.5 GiB     8300  Linux filesystem

Command (? for help): n
Partition number (3-128, default 3):
First sector (34-16777182, default = 925001) or {+-}size{KMGTP}:
Information: Moved requested sector from 925001 to 925696 in
order to align on 2048-sector boundaries.
Use 'l' on the experts' menu to adjust alignment
Last sector (925696-1026047, default = 1026047) or {+-}size{KMGTP}: 2M
Last sector (925696-1026047, default = 1026047) or {+-}size{KMGTP}: +2M
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): L
0700 Microsoft basic data  0c01 Microsoft reserved    2700 Windows RE
4200 Windows LDM data      4201 Windows LDM metadata  7501 IBM GPFS
7f00 ChromeOS kernel       7f01 ChromeOS root         7f02 ChromeOS reserved
8200 Linux swap            8300 Linux filesystem      8301 Linux reserved
8e00 Linux LVM             a500 FreeBSD disklabel     a501 FreeBSD boot
a502 FreeBSD swap          a503 FreeBSD UFS           a504 FreeBSD ZFS
a505 FreeBSD Vinum/RAID    a800 Apple UFS             a901 NetBSD swap
a902 NetBSD FFS            a903 NetBSD LFS            a904 NetBSD concatenated
a905 NetBSD encrypted      a906 NetBSD RAID           ab00 Apple boot
af00 Apple HFS/HFS+        af01 Apple RAID            af02 Apple RAID offline
af03 Apple label           af04 AppleTV recovery      af05 Apple Core Storage
be00 Solaris boot          bf00 Solaris root          bf01 Solaris /usr & Mac Z
bf02 Solaris swap          bf03 Solaris backup        bf04 Solaris /var
bf05 Solaris /home         bf06 Solaris alternate se  bf07 Solaris Reserved 1
bf08 Solaris Reserved 2    bf09 Solaris Reserved 3    bf0a Solaris Reserved 4
bf0b Solaris Reserved 5    c001 HP-UX data            c002 HP-UX service
ef00 EFI System            ef01 MBR partition scheme  ef02 BIOS boot partition
fd00 Linux RAID
Hex code or GUID (L to show codes, Enter = 8300): EF02
Changed type of partition to 'BIOS boot partition'


Command (? for help): p
Disk /dev/vda: 16777216 sectors, 8.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 3F5119FF-EB9C-44AB-A707-31F9ACBFAFF3
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 16777182
Partitions will be aligned on 2048-sector boundaries
Total free space is 98997 sectors (48.3 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          925000   450.7 MiB   8300  Linux filesystem
   2         1026048        16777150   7.5 GiB     8300  Linux filesystem
   3          925696          929791   2.0 MiB     EF02  BIOS boot partition

Command (? for help): t
Partition number (1-3): 1
Current type is 'EFI System'
Hex code or GUID (L to show codes, Enter = 8300): EF00
Changed type of partition to 'EFI System'

Command (? for help): p
Disk /dev/vda: 16777216 sectors, 8.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 3F5119FF-EB9C-44AB-A707-31F9ACBFAFF3
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 16777182
Partitions will be aligned on 2048-sector boundaries
Total free space is 98997 sectors (48.3 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          925000   450.7 MiB   EF00  EFI System
   2         1026048        16777150   7.5 GiB     8E00  Linux LVM
   3          925696          929791   2.0 MiB     EF02  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).
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
#


You do not create a filesystem on the BIOS Boot partition. It is just a contiguous set of blocks which GRUB2 uses to embed the core.img binary.

Now we are ready to setup GRUB2.

[root@test fpm]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub.cfg ...
cat: /boot/grub2/video.lst: No such file or directory
Found linux image: /boot/vmlinuz-3.1.0-0.rc9.git0.0.fc16.x86_64
Found initrd image: /boot/initramfs-3.1.0-0.rc9.git0.0.fc16.x86_64.img
Found linux image: /boot/vmlinuz-2.6.38.6-26.rc1.fc15.x86_64
Found initrd image: /boot/initramfs-2.6.38.6-26.rc1.fc15.x86_64.img
done

# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub.cfg ...


GRUB2 is now setup and ready for use. The required configuration file grub.cfg (equivalent to menu.lst in GRUB Legacy) was created and all the necessary files have been placed in /boot/grub2.

Here is the contents of grub.cfg:

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  load_env
fi
set default="0"
if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  load_env
fi
set default="0"
if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

        insmod part_gpt
        insmod ext2
        set root='(hd0,gpt1)'
        search --no-floppy --fs-uuid --set=root 9f6bc5ff-89af-4bf5-9e71-b4369c25518a
        echo    'Loading Linux 3.1.0-0.rc9.git0.0.fc16.x86_64 ...'
        linux   /vmlinuz-3.1.0-0.rc9.git0.0.fc16.x86_64 root=/dev/mapper/vg_test-lv_root ro quiet rhgb
        echo    'Loading initial ramdisk ...'
        initrd  /initramfs-3.1.0-0.rc9.git0.0.fc16.x86_64.img
}

menuentry 'Linux, with Linux 3.1.0-0.rc9.git0.0.fc16.x86_64 (recovery mode)' --class gnu-linux --class gnu --class os {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod ext2
        set root='(hd0,gpt1)'
        search --no-floppy --fs-uuid --set=root 9f6bc5ff-89af-4bf5-9e71-b4369c25518a
        echo    'Loading Linux 3.1.0-0.rc9.git0.0.fc16.x86_64 ...'
        linux   /vmlinuz-3.1.0-0.rc9.git0.0.fc16.x86_64 root=/dev/mapper/vg_test-lv_root ro single quiet rhgb
        echo    'Loading initial ramdisk ...'
        initrd  /initramfs-3.1.0-0.rc9.git0.0.fc16.x86_64.img
}
menuentry 'Linux, with Linux 2.6.38.6-26.rc1.fc15.x86_64' --class gnu-linux --class gnu --class os {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod ext2
        set root='(hd0,gpt1)'
        search --no-floppy --fs-uuid --set=root 9f6bc5ff-89af-4bf5-9e71-b4369c25518a
        echo    'Loading Linux 2.6.38.6-26.rc1.fc15.x86_64 ...'
        linux   /vmlinuz-2.6.38.6-26.rc1.fc15.x86_64 root=/dev/mapper/vg_test-lv_root ro quiet rhgb
        echo    'Loading initial ramdisk ...'
        initrd  /initramfs-2.6.38.6-26.rc1.fc15.x86_64.img
}
menuentry 'Linux, with Linux 2.6.38.6-26.rc1.fc15.x86_64 (recovery mode)' --class gnu-linux --class gnu --class os {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod ext2
        set root='(hd0,gpt1)'
        search --no-floppy --fs-uuid --set=root 9f6bc5ff-89af-4bf5-9e71-b4369c25518a
        echo    'Loading Linux 2.6.38.6-26.rc1.fc15.x86_64 ...'
        linux   /vmlinuz-2.6.38.6-26.rc1.fc15.x86_64 root=/dev/mapper/vg_test-lv_root ro single quiet rhgb
        echo    'Loading initial ramdisk ...'
        initrd  /initramfs-2.6.38.6-26.rc1.fc15.x86_64.img
}
### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###

### BEGIN /etc/grub.d/90_persistent ###
### END /etc/grub.d/90_persistent ###

Here is a list of the files placed in /boot/grub2:

acpi.mod                     gcry_sha512.mod     parttool.mod
affs.mod                     gcry_tiger.mod      password.mod
afs_be.mod                   gcry_twofish.mod    password_pbkdf2.mod
afs.mod                      gcry_whirlpool.mod  pbkdf2.mod
aout.mod                     gettext.mod         pci.mod
ata.mod                      gfxmenu.mod         play.mod
ata_pthru.mod                gfxterm.mod         png.mod
at_keyboard.mod              gptsync.mod         probe.mod
befs_be.mod                  grub.cfg            pxeboot.img
befs.mod                     grubenv             pxecmd.mod
biosdisk.mod                 gzio.mod            pxe.mod
bitmap.mod                   halt.mod            raid5rec.mod
bitmap_scale.mod             hashsum.mod         raid6rec.mod
blocklist.mod                hdparm.mod          raid.mod
boot.img                     hello.mod           read.mod
boot.mod                     help.mod            reboot.mod
bsd.mod                      hexdump.mod         regexp.mod
btrfs.mod                    hfs.mod             reiserfs.mod
bufio.mod                    hfsplus.mod         relocator.mod
cat.mod                      iorw.mod            scsi.mod
cdboot.img                   iso9660.mod         search_fs_file.mod
chain.mod                    jfs.mod             search_fs_uuid.mod
cmostest.mod                 jpeg.mod            search_label.mod
cmp.mod                      kernel.img          search.mod
command.lst                  keylayouts.mod      sendkey.mod
configfile.mod               keystatus.mod       serial.mod
core.img                     legacycfg.mod       setjmp.mod
cpio.mod                     linux16.mod         setpci.mod
cpuid.mod                    linux.mod           sfs.mod
crypto.lst                   lnxboot.img         sleep.mod
crypto.mod                   loadenv.mod         tar.mod
cs5536.mod                   locale              terminal.lst
datehook.mod                 loopback.mod        terminal.mod
date.mod                     lsacpi.mod          terminfo.mod
datetime.mod                 lsapm.mod           test_blockarg.mod
device.map                   lsmmap.mod          testload.mod
diskboot.img                 ls.mod              test.mod
dm_nv.mod                    lspci.mod           tga.mod
drivemap.mod                 lvm.mod             trig.mod
echo.mod                     mdraid09.mod        true.mod
efiemu32.o                   mdraid1x.mod        udf.mod
efiemu64.o                   memdisk.mod         ufs1.mod
efiemu.mod                   memrw.mod           ufs2.mod
elf.mod                      minicmd.mod         uhci.mod
example_functional_test.mod  minix2.mod          usb_keyboard.mod
ext2.mod                     minix.mod           usb.mod
extcmd.mod                   mmap.mod            usbms.mod
fat.mod                      moddep.lst          usbserial_common.mod
font.mod                     msdospart.mod       usbserial_ftdi.mod
fshelp.mod                   multiboot2.mod      usbserial_pl2303.mod
fs.lst                       multiboot.mod       usbtest.mod
functional_test.mod          nilfs2.mod          vbe.mod
gcry_arcfour.mod             normal.mod          vga.mod
gcry_blowfish.mod            ntfscomp.mod        vga_text.mod
gcry_camellia.mod            ntfs.mod            video_bochs.mod
gcry_cast5.mod               ntldr.mod           video_cirrus.mod
gcry_crc.mod                 ohci.mod            video_fb.mod
gcry_des.mod                 part_acorn.mod      videoinfo.mod
gcry_md4.mod                 part_amiga.mod      video.lst
gcry_md5.mod                 part_apple.mod      video.mod
gcry_rfc2268.mod             part_bsd.mod        videotest.mod
gcry_rijndael.mod            part_gpt.mod        xfs.mod
gcry_rmd160.mod              partmap.lst         xnu.mod
gcry_seed.mod                part_msdos.mod      xnu_uuid.mod
gcry_serpent.mod             part_sun.mod        xzio.mod
gcry_sha1.mod                part_sunpc.mod      zfsinfo.mod
gcry_sha256.mod              parttool.lst        zfs.mod


Most of these files are redundant as far as your particular system is concerned and will never be used by GRUB2. If you know what you are doing, you can remove the majority of them.

Here is what you should see when you reboot your system:

GPT layout

That is all there is to converting a MBR boot disk to GPT and upgrading from GRUB legacy to GRUB2. If you are comfortable with resizing filesystems, manipulating logical volumes, and partitioning disks, you can perform the whole operation in less than 30 minutes. Be careful and think through each operation before doing it. You can easily lose data or make your system unbootable.

Comments are closed.