Outils pour utilisateurs

Outils du site


issue86:grub_2_multibooting

Ceci est une ancienne révision du document !


Table des matières

1

In the first part of this mini-series, I explained the basic functionality of GRUB (version 2) and its configuration file grub.cfg. Ultimately, we want to achieve a multibooting system where changes or new installs of operating systems (OSs) don’t mess up GRUB. Your GRUB menu should offer a choice between multiple installed OSs to choose from. A prerequisite is an essential knowledge of how GRUB works. Follow me to find out! For now, let’s consider a normal installation of GRUB on the Master Boot Record (MBR) of your hard drive, which, for example, has been arranged for you when you installed Ubuntu. If you have a spare machine on which you can play with this GRUB installation, then do it! You can learn a lot from experimenting with GRUB (see also the links at the end of this article). If not, just believe the explanations below, or be more careful in your experiments – the exact nature of your experiments will determine not only how GRUB works, but also whether it still works…

Dans la première partie de cette courte série, j'ai expliqué les fonctions de base de GRUB (version 2) et de son fichier de configuration, grub.cfg. Notre objectif final est de créer un système multi-boot où des modifications ou de nouvelles installations de systèmes d'exploitation ne perturbent point GRUB. Le menu de GRUB devrait proposer un choix entre des systèmes d'exploitation multiples qui sont installés sur votre ordinateur. Un prérequis capital est une bonne connaissance du fonctionnement de GRUB. Suivez-moi pour le découvrir !

Pour le moment, nous allons examiner une installation normale de GRUB sur le Master Boot Record (MBR) de votre disque dur, qui, par exemple, a été confectionné pour vous lors de l'installation d'Ubuntu. Si vous avez une machine de rab, sur laquelle vous pouvez jouer avec cette installation de GRUB, alors faites-le ! Vous pouvez apprendre beaucoup de choses en faisant des expériences avec GRUB (voir aussi les liens à la fin de cet article). Sinon, acceptez tout simplement les explications ci-dessous ou faites plus attention lors des expériences - la nature exacte de ces expériences déterminera non seulement le fonctionnement de GRUB, mais également si GRUB est encore en état de fonctionner…

2

We already learned that GRUB runs from the MBR at hard disk boot, and that it relies on grub.cfg which is in /boot/grub/ on a partition that was specified to GRUB during its installation. Well actually, this “dependence” on grub.cfg is needed only for displaying the user-friendly menu from which you can select an OS using arrow keys and Enter. GRUB itself can thrive without grub.cfg, although it still needs to load specific modules from /boot/grub/ in order to access all of its functionality. You can access 'bare' GRUB from the GRUB menu by pressing 'c' (press Esc to return to the menu). Welcome to the GRUB command prompt! The GRUB operating system is just awaiting your commands now – and that puts you in control! This will be useful when, for any reason, the GRUB menu doesn’t load, or a GRUB menu entry does not work. An in-depth discussion of the possibilities is far beyond the scope of this article, and I refer to the internet links given at the end. I will discuss some introductory commands at the end of the article though, just to get you in play… Yes, ladies and gentlemen, mastering the command line opens a great new world of possibilities – also in GRUB!

Nous avons déjà appris que GRUB s'exécute à partir du MBR lors du démarrage du disque dur et qu'il dépend de grub.cfg qui se trouve dans /boot/grub/ sur une partition qui fut spécifiée à GRUB pendant son installation. Cependant, en fait, cette « dépendance » du fichier grub.cfg est nécessaire uniquement pour l'affichage du menu convivial à partir duquel vous pouvez sélectionner un système d'exploitation avec les touches fléchées et Entrée. GRUB lui-même se porte très bien sans grub.cfg, bien qu'il ait toujours besoin de charger des modules spécifiques à partir de /boot/grub/ afin de pouvoir accéder à toutes ses fonctionnalités. vous pouvez accéder à GRUB « tout court » en appuyant sur « c » (appuyez sur Échap pour revenir au menu). Bienvenue à l'invite de commandes GRUB ! Maintenant, le système d'exploitation GRUB attend vos commandes - et il vous laisse les contrôles ! Ce sera utile quand, pour quelque raison que ce soit, le menu GRUB ne charge pas, ou une entrée dans le menu GRUB ne fonctionne pas. Une discussion approfondie des possibilités excède, et de loin, le champ d'application de cet article et je vous renvoie à nouveau aux liens à la fin. Toutefois, je présenterai quelque commandes de base à la fin de l'article, pour que vous puissiez commencer à jouer… Oui, mesdames et messieurs, la maîtrise de la ligne de commande rend accessible un nouveau monde de possibilités - dans GRUB aussi !

3

The GRUB menu will be our focus now. Its components are controlled by the contents of /boot/grub/grub.cfg. Have a good look at grub.cfg. It is the file that GRUB reads. What is in there? Nothing but GRUB commands! The official manual on gnu.org denotes this as “GRUB's built-in scripting language”. By looking carefully, you may already understand a lot of what is stated there: several modules are loaded with insmod, for example to handle msdos-partitions, or to display png or jpeg images. Further, several so-called ‘menu entries’ (lines of the GRUB menu) are listed by their name of the OS plus kernel version, each followed by the specific instructions that GRUB needs to boot the corresponding OS. Essential instructions appear below each menu-entry in order to boot an OS: the hard drive and partition numbers where that OS resides, and the directory path and name of the kernel to be booted and of the initial ramdisk image (which is loaded first). The GRUB command to point at the Linux kernel is… linux. I’m sure at this stage you do not want to edit grub.cfg, and it is not recommended either. So have no worries: the GRUB configuration file is created for you when you type 'sudo update-grub' in a terminal. The update-grub command is delivered with the grub-pc package, which was also responsible for installing GRUB on the MBR. The update-grub command reads the contents of several files: on the one hand /etc/default/grub, which contains several personal settings, and on the other hand the executable scripts under /etc/grub.d/. We will play with the scripts next time.

Maintenant, nous allons nous concentrer sur le menu GRUB. C'est le contenu de /boot/grub/grub.cfg qui contrôle ces composants. Regardez bien grub.cfg. C'est le fichier que lit GRUB. Qu'y a-t-il dedans ? Rien que des commandes GRUB.

4

For now, let’s tweak /etc/default/grub. The first part of this file looks like the one shown on the next page, top right. • the menu entry that is selected by default when the GRUB menu shows, is determined by GRUB_DEFAULT=x. You have to fill in the number of the line, counting from… zero. Bummer. • the counter (in seconds) after which the default entry is executed if no key is pressed, is determined by GRUB_TIMEOUT (as seconds). • GRUB_HIDDEN_TIMEOUT=0 should be commented out with a hash (#) if you don't want the GRUB menu to be hidden. This may need to be changed for your first installed Linux distribution if you did not install Windows. • GRUB_CMDLINE_LINUX_DEFAULT sets the kernel parameters to be added to the linux command, for each default menu entry for Linux distros in grub.cfg. Recovery entries excluded. • adding GRUB_BACKGROUND=/path/filename determines the splash image to be displayed as a menu background. Alternatively, just putting a background image (jpeg or png) into /boot/grub should suffice to be picked up by update-grub. Change these settings as you like. Then comes the moment to update /boot/grub/grub.cfg correspondingly. First, backup your existing grub.cfg. Then run this in a terminal: sudo update-grub

5

You will see some messages during the process, which should last less than a minute. After that, have a look at grub.cfg to check if everything looks OK. Reboot and enjoy your changes! Booting with an erratic (or absent) grub.cfg, will leave you in the GRUB terminal, or – worse – in GRUB rescue mode. So it is a very good idea to be prepared for that (see the online resources). The best way to prepare for this is to run exercises in the GRUB terminal and learn to boot OSs from there. You better do that before experimenting with grub.cfg (so that you still have a working GRUB menu at your disposition). When you see the GRUB menu during booting, press ‘c’ to get at the GRUB prompt (and Esc to turn back to the menu). Now you can learn to manually run GRUB commands (instead of letting the menu do this for you). I list only a few commands here to start with: set pager=1 # to avoid longer GRUB output to roll off your screen help [command] # without argument, lists available commands; with argument, shows help of the specified command set # lists current settings ls <path> # displays contents of a directory cat <file> # displays contents of a file boot # starts the boot sequence; identical to selecting an OS in the GRUB menu with Enter. This command will work only if GRUB has been told where the OS to be booted resides: you find these essential commands under each 'menu entry' in grub.cfg, or just wait till next time!).

issue86/grub_2_multibooting.1418059270.txt.gz · Dernière modification : 2014/12/08 18:21 de auntiee