8.77. GRUB-2.12

The GRUB package contains the GRand Unified Bootloader.

Approximate build time: 0.3 SBU
Required disk space: 166 MB

8.77.1. Installation of GRUB

[Warning]

Warning

Unset any environment variables which may affect the build:

unset {C,CPP,CXX,LD}FLAGS

Don't try tuning this package with custom compilation flags. This package is a bootloader. The low-level operations in the source code may be broken by aggressive optimization.

Create the PKGBUILD for the Grub package with the following commands:

mkdir /sources/grub
cd /sources/grub
cat > PKGBUILD << "REALEOF"
# Maintainer: Linux From Scratch <lfs-dev@lists.linuxfromscratch.org>

pkgname="grub"
pkgver="2.12"
pkgrel="1"
_ufver="16.0.01"
pkgdesc="The GRUB package contains the GRand Unified Bootloader."
arch=('x86'
      'x86_64')
url="https://www.gnu.org/software/grub/"
license=('GPLv3')
groups=('core')
depends=('bash'
         'efivars'
         'efibootmgr'
         'gcc'
         'gettext'
         'glibc'
         'xz'
         'sed'
         'rootfs')
makedepends=('binutils'
             'bison'
             'coreutils'
             'diffutils'
             'grep'
             'make'
             'ncurses'
             'texinfo')
optdepends=('freetype'
            'fuse'
            'lvm2')
backup=('etc/grub/grub.cfg')
source=('https://ftp.gnu.org/gnu/grub/grub-2.12.tar.xz'
        'https://unifoundry.com/pub/unifont/unifont-16.0.01/font-builds/unifont-16.0.01.pcf.gz')
md5sums=('60c564b1bdc39d8e43b3aab4bc0fb140'
         '007ffa7aab47ed3f270caee84d12148b')
noextract=("unifont-${_ufver}.pcf.gz")

prepare(){
  cd "${pkgname}-${pkgver}"
  # Add a file missing from the release tarball
  echo depends bli part_gpt > grub-core/extra_deps.lst
}

build(){
  cd "${pkgname}-${pkgver}"
  ./configure --prefix=/usr          \
              --sysconfdir=/etc      \
              --disable-efiemu       \
              --with-platform=efi    \
              --target=x86_64        \
              --disable-werror
  make
}

package(){
  cd "${pkgname}-${pkgver}"
  make DESTDIR="${pkgdir}" install

  # Install an empty grub.cfg
  install -vdm755 "${pkgdir}/etc/grub"
  touch "${pkgdir}/etc/grub/grub.cfg"

  # Install the Bash completion file
  install -vdm755 "${pkgdir}/usr/share/bash-completions/completions"
  mv -v "${pkgdir}/etc/bash_completion.d/grub" \
        "${pkgdir}/usr/share/bash-completion/completions"

  # If you have Freetype installed, uncomment the next two lines
  # mkdir -pv "${pkgdir}/usr/share/fonts/unifont"
  # gunzip -c "${srcdir}/unifont-${_ufver}.pcf.gz" > /usr/share/fonts/unifont/unifont.pcf
  # install -vDm755 grub-mkfont "${pkgdir}/usr/bin/"
  # install -vDm644 ascii.h widthspec.h *.pf2 "${pkgdir}/usr/share/grub/"

  # If Fuse and LVM2 are installed, install grub-mount
  # install -vDm755 grub-mount ${pkgdir}/usr/bin/
}
REALEOF

The meaning of the new configure options:

--disable-werror

This allows the build to complete with warnings introduced by more recent versions of Flex.

--disable-efiemu

This option minimizes what is built by disabling a feature and eliminating some test programs not needed for LFS.

--with-platform=efi

This option ensures building GRUB with EFI enabled.

--target=x86_64

This option ensures building GRUB for x86_64 even if building on a 32-bit LFS system. Most EFI firmware on x86_64 does not support 32-bit bootloaders.

--target=i386

A few 32-bit x86 platforms have EFI support. And, some x86_64 platforms have a 32-bit EFI implementation, but they are very old and rare. Use this instead of --target=x86_64 if you are absolutely sure that LFS is running on such a system.

Prepare the build directory for the pacman user and build the package:

chown -R root:pacman .
chmod 2775 .
chmod 664 PKGBUILD
su pacman -c 'makepkg -L --nodeps'

Add the newly created package to the central package repository:

cp grub-2.12-1-$(uname -m).pkg.tar.xz \
   /srv/pacman/repos/LFS/
repo-add /srv/pacman/repos/LFS/LFS.db.tar.xz \
         /srv/pacman/repos/LFS/grub-2.12-1-$(uname -m).pkg.tar.xz

Update the local cache and install the Grub package:

pacman -Syu
pacman -S grub --overwrite \* -dd --noconfirm

Finally, copy the source files into the source repository and clean up the build directory:

mkdir /srv/pacman/source/LFS/grub
cp PKGBUILD /srv/pacman/source/LFS/grub
cd /sources
rm -rf grub

Making your LFS system bootable with GRUB will be discussed in Section 10.4, “Using GRUB to Set Up the Boot Process.”

8.77.2. Contents of GRUB

Installed programs: grub-bios-setup, grub-editenv, grub-file, grub-fstest, grub-glue-efi, grub-install, grub-kbdcomp, grub-macbless, grub-menulst2cfg, grub-mkconfig, grub-mkfont, grub-mkimage, grub-mklayout, grub-mknetdir, grub-mkpasswd-pbkdf2, grub-mkrelpath, grub-mkrescue, grub-mkstandalone, grub-mount grub-ofpathname, grub-probe, grub-reboot, grub-render-label, grub-script-check, grub-set-default, grub-sparc64-setup, and grub-syslinux2cfg
Installed directories: /usr/lib/grub, /usr/lib/grub/x86_64-efi, /etc/grub.d, /usr/share/grub, and /boot/grub

Short Descriptions

grub-bios-setup

Is a helper program for grub-install

grub-editenv

Is a tool to edit the environment block

grub-file

Checks to see if the given file is of the specified type

grub-fstest

Is a tool to debug the file system driver

grub-glue-efi

Glues 32-bit and 64-bit binaries into a single file (for Apple machines)

grub-install

Installs GRUB on your drive

grub-kbdcomp

Is a script that converts an xkb layout into one recognized by GRUB

grub-macbless

Is the Mac-style bless for HFS or HFS+ file systems (bless is peculiar to Apple machines; it makes a device bootable)

grub-menulst2cfg

Converts a GRUB Legacy menu.lst into a grub.cfg for use with GRUB 2

grub-mkconfig

Generates a grub.cfg file

grub-mkfont

Converts common font file formats into PF2

grub-mkimage

Makes a bootable image of GRUB

grub-mklayout

Generates a GRUB keyboard layout file

grub-mknetdir

Prepares a GRUB netboot directory

grub-mkpasswd-pbkdf2

Generates an encrypted PBKDF2 password for use in the boot menu

grub-mkrelpath

Makes a system pathname relative to its root

grub-mkrescue

Makes a bootable image of GRUB suitable for a floppy disk, CDROM/DVD, or a USB drive

grub-mkstandalone

Generates a standalone image

grub-mount

A debug tool for filesystem drivers

grub-ofpathname

Is a helper program that prints the path to a GRUB device

grub-probe

Probes device information for a given path or device

grub-reboot

Sets the default boot entry for GRUB for the next boot only

grub-render-label

Renders Apple .disk_label for Apple Macs

grub-script-check

Checks the GRUB configuration script for syntax errors

grub-set-default

Sets the default boot entry for GRUB

grub-sparc64-setup

Is a helper program for grub-setup

grub-syslinux2cfg

Transforms a syslinux config file into grub.cfg format