LinuxCommandLibrary

grub-mkimage

Create GRUB images for booting

SYNOPSIS

grub-mkimage [OPTION...] [MODULE...]

PARAMETERS

-o, --output=FILE
    Output to FILE. This option is required.

-d, --directory=DIR
    Use images and modules under DIR. Defaults to /boot/grub or the directory the grub-mkimage binary resides.

-c, --config=FILE
    Embed configuration file FILE. Note that it must contain only complete menu entries which are not used anymore.

-f, --format=FORMAT
    Use FORMAT for output image.

-m, --memdisk=FILE
    Embed FILE as a memdisk.

--cmdline=STRING
    Set command line to STRING. Used for passing parameters to the linux kernel.

-p, --prefix=DIR
    Set GRUB prefix to DIR.

-O, --target=TARGET
    Set target platform to TARGET.

--compress=COMPRESS
    Compress the image using COMPRESS algorithm (xz, gzip, lzo). By default it uses no compression.

--product-version
    Print the GRUB version string.

--verbose
    Print verbose messages.

-n, --no-dependencies
    Do not add module dependencies automatically.

--help
    Display this help message and exit.

--version
    Print version information and exit.

DESCRIPTION

grub-mkimage is a powerful tool used to generate bootable disk images for the GRand Unified Bootloader (GRUB). It allows users to create custom bootloaders with specific modules and configurations. The primary function is to embed essential GRUB modules into a single image file, which can then be written to a boot sector or used to boot from various media like USB drives or hard disks. This tool gives flexibility in building minimal boot images containing only the necessary modules to boot a system or provide a rescue environment. grub-mkimage is a critical component in setting up custom GRUB environments. Often, it's used in conjunction with `grub.cfg` to define the boot menu entries and configurations to be loaded during the boot process. It offers a granular level of control over the boot environment.
The output file can be used to boot operating systems or as part of a system rescue disk. Modules can be preloaded to avoid the need to read them from a file system.

CAVEATS

The correct set of modules must be specified for the target system. Incorrect modules can cause boot failures.

MODULE SELECTION

Choosing the right modules is crucial. Common modules include 'normal', 'linux', 'initrd', 'ext2', 'fat', etc. The 'normal' module is required to load the normal GRUB interface. 'linux' and 'initrd' are used to load the kernel and initrd respectively. Filesystem modules such as 'ext2' or 'fat' are needed to access the kernel and initrd files on the filesystem.

EXAMPLE USAGE

A typical example might involve creating a boot image for a USB drive:
grub-mkimage -o boot.img -O i386-pc -p '(hd0,1)/boot/grub' normal linux ext2 ntfs iso9660 fat part_msdos
This command creates an image named 'boot.img' for the i386-pc platform, setting the prefix to '(hd0,1)/boot/grub' and including the specified modules.

SEE ALSO

Copied to clipboard