How to use the command 'grub-editenv' (with examples)
- Linux
- December 25, 2023
The ‘grub-editenv’ command is used to edit GRUB (Grand Unified Bootloader) environment variables. GRUB is a boot loader that allows users to select which operating system to boot when starting their computer. The environment variables controlled by ‘grub-editenv’ can be used to customize the GRUB boot process. In this article, we will explore four examples of using the ‘grub-editenv’ command.
Use case 1: Set a default boot entry
Code:
grub-editenv /boot/grub/grubenv set default=Ubuntu
Motivation: Setting a default boot entry can be useful if you want to automatically boot into a specific operating system without having to manually select it each time you start your computer. In this example, we are setting the default boot entry to ‘Ubuntu’.
Explanation:
- ‘grub-editenv’ is the command to edit GRUB environment variables.
- ‘/boot/grub/grubenv’ is the path to the GRUB environment file.
- ‘set’ is the action we want to perform on the environment variable.
- ‘default=Ubuntu’ is the value we want to set for the ‘default’ variable.
Example output: No output is displayed when the command is successful. If there is an error, an appropriate error message will be shown.
Use case 2: Display the current value of the ’timeout’ variable
Code:
grub-editenv /boot/grub/grubenv list timeout
Motivation: Checking the current value of the ’timeout’ variable can be helpful to determine how long GRUB waits before automatically booting into the default operating system.
Explanation:
- ‘grub-editenv’ is the command to edit GRUB environment variables.
- ‘/boot/grub/grubenv’ is the path to the GRUB environment file.
- ’list’ is the action we want to perform to display the value of the variable.
- ’timeout’ is the name of the environment variable we want to display.
Example output: timeout=5
Use case 3: Reset the ‘saved_entry’ variable to the default
Code:
grub-editenv /boot/grub/grubenv unset saved_entry
Motivation: The ‘saved_entry’ variable is used to remember the last selected boot entry. By resetting it to the default, we can ensure that the default operating system is always booted.
Explanation:
- ‘grub-editenv’ is the command to edit GRUB environment variables.
- ‘/boot/grub/grubenv’ is the path to the GRUB environment file.
- ‘unset’ is the action we want to perform to remove the value of the variable.
- ‘saved_entry’ is the name of the environment variable we want to unset.
Example output: No output is displayed when the command is successful. If there is an error, an appropriate error message will be shown.
Use case 4: Append “quiet splash” to the kernel command line
Code:
grub-editenv /boot/grub/grubenv list kernel_cmdline
Motivation: Appending “quiet splash” to the kernel command line can hide the boot messages and show only the splash screen during the boot process. This can be useful to create a cleaner and more streamlined boot experience.
Explanation:
- ‘grub-editenv’ is the command to edit GRUB environment variables.
- ‘/boot/grub/grubenv’ is the path to the GRUB environment file.
- ’list’ is the action we want to perform to display the value of the variable.
- ‘kernel_cmdline’ is the name of the environment variable we want to display.
Example output:
kernel_cmdline=“root=UUID=
Conclusion:
In this article, we have explored four examples of using the ‘grub-editenv’ command. These examples demonstrate how to set a default boot entry, display the current value of an environment variable, reset a variable to the default, and append text to the kernel command line. By understanding the usage of this command, users can have more control over the GRUB boot process and customize it to their needs.