GRUB-EDTENV Command Usage (with examples)

GRUB-EDTENV Command Usage (with examples)

The grub-editenv command is a critical tool for managing GRUB environment variables on Unix-like systems. It offers a way to configure and customize the bootloader’s behavior by editing specific environment files. This is particularly useful for managing boot configurations without directly editing the GRUB configuration files, thus making the process less error-prone.

Use case 1: Set a Default Boot Entry

Code:

grub-editenv /boot/grub/grubenv set default=Ubuntu

Motivation:

Setting a default boot entry is essential when you have multiple operating systems or kernel versions and want one to boot automatically. By specifying a default entry, you ensure that the desired system or version starts without manual intervention, which is especially useful for servers or headless systems that require stability and consistent startup behavior.

Explanation:

  • grub-editenv: The main command used to edit GRUB environment variables.
  • /boot/grub/grubenv: The file path where GRUB environment variables are stored.
  • set: The action to take on the environment variable.
  • default=Ubuntu: Sets the default boot entry to “Ubuntu,” assuming an entry named “Ubuntu” exists in the GRUB configuration.

Example output:

There may not be a textual output, but a subsequent listing or boot test will confirm the change, as the default entry will be set to “Ubuntu.”

Use case 2: Display the Current Value of the timeout Variable

Code:

grub-editenv /boot/grub/grubenv list timeout

Motivation:

Understanding the timeout value is important for system administrators who need to manage how long the GRUB menu is displayed before automatically selecting the default boot entry. Knowing this value helps in configuring the system to either allow more time for manual selection or to speed up boot times.

Explanation:

  • grub-editenv: The main command used to edit GRUB environment variables.
  • /boot/grub/grubenv: The file path where GRUB environment variables are stored.
  • list: Command used to view the current value of a variable.
  • timeout: The specific variable whose value you want to display.

Example output:

timeout=5

This output shows that the current timeout is set to 5 seconds.

Use case 3: Reset the saved_entry Variable to the Default

Code:

grub-editenv /boot/grub/grubenv unset saved_entry

Motivation:

Resetting the saved_entry is useful when the boot sequence should return to using the default entry once a particular need for booting to a previously saved entry is no longer relevant. For instance, if you temporarily booted into a different system for troubleshooting, you might want to unset this to revert the behavior.

Explanation:

  • grub-editenv: The command for editing GRUB environment variables.
  • /boot/grub/grubenv: The relevant file where these environment variables are stored.
  • unset: The command action used to clear a variable.
  • saved_entry: The variable that is being reset to its default state.

Example output:

Again, this command might not produce direct output, but the effect will be that the bootloader no longer uses a specifically saved entry, reverting to the default.

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 is often done to clean up the boot process visually, removing verbose messages and providing a graphical boot splash screen. This is helpful for end-user systems where a less cluttered boot sequence is desirable.

Explanation:

  • grub-editenv: The primary command for altering GRUB environment variables.
  • /boot/grub/grubenv: The path file containing the pertinent environment variables for GRUB.
  • list: Function to display current settings.
  • kernel_cmdline: The specific command-line parameter for modifying kernel start options.

Example output:

If “quiet splash” was successfully appended earlier, this command might show:

kernel_cmdline="quiet splash"

This indicates that the required changes are reflected in the GRUB environment.

Conclusion

The grub-editenv command is a versatile tool for managing GRUB environment variables, providing options for setting default boot entries, viewing and resetting variables, and modifying kernel command-line parameters. These functions are vital for system administrators and users who need efficient boot management and customization without the risk of manually editing the primary configuration files themselves.

Related Posts

Understanding the 'lsmod' Command (with examples)

Understanding the 'lsmod' Command (with examples)

The lsmod command in Linux is a vital utility that provides information about the status of the kernel modules currently loaded in the Linux system.

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

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

The sbatch command is a utility for submitting batch jobs to the SLURM workload manager.

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

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

The gouldtoppm command is a utility found within the Netpbm package, designed to convert Gould scanner files into PPM (Portable Pixmap) image files.

Read More