Build GRUB2 from source

or Bootloaders, part 2

Published:

I wonder if there is a UI framework for making minimalistic and beautiful apps that work without OS, the things that we see in UEFI settings like this:

UEFI settings on GIGABYTE motherboard

Build GRUB

git clone https://git.savannah.gnu.org/git/grub.git
cd grub

./bootstrap

# EFI
./configure \
  --with-platform=efi \
  --target=x86_64 \
  --disable-werror \
  --prefix=$(pwd)/../grub-install

# BIOS
./configure \
  --with-platform=pc \
  --target=i386 \
  --disable-werror \
  --prefix=$(pwd)/../grub-install

make
make install

cd $(pwd)/../grub-install/bin

find ../lib/grub/x86_64-efi -name '*.mod' \
  | sed -e 's/..\/lib\/grub\/x86_64-efi\///g' \
  | sed -e 's/\.mod//g' \
  | sort > modules.list

./grub-mkimage \
  --format=x86_64-efi \
  --output=bootx64.efi \
  --prefix='(tftp,192.168.3.146)/grub' \
  --verbose $(<modules.list|tr '\n' ' ') > grub-mkimage.log 2>&1
# modules = efinet tftp chain

Building BIOS version you can get this error:

/usr/bin/ld: relocatable linking with relocations from format elf64-x86-64 (lib/zstd/zstd_module-debug.o) to format elf32-i386 (zstd.module) is not supported

TODO - how to fix it?

References:

Font customization

./grub-mkfont -s 24 -o Sarabun_24.pf2 Sarabun-Regular.ttf
./grub-mkfont -s 16 -o Sarabun_16.pf2 Sarabun-Regular.ttf
./grub-mkfont -s 32 -o Sarabun_32.pf2 Sarabun-Regular.ttf

edk2

Build edk2 example

sudo pacman -Syu nasm

git clone https://github.com/tianocore/edk2.git
cd edk2
git submodule update --init
source edksetup.sh BaseTools
# turn off warnings as errors: modify settings under Conf/tools_def.txt
# to remove the warnings-as-errors flag 
# ref: https://edk2-devel.narkive.com/i74qD279/edk2-how-to-turnoff-error-c2220-warning-treated-as-error-edk-ii

make -C BaseTools/Source/C
  • edit Conf/target.txt
TARGET_ARCH           = X64
TOOL_CHAIN_TAG        = GCC
  • create MyHelloWrold/MyHelloWrold.c
  • create MyHelloWrold/MyHelloWrold.inf
  • edit ShellPkg/ShellPkg.dsc
  • add into [Components]: MyHelloWorld/MyHelloWorld.inf
  • if you see BaseTools C Tool binary was not found (GenFw) you may need to run
make -C /scgames/installer/edk2/BaseTools/Source/C

gfxboot

dnsmasq configuration

UEFI bootloader

UEFI examples

UEFI GUI

mu project

Rate this page