LinuxCommandLibrary

grub-script-check

Check GRUB configuration script syntax

TLDR

Check a specific script file for syntax errors

$ grub-script-check [path/to/grub_config_file]
copy

Display each line of input after reading it
$ grub-script-check [[-v|--verbose]]
copy

Display help
$ grub-script-check --help
copy

Display version
$ grub-script-check --version
copy

SYNOPSIS

grub-script-check [OPTION...] [FILE...]

PARAMETERS

-h, --help
    Print a short usage message and exit

-V, --version
    Print version information and exit

-v, --verbose
    Print more verbose messages

DESCRIPTION

The grub-script-check command is a utility from the GRUB 2 bootloader package designed to validate the syntax of GRUB configuration scripts. These scripts, often in files like /boot/grub/grub.cfg or custom themes, use GRUB's domain-specific scripting language to define boot menus, kernel parameters, and boot-time actions.

It parses input files (or stdin) without executing them, reporting syntax errors such as mismatched quotes, invalid commands, or malformed expressions. This prevents boot failures from configuration mistakes during updates via grub-mkconfig or manual edits.

Ideal for sysadmins and users customizing GRUB, it outputs errors to stderr with line numbers in verbose mode. Successful checks exit with code 0; errors trigger non-zero exits. Widely used in distribution grub-update hooks for safe config generation.

Limited to syntax only—no semantic checks (e.g., valid devices) or runtime simulation. Supports multiple files sequentially.

CAVEATS

Performs only syntactic validation, not semantic or logical checks.
Does not simulate execution or verify runtime dependencies like files/devices.
Errors printed to stderr; stdin used if no FILEs provided.

EXIT STATUS

0: No syntax errors found
1: Syntax error(s) detected
2: Command-line usage error

EXAMPLE

grub-script-check /boot/grub/grub.cfg
Validates the primary GRUB config file.

grub-script-check -v < custom-script
Checks stdin input verbosely.

HISTORY

Introduced in GRUB 2.00 (2012) alongside advanced scripting features. Enhanced in later GRUB 2.x releases for better error reporting and parser robustness. Integral to modern distros like Ubuntu, Fedora for config validation.

SEE ALSO

grub-mkconfig(8), grub.cfg(5), grub-editenv(1), update-grub(8)

Copied to clipboard