From Fedora Project Wiki
(début de traduction)
 
(Traduciton initiale de la section «Créer une entrée dans le menu de démarrage »)
Line 73: Line 73:
TL;DR : cela doit se produire automatiquement. Si ce n'est pas le cas, continuez à lire.
TL;DR : cela doit se produire automatiquement. Si ce n'est pas le cas, continuez à lire.


Lors de la mise sous tension de votre système, le micrologiciel recherche des variables EFI qui lui indiquent comment démarrer. Si vous êtes sur un système qui a démarré en mode EFI et que les services EFI fonctionnent correctement, vous pouvez configurer votre ordre de démarrage avec <code>efibootmgr</code>. Sinon, vous allez devoir amorcer le processus.


When you power on your system, your firmware will look for EFI variables that tell it how to boot.  If you're already booted in EFI mode and EFI runtime services are working correctly, you can configure your boot menu with <code>efibootmgr</code>. If not, you'll have to bootstrap the process.
Heureusement, <code>shim</code> peut vous aider à amorcer. L'exécutable EFI <code>/boot/efi/EFI/BOOT/fallback.efi</code> va rechercher des fichiers <code>BOOT.CSV</code> dans votre ESP et va ajouter des entrées  leur correspondant, '''si de telles entréés ne semblent pas déjà exister'''. <code>shim</code> fournit un fichier <code>BOOT.CSV</code> qui ajoute pour vous une entrée pour<code>grub2-efi</code>. Ainsi la seule invocation de <code>fallback.efi</code> dans le shell EFI devrait suffire. Vous pouvez faire cela avec des commandes telles que :
 
Fortunately, <code>shim</code> can help you bootstrap.  The EFI program <code>/boot/efi/EFI/BOOT/fallback.efi</code> will look for files called <code>BOOT.CSV</code> in your ESP and will add boot entries corresponding to them, '''if such entries do not already appear to exist'''. <code>shim</code> provides a <code>BOOT.CSV</code> file that will add an entry for <code>grub2-efi</code> for youSo just using the EFI Shell to invoke <code>fallback.efi</code> should do the trick. You can do this with commands like:


<pre>
<pre>
Line 84: Line 83:
</pre>
</pre>


If you have no boot entries at all, then just booting off your disk in UEFI mode should automatically invoke <code>/boot/efi/EFI/BOOT/BOOTX64.EFI</code>, which will, in turn, invoke <code>fallback.efi</code>.
SI vous n'avez aucune entrée dans le menu de démarrage, le simple fait de démarrer votre disque en mode UEFI devrait invoquer automatiquement <code>/boot/efi/EFI/BOOT/BOOTX64.EFI</code>, qui à son tour devrait invoquer <code>fallback.efi</code>.


If you already have incorrect boot entries, you'll either need to delete them or to modify <code>BOOT.CSV</code> to create new entries with different names.
Si vous avez déjà des entrées incorrectes dans le menu de démarrage, vous devriez soit les supprimer, soit modifier <code>BOOT.CSV</code> pour créer de nouvelles entrées avec des noms différents.


== Adding Other operating systems to the GRUB 2 menu ==
== Adding Other operating systems to the GRUB 2 menu ==

Revision as of 07:16, 8 March 2018

Introduction

GRUB 2 est la dernière version de GNU GRUB, the GRand Unified Bootloader — Grand chargeur de démarrage unifié. Un chargeur de démarrage est le premier programme qui s'exécute au démarrage d'un ordinateur. Il est responsable du chargement et du transfert de contrôle au noyau du système d'exploitation, (Linux, dans le cas de Fedora). Le noyau peut alors initialiser le reste du système d'exploitation.

GRUB2 a remplacé l'ancien GRUB (version 0.9x) que l'on appelle désormais GRUB Legacy.

À partir de Fedora 16, GRUB2 est devenu le chargeur de démarrage par défaut sur les systèmes x86 BIOS. Pour des mises à jour de tels systèmes, la procédure par défaut est d'installer GRUB2, mais vous pouvez décider de sauter complètement la configuration du chargeur de démarrage.

Tâches /Problèmes courants

Mise à jour de la configuration GRUB2 sur les systèmes BIOS

Le paquet grub2 contient les commandes pour installer le chargeur de démarrage ou pour créer un fichier de configuration.

grub2-install installe le chargeur de démarrage — ordinairement dans le MBR, dans le vide entre le MBR et la première partition, et sous forme de fichiers dans le dossier /boot. Son installation se fait à l'aide d'une commande qui ressemble à :

grub2-install /dev/sda

grub2-mkconfig crée une nouvelle configuration prenant en compte le système en cours d'exécution, ce qui est présent dans /boot, ce que l'on a défini dans /etc/default/grub, et les scripts personnalisables du dossier /etc/grub.d/. Un nouveau fichier de configuration est créé par la commande suivante :

grub2-mkconfig -o /boot/grub2/grub.cfg

Le format de configuration a évolué au fil du temps, et une nouvelle configuration peut être légèrement incompatible avec l'ancien chargeur de démarrage. Par conséquent, c'est en général une bonne idée que d'exécuter grub2-install avant d'exécuter grub2-mkconfig.

L'installateur de Fedora, anaconda, exécute ces commandes de GRUB2 et il n'y a ordinairement aucune raison des les exécuter à la main.

On peut généralement modifier sans risque le fichier /boot/grub2/grub.cfg dans Fedora. Grubby dans Fedora répare la configuration lors d'une mise à jour du noyau et n'essaye pas de faire d'autres modifications que celles qui sont nécessaires (d'autres distributions, en particulier Debian et ses dérivées, fournissent un correctif logiciel qui ajoute une commande update-grub qui n'est ni incluse, ni nécessaire dans Fedora). Des changements faits à la main peuvent néanmoins être écrasés par grub2-mkconfig à la prochaine mise à jour du système par anaconda. Certains personnalisations peuvent être placées dans /etc/grub.d/40_custom ou /boot/grub2/custom.cfg, ce qui les met à l'abri des effets de grub2-mkconfig.

Mise à jour de la configuration de GRUB2 sur des systèmes UEFI

Pour installer ou réparer GRUB 2 sur un système UEFI à partir de Fedora 18, vous devez faire quatre choses :

Créer une partition ESP

Le micrologiciel UEFI est prévu pour démarrer des exécutables qu'il trouve dans une partion EFI System (ESP) sur un disque doté d'une table de partition GPT. Dans gdisk, cela ressemble à ceci :

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          264191   128.0 MiB   EF00  EFI System

Cette partition doit être au format FAT. Dans le doute, FAT32 est une bonne version de FAT à adopter.

Fedora s'attend à ce que cette partition soit montée sur /boot/efi.

Installer les fichiers du chargeur de démarrage

Si les paquets concernés ne sont pas encore installés, installez-les  avec :

dnf install grub2-efi shim

ensuite exécutez :

dnf reinstall grub2-efi shim

Assurez-vous que la partition ESP est montée sur /boot/efi avant de faire cela.

Cela installe le shim signé et le binaire GRUB2.

Créer une configuration GRUB 2

Sous EFI, GRUB2 recherche son fichier sa configuration dans /boot/efi/EFI/fedora/grub.cfg. Pour que les noyaux récemment installés fonctionne, grubby s'attend à ce que /etc/grub2-efi.cfg soit un lien symbolique vers la configuration réelle (c.-à-d. /boot/efi/EFI/fedora/grub.cfg).

Si vous disposez déjà d'un fichier de configuration GRUB2 EFI, ça devrait aller. Sinon, grub2-mkconfig peut vous aider, mais le degré de difficulté peut varier.

   grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
Stop (medium size).png
grub2-install ne doit pas être utilisé sur les systèmes EFI. Le paquet grub2-efi installe un exécutable grubx64.efi pré-compilé sur la partition ESP. Cet exécutable recherche un fichier de configuration grub.cfg dans le dossier /boot/efi/EFI/fedora/ alors que la commande grub2-install crée un exécutable grubx64.efi personnalisé, efface l'original installé, et recherche un fichier de configuration grub.cfg dans /boot/grub2.

Créer une entrée dans le menu de démarrage

TL;DR : cela doit se produire automatiquement. Si ce n'est pas le cas, continuez à lire.

Lors de la mise sous tension de votre système, le micrologiciel recherche des variables EFI qui lui indiquent comment démarrer. Si vous êtes sur un système qui a démarré en mode EFI et que les services EFI fonctionnent correctement, vous pouvez configurer votre ordre de démarrage avec efibootmgr. Sinon, vous allez devoir amorcer le processus.

Heureusement, shim peut vous aider à amorcer. L'exécutable EFI /boot/efi/EFI/BOOT/fallback.efi va rechercher des fichiers BOOT.CSV dans votre ESP et va ajouter des entrées leur correspondant, si de telles entréés ne semblent pas déjà exister. shim fournit un fichier BOOT.CSV qui ajoute pour vous une entrée pourgrub2-efi. Ainsi la seule invocation de fallback.efi dans le shell EFI devrait suffire. Vous pouvez faire cela avec des commandes telles que :

> fs0:
> cd EFI\BOOT
> fallback.efi

SI vous n'avez aucune entrée dans le menu de démarrage, le simple fait de démarrer votre disque en mode UEFI devrait invoquer automatiquement /boot/efi/EFI/BOOT/BOOTX64.EFI, qui à son tour devrait invoquer fallback.efi.

Si vous avez déjà des entrées incorrectes dans le menu de démarrage, vous devriez soit les supprimer, soit modifier BOOT.CSV pour créer de nouvelles entrées avec des noms différents.

Adding Other operating systems to the GRUB 2 menu

grub2-mkconfig will add entries for other operating systems it can find. That will be done based on the output of the os-prober tool.

That might however not work so well, especially not for booting other Linux operating systems, and especially not on UEFI systems. See http://www.gnu.org/software/grub/manual/grub.html#Multi_002dboot-manual-config .

Setting default entry

Warning.png
Please look to (default) kernel sysconfig options.
if file /etc/sysconfig/kernel have
UPDATEDEFAULT=yes
in every kernel update the grub entry is update to last entry, if you don't want that please set:
UPDATEDEFAULT=no
(write "no" in lower case)
Warning.png
Some parts of this section is wrong or outdated for F17 and later releases.
Be also aware of [Bug 768106 - grubby does not support grub2 set default="${saved_entry}" and replaces with "0"]. version grubby-8.28-1.fc19 has fixed issues with "Default Menuentry" as noted in the linked bug-report

Due to grub2-mkconfig (and os-prober) we cannot predict the order of the entries in /boot/grub2/grub.cfg, so we set the default by name/title instead.

Open /etc/default/grub and ensure this line exists:

GRUB_DEFAULT=saved

and ensure this line not exists:

GRUB_SAVEDEFAULT=true

or ensure this line exists:

GRUB_SAVEDEFAULT=false
Note.png
Note
If GRUB_SAVEDEFAULT is set to true, then, when an entry is selected, save it as a new default entry for use by future runs of GRUB. So, maybe, you need be sure that GRUB_SAVEDEFAULT is not set to true. GRUB_SAVEDEFAULT is only useful if GRUB_DEFAULT is saved.

Apply the change to grub.cfg by running:

grub2-mkconfig -o /boot/grub2/grub.cfg

Now list all possible menu entries

grep -P "submenu|^menuentry" /boot/grub2/grub.cfg | cut -d "'" -f2

Now set the desired default menu entry

grub2-set-default "<submenu title><menu entry title>"

Verify the default menu entry

grub2-editenv list
Note.png
Note
The above method fails to work on some F20 (and newer) systems due to a missing or improperly linked /boot/grub2/grubenv file. The /boot/grub2/grubenv is symbolic linked to /boot/efi/EFI/fedora/grubenv but /boot is not mounted at the time of booting. So grub2 does not have access to the environment variables. To fix this, change /boot/grub2/grubenv to point to ../efi/EFI/fedora/grubenv instead and your chosen default OS will boot without any problems.
Note.png
Note
There are other, simpler, ways of setting the default entry, but they are prone to error if/when grub2-mkconfig is re-run. These include directly setting the default in /boot/grub2/grub.cfg or setting GRUB_DEFAULT to either a number or an entry title in /etc/default/grub. Neither of these methods is recommended.

If you understand the risks involved and still want to directly modify /boot/grub2/grub.cfg, here's how you can do it:

Edit /boot/grub2/grub.cfg, and change the line

Stop (medium size).png
This is not the recommended method
This will not survive grub2-mkconfig. It might not even survive a kernel update.
set default="0" 

to

set default="5"

Encountering the dreaded GRUB 2 boot prompt

Idea.png
XFS and LVM Note
Since recent versions of Fedora and even RHEL/CentOS have started using xfs and lvm by default, it's worth noting that these steps outlined here may need to be preceded with the necessary step to load the XFS and/or LVM module(s).


If improperly configured, GRUB 2 may fail to load and subsequently drop to a boot prompt. To address this issue, proceed as follows:

0. Load the XFS and LVM modules

insmod xfs
insmod lvm

1. List the drives which GRUB 2 sees:

grub2> ls

2. The output for a dos partition table /dev/sda with three partitons will look something like this:

(hd0) (hd0,msdos3) (hd0,msdos2) (hd0,msdos1)

3. While the output for a gpt partition table /dev/sda with four partitions will look something like this:

(hd0) (hd0,gpt4) (hd0,gpt3)  (hd0,gpt2) (hd0,gpt1)

4. With this information you can now probe each partition of the drive and locate your vmlinuz and initramfs files:

ls (hd0,1)/ 

Will list the files on /dev/sda1. If this partition contains /boot, the output will show the full name of vmlinuz and initramfs.

5. Armed with the location and full name of vmlinuz and initramfs you can now boot your system.

5a. Declare your root partition:

grub> set root=(hd0,3)

5b. Declare the kernel you wish to use:

grub> linux (hd0,1)/vmlinuz-3.0.0-1.fc16.i686 root=/dev/sda3 rhgb quiet selinux=0 
# NOTE : add other kernel args if you have need of them
# NOTE : change the numbers to match your system

5c. Declare the initrd to use:

  
grub> initrd (hd0,1)/initramfs-3.0.0-1.fc16.i686.img
# NOTE : change the numbers to match your system

5d. Instruct GRUB 2 to boot the chosen files:

grub> boot

6. After boot, open a terminal.

7. Issue the grub2-mkconfig command to re-create the grub.cfg file grub2 needed to boot your system:

grub2-mkconfig -o /boot/grub2/grub.cfg

8. Issue the grub2-install command to install grub2 to your hard drive and make use of your config:

grub2-install --boot-directory=/boot /dev/sda
# Note: your drive may have another device name. Check for it with mount command output.

Additional Scenario

It's also possible to boot into a configfile that's located on another partition. If the user is faced with such a scenario, as is often the case with multi-boot systems containing Ubuntu and Fedora, the following steps in the grub rescue shell might become useful to know:

insmod part_msdos
insmod xfs
insmod lvm
set root='hd0,msdos1'
configfile /grub2/grub.cfg

Where, hd0,msdos1 is the pertinent boot partition, which holds the grub.cfg file.

Other GRUB 2 issues

Absent Floppy Disk : It has been reported by some users that GRUB 2 may fail to install on a partition's boot sector if the computer floppy controller is activated in BIOS without an actual floppy disk drive being present. A possible workaround is to run (post OS install) from rescue mode:

grub2-install <target device> --no-floppy

Setting a password for interactive edit mode

If you wish to password-protect GRUB2's interactive edit mode but you do not want to require users to enter a password to do a plain, simple, ordinary boot, create /etc/grub.d/01_users with the following lines:

cat << EOF
set superusers="root"
export superusers
password root secret
EOF

To apply your changes run:

grub2-mkconfig -o /boot/grub2/grub.cfg

You can encrypt the password by using pbkdf2. Use grub2-mkpasswd-pbkdf2 to encrypt the password, then replace the password line with:

password_pbkdf2 root grub.pbkdf2.sha512.10000.1B4BD9B60DE889A4C50AA9458C4044CBE129C9607B6231783F7E4E7191D8254C0732F4255178E2677BBE27D03186E44815EEFBAD82737D81C87F5D24313DDDE7.E9AEB53A46A16F30735E2558100D8340049A719474AEEE7E3F44C9C5201E2CA82221DCF2A12C39112A701292BF4AA071EB13E5EC8C8C84CC4B1A83304EA10F74

More details can be found at Ubuntu Help: GRUB2 Passwords.

Starting from atleast Fedora 21, the --md5pass kickstart option must be set using output from grub2-mkpasswd-pbkdf2.

Using old graphics modes in bootloader

Terminal device is chosen with GRUB_TERMINAL; additional quote from http://www.gnu.org/software/grub/manual/grub.html#Simple-configuration

Valid terminal output names depend on the platform, but may include ‘console’ (PC BIOS and EFI consoles), ‘serial’ (serial terminal), ‘gfxterm’ (graphics-mode output), ‘ofconsole’ (Open Firmware console), or ‘vga_text’ (VGA text output, mainly useful with Coreboot).

The default is to use the platform's native terminal output.

The default in Fedora is gfxterm and to get the legacy graphics modes you need to set GRUB_TERMINAL to right variable from the description above in /etc/default/grub

Enable Serial Console in Grub

To enable Serial console in grub add the following entry's to /etc/default/grub

( Adjust baudrate/parity/bits/flow control to fit your environment and cables)

GRUB_CMDLINE_LINUX='console=tty0 console=ttyS0,115200n8'
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"

And re-generate grub

grub2-mkconfig -o /boot/grub2/grub.cfg

Further Reading