grub-script-check
Check GRUB configuration script syntax
TLDR
Check a specific script file for syntax errors
Display each line of input after reading it
Display help
Display version
SYNOPSIS
grub-script-check [OPTIONS] FILE
PARAMETERS
FILE
The path to the GRUB script file to be checked for syntax errors. This parameter is mandatory.
-h, --help
Displays a help message with usage information and then exits.
-v, --version
Prints the version information of the grub-script-check utility and then exits.
DESCRIPTION
The grub-script-check command is a vital utility within the GRUB2 bootloader suite, specifically designed to parse and validate GRUB configuration scripts. Its primary function is to inspect a given GRUB script file (commonly grub.cfg or custom configuration snippets) for syntax errors, malformed commands, and adherence to the GRUB scripting language rules. This tool is exceptionally useful for debugging GRUB configuration issues before attempting a reboot, thereby mitigating the risk of an unbootable system due to a faulty bootloader configuration. When executed, grub-script-check will report any detected errors, often pinpointing the exact line number where the issue lies, which significantly aids administrators in identifying and correcting mistakes in their GRUB setup. It acts as a static analysis tool for your GRUB boot configuration.
CAVEATS
While grub-script-check is excellent for syntax validation, it does not perform a logical or runtime check. A script can be syntactically perfect but still cause issues at boot time if the logic is flawed or if it refers to non-existent devices/paths. It also doesn't simulate the full boot environment, so some issues related to specific modules or hardware detection might not be caught. Always test critical GRUB changes in a virtual machine or a non-production environment first.
USAGE IN AUTOMATION
The command returns an exit status of 0 if no syntax errors are found, and a non-zero value if errors are detected. This makes it ideal for use in automated scripts and continuous integration pipelines to validate GRUB configuration files before deployment or system updates.
Example: grub-script-check /boot/grub/grub.cfg && echo 'GRUB config is OK' || echo 'GRUB config has errors!'
ERROR REPORTING
When errors are found, grub-script-check typically outputs diagnostic messages to standard error (stderr), indicating the file name, line number, and a description of the syntax error, which is extremely helpful for pinpointing and fixing issues.
HISTORY
The grub-script-check command emerged as an essential component with the development of GRUB2. Unlike its predecessor, GRUB Legacy, GRUB2 introduced a significantly more powerful and intricate scripting language for its configuration (grub.cfg). This complexity necessitated a dedicated tool for validating script syntax. Its inclusion reflects the GRUB2 project's commitment to providing robust and manageable bootloader configurations, allowing system administrators to debug configuration files proactively rather than reactively during a critical boot sequence.
SEE ALSO
grub-mkconfig(8), grub-install(8), grub(8), update-grub(8), grub-reboot(8)