LinuxCommandLibrary

grub-mkrelpath

Create relative paths suitable for GRUB

SYNOPSIS

grub-mkrelpath [-s | -h | -V] from-path to-path

PARAMETERS

-s, --short-root
    use shortest notation for root filesystem or devices

-h, --help
    display help message and exit

-V, --version
    print version information and exit

DESCRIPTION

grub-mkrelpath is a utility in the GRUB 2 bootloader suite that computes a relative path from a source directory (from-path) to a target directory (to-path). It is essential for creating portable GRUB scripts and configuration files, where absolute paths can fail due to varying root filesystems, boot devices, or multi-boot setups.

The tool traverses the directory hierarchy, using .. to go up and subdirectory names to go down, producing the shortest possible relative path. For instance, grub-mkrelpath /boot/grub /etc/fstab might output ../../../etc/fstab. The -s option optimizes further by preferring compact root notations like (hd0) when GRUB device syntax applies.

Commonly invoked by grub-mkconfig during bootloader updates, it ensures configs adapt to the current boot environment. Paths must be valid and accessible; invalid inputs lead to errors. This makes GRUB deployments robust across Linux distributions and hardware changes.

CAVEATS

Fails (exit 1) if paths are invalid or relative path cannot be computed; assumes directory paths; no support for symlinks or non-standard filesystems.

EXIT STATUS

0: success
1: failure to compute path

EXAMPLE

grub-mkrelpath /boot /
Outputs: ..
grub-mkrelpath -s /boot/grub /(root)
Optimizes to shortest GRUB notation.

HISTORY

Introduced in GRUB 2.00 (2012) as part of GRUB2 utilities; evolved in later versions (e.g., 2.02+) for better device shorthand and portability.

SEE ALSO

Copied to clipboard