Booting CentOS from UEFI

Basic Input Output System (BIOS) is firmware that sits between hardware and software. BIOS initializes all hardware components like CPU, RAM, graphics cards, peripherals etc. it then performs Power On Self Test (POST) to ensure everything is working correctly. It then looks for bootable device and hands over control to the OS. Thus, BIOS has been playing a crucial role in booting a device for a long time.

However, BIOS technology is outdated. Its interface is text based blue screen as shown here:

It can boot hard drives that are 2.1 TB or less which is because it uses Master Boot Record (MBR). MBR stores the partitioning information on a drive. The organization of the partition table in the MBR limits the maximum addressable storage space of a partitioned disk. MBR also only supports up to four primary partitions.

Motivation

To overcome these limitations Unified Extensible Firmware Interface (UEFI) came up.

Advantages of UEFI

  • It can work with drives of size millions of petabytes as it uses GUID Partition Table (GPT) rather than MBR. The practical limits are dependent on the operating system and its file systems
  • It allows large number of partitions typically dependent on your operating system
  • It stores partitioning and boot data in multiple copies across the disk making it more robust and recoverable in case of data corruption
  • GPT also stores cyclic redundancy check (CRC) values to check that its data is intact. If the data is corrupted, GPT can notice the problem and attempt to recover the damaged data from another location on the disk
  • It can support graphical interface unlike BIOS text based blue screen
  • Supports secure boot and can check malware during boot
  • Supports networking features within the firmware and remote troubleshooting and configuration

Migration Steps

Following are the steps required to boot CentOS from UEFI.

Preparing EFI Bootloader

The EFI system partition needs to be formatted with a file system whose specification is based on the FAT file system and maintained as part of the UEFI specification. The EFI bootloader contains .efi file.

  • efiboot.img has file structure /EFI/BOOT/
  • Steps to create custom efiboot.img
    • #dd if=/dev/zero bs=1024 count=1440 of=efiboot-new.img        <– create a .img
    • #mkfs.vfat -n “BOOT_EFI” efiboot-new.img                                        <– format it with FAT file system
    • #mkdir new
    • #mount -t vfat -o loop efiboot-new.img new
    • #mkdir new/EFI
    • #mkdir new/EFI/BOOT/
  • Copy the configuration (like grub configuration) and efi file
  • #cp BOOTX64.efi new/EFI/BOOT/                                                            <– Prerequisite we need .efi file
  • #umount new
  • #mv efiboot-new.img efiboot.img
Working with bootloaders

EFI with GRUB

For centos 6 distribution we can get the BOOTX64.efi file

http://mirror.centos.org/centos/6/os/x86_64/EFI/BOOT/

Command to generate bootx64.efi

grub-mkimage -o bootx64.efi -p /efi/boot -O x86_64-efi \

fat iso9660 part_gpt part_msdos \

normal boot linux configfile loopback chain keylayouts \

efifwsetup efi_gop efi_uga jpeg png \

ls search search_label search_fs_uuid search_fs_file \

gfxterm gfxterm_background gfxterm_menu test all_video loadenv \

exfat ext2 ntfs udf password password_pbkdf2 pbkdf2 linuxefi

EFI with syslinux bootloader

The last update on syslinux community was on 2014-10-06 : Syslinux 6.03 released. The syslinux bootloader have efi support.

https://wiki.syslinux.org/wiki/index.php?title=The_Syslinux_Project

https://wiki.syslinux.org/wiki/index.php?title=Install#UEFI

Configuration for syslinux EFI bootloader

https://docs.slackware.com/howtos:slackware_admin:set_up_syslinux_as_boot_loader_on_uefi_based_hardware

Add efiboot.img bootloader to iso

The command ‘genisoimage’ have option -e to add the efibased bootloader

Example:

  • genisoimage  -V “CentOS 7 x86_64”  -A “CentOS 7 x86_64”  -o mytest.iso -joliet-long -b isolinux/isolinux.bin  -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e isolinux/efiboot.img  -R -J -v -T live
  • The ‘mkisofs’ command
  • mkisofs -U -r -v -T -J -joliet-long -V “RHEL-7.1 Server.x86_64” -volset “RHEL-7.1 Server.x86_64” -A “RHEL-7.1 Server.x86_64” -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e images/efiboot.img -no-emul-boot -o ../hpbs.iso .

Make BIOS and EFI hybrid boot iso

Add efiboot as second boot image in mkisofs or genisoimage -eltorito-alt-boot -e images/efiboot.img -no-emul-boot

https://fedoraproject.org/wiki/User:Pjones/BootableCDsForBIOSAndUEFI

Example:

  • genisoimage  -V “CentOS 7 x86_64”  -A “CentOS 7 x86_64”  -o mytest.iso -joliet-long -b isolinux/isolinux.bin  -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e isolinux/efiboot.img  -R -J -v -T live

Add utility for GPT partition

gdisk – interactive utility

sgdisk – scriptable version of gdisk

Example

  • sgdisk –clear \
  • –new 1::+1M –typecode=1:ef02 –change-name=1:’BIOS boot partition’ \
  • –new 2::+100M –typecode=2:ef00 –change-name=2:’EFI System’ \
  • –new 3::-0 –typecode=3:8300 –change-name=3:’Linux root filesystem’ \
Sameer Mahajan | GS Lab
Author
Sameer Mahajan | Principal Architect

Sameer Mahajan has 25 years of experience in the software industry. He has worked for companies like Microsoft and Symantec across areas like machine learning, storage, cloud, big data, networking and analytics in the United States & India.

Sameer holds 9 US patents and is an alumnus of IIT Bombay and Georgia Tech. He not only conducts hands-on workshops and seminars but also participates in panel discussions in upcoming technologies like machine learning and big data. Sameer is one of the mentors for the Machine Learning Foundations course at Coursera.

Read more blogs from Sameer