grub-mkconfig

system managementLinux
The grub-mkconfig command is one of the most frequently used commands in Linux/Unix-like operating systems. grub-mkconfig Generate a GRUB configuration file

Quick Reference

Command Name:

grub-mkconfig

Category:

system management

Platform:

Linux

Basic Usage:

grub-mkconfig [options] [arguments]

Common Use Cases

    Syntax

    grub-mkconfig [options]

    Options

    Option Description
    -o, --output=FILE Output generated config to FILE [default=stdout]
    -h, --help Display help information and exit
    -v, --version Output version information and exit

    Environment Variable Description
    GRUB_DEFAULT Default menu entry (name, index, or 'saved')
    GRUB_TIMEOUT Time to wait before booting default entry
    GRUB_CMDLINE_LINUX Command-line arguments for Linux kernel
    GRUB_DISABLE_OS_PROBER Disable os-prober for detecting other OSes
    GRUB_DISABLE_RECOVERY Disable generation of recovery mode menu entries
    GRUB_DISTRIBUTOR Distributor name for menu entries

    Examples

    How to Use These Examples

    The examples below show common ways to use the grub-mkconfig command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    grub-mkconfig -o /boot/grub/grub.cfg
    Generate a GRUB configuration file and write it to /boot/grub/grub.cfg.
    # Advanced Examples Advanced
    sudo grub-mkconfig -o /boot/grub/grub.cfg
    Generate GRUB configuration with root privileges (recommended).
    GRUB_DISABLE_OS_PROBER=true grub-mkconfig -o /boot/grub/grub.cfg Generate configuration without running os-prober. grub-mkconfig | less Generate configuration and view it without writing to a file. grub-mkconfig -o /mnt/boot/grub/grub.cfg Generate configuration for a system mounted at /mnt (e.g., during recovery).

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The grub-mkconfig command generates a configuration file for GRUB (GRand Unified Bootloader), which controls the boot menu and boot process on most Linux systems. This command creates a grub.cfg file that defines available operating systems, kernel options, and boot parameters. Key features of grub-mkconfig: 1. Automatic OS Detection: Using scripts in /etc/grub.d/, grub-mkconfig automatically detects installed operating systems (including non-Linux systems) and creates menu entries for them. 2. Kernel Discovery: It finds available Linux kernels and creates menu entries with appropriate parameters for each kernel version. 3. Configuration Customization: The command reads settings from /etc/default/grub and other configuration files to customize boot behavior, such as timeout, default entry, and kernel parameters. 4. Recovery Options: By default, it creates recovery mode entries for each kernel, providing failsafe boot options for troubleshooting. 5. Script-Based Architecture: The configuration generation is modular, with numbered scripts in /etc/grub.d/ controlling different aspects of the configuration. Users can add custom scripts to this directory to extend functionality. 6. Environment Variable Control: Many aspects of the generated configuration can be controlled through environment variables, both persistent (in configuration files) and temporary (for one-time generation). 7. Distribution Integration: Most Linux distributions provide a wrapper script (often called update-grub) that calls grub-mkconfig with appropriate parameters. Common use cases include updating the boot menu after installing new kernels, changing boot parameters, adding custom boot entries, and restoring boot functionality after system changes. It's essential to run this command with root privileges, as it affects critical system boot functionality.

    Related Commands

    These commands are frequently used alongside grub-mkconfig or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the grub-mkconfig command works in different scenarios.

    $ grub-mkconfig
    View All Commands