How to use the command 'grub-mkconfig' (with examples)

How to use the command 'grub-mkconfig' (with examples)

The ‘grub-mkconfig’ command is used to generate a GRUB configuration file. GRUB (Grand Unified Bootloader) is a boot loader that allows users to choose between different operating systems or kernels on a computer. The configuration file generated by ‘grub-mkconfig’ contains information about the available boot options and how to load them.

Use case 1: Do a dry run and print the configuration to stdout

Code:

sudo grub-mkconfig

Motivation: Doing a dry run and printing the configuration to stdout allows you to preview the changes that would be made to the configuration file without actually modifying it. This can be useful to verify that the generated configuration is correct before applying it.

Explanation:

  • sudo: Runs the command with administrative privileges.
  • grub-mkconfig: The command to generate the GRUB configuration file.

Example output:

Generating grub configuration file ...
Found background: /usr/share/desktop-base/login-background.svg
Found background image: /usr/share/desktop-base/login-background.svg
...

Use case 2: Generate the configuration file

Code:

sudo grub-mkconfig --output=/boot/grub/grub.cfg

Motivation: Generating the configuration file is the primary use case of the ‘grub-mkconfig’ command. The configuration file is necessary for GRUB to function properly and correctly display the available boot options.

Explanation:

  • sudo: Runs the command with administrative privileges.
  • grub-mkconfig: The command to generate the GRUB configuration file.
  • --output=/boot/grub/grub.cfg: Specifies the location and name of the output file. In this case, the configuration file will be generated at /boot/grub/grub.cfg.

Example output:

Generating grub configuration file ...
Found background: /usr/share/desktop-base/login-background.svg
Found background image: /usr/share/desktop-base/login-background.svg
...
Configuration file written successfully.

Use case 3: Print the help page

Code:

grub-mkconfig --help

Motivation: Printing the help page is useful when you need information about the available options and how to use the ‘grub-mkconfig’ command.

Explanation:

  • grub-mkconfig: The command to generate the GRUB configuration file.
  • --help: Displays the help page, which provides information about the command’s usage and available options.

Example output:

Usage: grub-mkconfig [OPTION]...
Generate a GRUB configuration file.

  -o, --output=FILE          write output to FILE instead of stdout
  -v, --version              print version information and exit
  -?, --help                 print this message and exit

For a complete list of options, see the info documentation.

Conclusion:

The ‘grub-mkconfig’ command is a powerful tool for generating a GRUB configuration file. It allows you to preview the configuration changes, generate the actual configuration file, and access the help page for more information. By understanding and effectively using this command, you can customize and manage the boot options of your computer with ease.

Related Posts

How to use the command 'wps' (with examples)

How to use the command 'wps' (with examples)

The wps command assists AirPort in connecting to a network using Wireless Protected Setup.

Read More
How to use the command 'gh browse' (with examples)

How to use the command 'gh browse' (with examples)

The gh browse command allows you to open GitHub repositories and their various pages in a web browser or print the destination URL.

Read More
Managing Docker Services: A Guide (with examples)

Managing Docker Services: A Guide (with examples)

Docker services provide a powerful way to manage and scale applications in a containerized environment.

Read More