LinuxCommandLibrary

grub-mkimage

Create GRUB images for booting

SYNOPSIS

grub-mkimage [OPTION...] [MODULE...] --output=FILE

PARAMETERS

-d, --directory=DIR
    use images and modules from DIR (default=/boot/grub)

-O, --format=FORMAT
    produce image for FORMAT (e.g., i386-pc, x86_64-efi)

-o, --output=FILE
    set output filename (required)

-p, --prefix=DIR
    set prefix directory [default=(prefix)/grub]

--compress[=no|xz|lz4|zstd]
    compress modules using specified algorithm

--target=TARGET
    specify target platform (e.g., i386, x86_64)

-q, --quiet
    work silently

-V, --verify
    verify the generated image

--xattr
    enable extended attributes if supported

-v, --version
    print version information

-h, -?, --help
    display help and exit

DESCRIPTION

grub-mkimage is a key utility in the GRUB 2 bootloader suite used to generate standalone boot images by embedding specified GRUB modules into a single binary file. These images, such as core.img for BIOS or EFI binaries, are crucial for GRUB's stage 1.5 or direct EFI booting, allowing the bootloader to access filesystems, load kernels, and perform other boot tasks without relying on external module files.

The command accepts a list of modules (e.g., ext2, fat, linux, part_msdos) as arguments and outputs a file in formats like i386-pc (legacy BIOS), x86_64-efi (UEFI), or others. Essential options include --output (mandatory), --format or -O for architecture, --directory to locate modules (default /boot/grub), and --prefix for GRUB's installation path.

Compression via --compress (xz, lz4, etc.) reduces size for embedded or rescue use. It's invoked automatically by grub-install but useful manually for custom minimal images supporting specific filesystems or boot modes. Verification with --verify ensures integrity. This flexibility supports diverse platforms from PCs to embedded devices.

CAVEATS

Requires --output; modules must exist in --directory. Some formats need specific hardware support. Large module sets increase image size.

EXAMPLE

grub-mkimage -O i386-pc -o core.img -d /boot/grub ext2 fat part_msdos linux

Creates BIOS core image supporting ext2/FAT, MSDOS partitions, Linux loader.

EFI EXAMPLE

grub-mkimage -O x86_64-efi -o grubx64.efi fat ext2 linux normal

HISTORY

Introduced in GRUB 2.00 (2009) by the GNU GRUB project, replacing GRUB Legacy tools like grub-mkimage from stage loading era. Evolved with UEFI support in GRUB 2.02+ and compression in later versions.

SEE ALSO

Copied to clipboard