LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

grub-mkimage

Build a bootable GRUB image

TLDR

Build an EFI image with the modules it needs
$ grub-mkimage -O x86_64-efi -p /boot/grub -o [path/to/grub.efi] part_gpt ext2
copy
Build a BIOS core image
$ grub-mkimage -O i386-pc -p /boot/grub -o [path/to/core.img] biosdisk part_msdos ext2
copy
Embed an early config file
$ grub-mkimage -O x86_64-efi -p /boot/grub -c [path/to/embedded.cfg] -o [path/to/grub.efi] part_gpt ext2
copy
Take modules from a directory
$ grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -o [path/to/grub.efi] part_gpt ext2
copy
Print the version
$ grub-mkimage --version
copy

SYNOPSIS

grub-mkimage [OPTION]... [MODULES]

DESCRIPTION

grub-mkimage builds a single bootable GRUB 2 image for one platform and writes it to a file or to standard output. The image contains the GRUB kernel plus the modules named on the command line, so it can start from firmware that has no separate module directory yet.grub-install calls this tool when it installs a boot loader. Run it directly to build a custom EFI binary, a PXE image, or a core image for a partition that GRUB's installer does not cover. For an image that also packs every module and extra files such as a config into a memdisk, use grub-mkstandalone.

PARAMETERS

-O, --format FORMAT

Image format. Common values are i386-pc for BIOS and x86_64-efi for 64-bit UEFI. --help lists every format this build supports.
-o, --output FILE
Write the image to FILE. The default is standard output.
-p, --prefix DIR
GRUB prefix directory stored in the image, usually /boot/grub.
-c, --config FILE
Embed FILE as the early configuration the image runs before it reads the normal config.
-d, --directory DIR
Read GRUB images and modules from DIR. The default is the platform directory under /usr/lib/grub.
-m, --memdisk FILE
Embed FILE as a memdisk. This implies a prefix inside that memdisk and overrides a prefix given earlier.
-C, --compression xz|none|auto
Compression for the core image.
-k, --pubkey FILE
Embed FILE as a public key for signature checking.
-v, --verbose
Print verbose messages.
-?, --help
Show the full option list and exit.
-V, --version
Print the version and exit.
MODULES
GRUB module names to build into the image, such as part_gpt and ext2. Names are separated by spaces.

INSTALL

sudo apt install grub-common
copy
sudo pacman -S grub
copy
sudo apk add grub
copy

CAVEATS

The format must match the firmware. An x86_64-efi image does not boot on BIOS, and an i386-pc image does not boot as a UEFI application. Modules that are not listed are unavailable until GRUB can read its prefix directory from disk. The command does not install the image into firmware; copy it to the EFI system partition or hand it to the boot setup you are building.

SEE ALSO

RESOURCES

Copied to clipboard
Kai