From Mageia wiki
Jump to: navigation, search
Drakconf multiflag.png
Other languages

Deutsch ; English ; Français ;


Presentation

Grub2-efi is installed by default when installing Mageia 5 and over in UEFI mode. This page explains how to carry out a Grub2-efi post installation configuration and/or customization. Don't follow this page if you are using Grub Legacy or Grub2 in MBR mode.

Grub2-efi structure

When installing Mageia, the installer did the following things:

  • it looked for an EFI System Partition (ESP), created it if not already existing, and mounted it in /boot/EFI,
  • it installed Grub2-efi, that means:
    • it wrote the file /boot/EFI/EFI/mageia/grubx64.efi in the ESP,
    • it wrote the configuration scripts in the /etc/grub.d folder and the configuration file /etc/default/grub,
    • it executed the scripts to create the main configuration file /boot/grub2/grub.cfg. This file is read each time Grub2-efi is executed and can be re-written with the command grub2-mkconfig ,
  • it created an entry in the non-volatile RAM on the mother board, this entry is placed first in the boot order and points to /boot/EFI/EFI/mageia/grubx64.efi.

In case of problems with the /boot/EFI/EFI/mageia/grubx64.efi file or the /boot/grub2 folder, they can be rewritten with the grub2-install --target=x86_64-efi --efi-directory=/boot/EFI --bootloader-id=mageia --recheck command. "--efi-directory" specifies the mount-point of the ESP. "--bootloader-id" specifies the folder name where grubx64.efi is copied, it is also the name of the new entry the command creates in the non-volatile RAM, you can write what you want.
Grub2-14.png
See Interacting with the UEFI firmware for more information about managing the entries in the non-volatile RAM.

The ESP

ESP (for EFI System Partition) is a small partition of about 100 to 300 MB that contains the boot loader programs for all installed operating systems. It is part of the UEFI specification and OS independant. During an UEFI installation, the Mageia installer detects it automatically (or creates it if any), it is generally /dev/sda and mounts it on /boot/EFI.
Here is the ESP on the computer used in this page:
Grub2-15.png
You can see in the ESP and more precisely in /boot/EFI/EFI there is three folders called /boot/EFI/EFI/mageia, /boot/EFI/EFI/Microsoft and /boot/EFI/EFI/ubuntu. They have been created each one by their matching installer. If Mageia had been installed a second time, it would still have only one folder called /boot/EFI/EFI/mageia for both.

Grub configuration

Principle

Each time you start your computer, grub2.efi is executed, it acts according to its configuration file called grub.cfg situated in /boot/grub2/. This file isn't intended to be modified by hand, but if you are able and want to do it, then do so. grub.cfg is written in Grub's built-in scripting language, which has a syntax quite similar to that of GNU Bash and other Bourne shell derivatives.
For the others, a tool called grub2-mkconfig can do it quite well. It uses a bunch of scripts stored in /etc/grub.d and a configuration file called /etc/default/grub. This file contains the grub2.efi menu settings that are read by the scripts and written into grub.cfg. It is the customization part of the grub2.efi. This means that if you want to change the grub2.efi menu, you will have to edit existing scripts or create new ones, then update the menu.

The configuration scripts

Let's have a look to the /etc/grub.d folder.
Grub2-1.png

  • 00_header, is the script that loads GRUB settings from /etc/default/grub, including timeout, default boot entry, and others.
  • 10_linux, loads the menu entries for the installed distribution.
  • 20_linux_xen,
  • 20_ppc_terminfo,
  • 30_os-prober, is the script that will scan the hard disks for other operating systems and add them to the boot menu.
  • 40_custom, is a template that you can use to create additional entries to be added to the boot menu.
  • 41_custom
  • 90_persistent
  • 93_memtest, loads the memtest utility.

Have you noticed the numbering in the script names? It defines precedence. This means that 10_linux will be executed before 30_os-prober and therefore placed higher in the boot menu order.
Like the /boot/grub2/grub.cfg file, they are not intended to be edited, save for 40_custom and 41_custom. You need to be very careful when working with these scripts. Scripts are meant to be executed. This means that they have the execute bit turned on. If you want to disable a script, don't delete it, turn the execute bit off and it will not run,

You can place as many files as you want into the /etc/grub.d directory, all the executable shell scripts will be read in their numbering order.

The configuration files

The main configuration file is /etc/default/grub, it is parsed by the 00_header script
Grub2-2.png

  • GRUB_DISABLE_OS_PROBER= allows or not OS_PROBER to probe all the OSes installed on the hard disks to automatically create a menu with each detected one .
  • GRUB_CMDLINE_LINUX_DEFAULT= allows to add options to the kernel.
  • GRUB_THEME= specifies the default theme.
  • GRUB_TIMEOUT= specifies the default timeout. Setting to -1 will make grub2 wait indefinitely until you manually select an entry and hit Enter.

There are many other options, see all the valid keys

You can also use another configuration file /boot/grub2/custom.cfg
Grub2-3.png

Naming convention

It differs from grub-legacy.

  • it names hard disks hd and floppies fd, and counts them from 0, hd0 for sda, hd1 for sdb, ...
  • it names partitions gpt and counts them from 1, gpt1 for the first one, gpt2 for the second, ...

example: sdb4 is named hd1,gpt4
If there is a path after the drive and partition, use the brackets, example: (hd0,gpt4)/boot/grub2

Menu modification

Menu by default

Grub2-sc1.png
Here is the menu you have by default in the case you installed Windows 10, then Ubuntu and then Mageia 5. Because it is the last installed, Mageia is at the first line and is launched by default.
The second line is a sub-menu where are the Mageia safe mode and former kernels. These two lines has been written by the 10_linux script.
The third line is for Windows
The fourth line launches Ubuntu and the fifth one is also a sub-menu where are the Ubuntu safe mode and former kernels. These three last lines has been written by the 30_os-prober script.

Deleting entries

If the 30_os-prober script is disabled, you will obtain a minimal menu with only the Mageia entries. The best way to do that is to modify the /etc/default/grub file, changing "false" by "true" in the "GRUB_DISABLE_OS_PROBER=" option Grub2-4.png
You have now to re-write the /boot/grub2/grub.cfg file using the grub2-mkconfig -o /boot/grub2/grub.cfg command.
Grub2-5.png
You get this minimal menu
Grub2-sc2.png

Notepad.png
Please note!
the update-grub command is an alias for grub2-mkconfig -o /boot/grub2/grub.cfg

Adding an entry

To add an entry, it is possible to use the 40_custom script but we will create a new script instead because this way we can choose the new entry place in the menu by changing the script place in the /etc/grub.d folder.
To write a new script to create a new entry for Ubuntu for example, we can carry out a copy/paste from the /boot/grub2/grub.cfg part written by the 30_os-prober script.

  • make sure 30_os-prober is enable in /etc/default/grub
  • generate grub.cfg with update-grub and look for the part that creates the Ubuntu entry. You will find it after the comment:### BEGIN /etc/grub.d/30_os-prober###. The first part is the Windows entry, then is the Ubuntu entry (background in blue, see the screenshot below) and then the Ubuntu sub-menu.

Grub2-6.png

  • Select the Ubuntu entry (plus the sub-menu if you want, but it is much more longer than displayed in the screenshot) and paste it in the script file called for example 50_custom, add the lines "#!/bin/sh", "cat <<EOF" and "EOF" as shown in the screenshot below, save 50_custom in the /etc/grub.d folder and make it executable.

Grub2-7.png

  • disable 30_os-prober and generate again grub.cfg
  • here is the new menu

Grub2-sc3.png

It is also possible to create an entry to shutdown and/or reboot the system. Simply create the script as shown below, call it 60_custom. You can create the both entries in the same script or create two scripts.
Grub2-9.png
Don't forget to make the scripts executable and to generate the grub.cfg file
Here is the new menu
Grub2-sc4.png

Changing the entries order

It is easy to change the entries order in the grub2 menu, you have just to change the scripts numbering in the /etc/grub.d folder. For example, if you want Ubuntu in first line, rename 50_custom by 05_custom and generate the grub.cfg file.
Grub2-sc5.png

Changing the entries titles

The script that creates an entry always begin by

menuentry 'Title' <options> {
...
...

The text between the simple quotes is free and is the title displayed in the grub2 menu. For example, for Ubuntu, the title is underlined in the screenshot below, you can change it by whatever you like, for example 'New title for Ubuntu'
Grub2-8.png
Grub2-sc6.png

Notepad.png
Please note!
You could also change the title by modifying the grub.cfg file, but doing this way, the new titles will not survive a new grub.cfg generation

Grub-customizer

Grub-customizer is a graphical tool to manage the main grub2 settings. It is present in the Mageia repositories.
On the first tab, you can recognize our menu with four entries and a sub-menu. It is possible here to modify the entries titles, to create or remove entries and to change their order.
Grub2-11.png
The second tab is obvious, except the check box "look for other operating systems", if checked the 30_os-prober script is enabled. The "advanced settings" button allows to set the options of the /etc/default file.
Grub2-12.png
The last tab deals with the resolution and themes. The "advanced settings" button is the same than above.
Grub2-13.png

For more information see https://launchpad.net/grub-customizer

Interacting with the UEFI firmware

Don't mix up the boot loader (grub2-efi in our case) installed by the operating system and the UEFI boot manager that is part of the UEFI software shipped with you mother board. Each time you install a new operating system it creates an entry in the UEFI boot manager that launch its boot loader. grub2-efi is independent of the boot manager, but in case of problem with a boot loader, you can ask the boot manager to boot another operating system, using another bootloader.

From Mageia

With the efibootmgr -v command, you can see your UEFI entries:
Grub2-16.png
BootCurrents tells which entry is the current one and and Timeout tells how long to wait before using the default entry that means the first one in BootOrder.
Boot0002 is the boot entry produced by the mageia installation, Boot0004 by the Ubuntu installation and Boot0001 by the Windows one.
Suppose you are having problems with grub2-efi that freezes before it reaches the menu. You can then try to boot the fail-safe mode and change the boot order using this command:


Konsole.png
[root@computer ~]# efibootmgr -o 4,2
[root@computer ~]# _

and the Ubuntu entry will be used first, that mean the boot loader installed with the Ubuntu installation.
For more information about the UEFI boot manager, see efibootmgr

From Windows

To set an entry to be the default one, start Windows and open a command prompt as an administrator: Menu -> All programs -> Windows system -> right click on Command Prompt -> Run as administrator
Then Click on "Yes" in the dialog box and type:

 bcdedit /set {bootmgr} path \EFI\<id>\grubx64.efi 

<id> specifies the folder name where grubx64.efi is copied, for example "mageia" or "ubuntu", see The ESP.

Links