Outils pour utilisateurs

Outils du site


issue99:labo_linux

Table des matières

1

One of the things I’ve always loved about Linux is the fact you can customize the heck out of it without buying third-party add-ons. The first interface hack that put a big smile on my face was when I hacked my Mythbox (MythTV) so the LILO boot loader displayed a Simpsons TV show background and the OS choice text on top - it was one of those moments that reminded me of the awesome ANSI BBS art days. I got all excited about customizing LILO (LInux LOader) further, and then along came GRUB (GRand Unified Bootloader). When GRUB first came out, I found myself scratching my head wondering why fix something that seemed way better than the solution? I’m sure more than a few of us have questioned several choices made in the open source movement, but those choices are what make the movement so great. GRUB has evolved and the cool factor is definitely back. For reference, I’m actually referring to GRUB2, the version included on most recent *buntu distributions. Specifically, I’ll be using GRUB version 2.02~beta2-22ubuntu1 on Lubuntu 14.04. To see what version of GRUB2 you’re running type: grub-install -V or grub-install –version If Ubuntu is your only OS installed, GRUB2 will not display the GRUB menu, it will just load Ubuntu. To display the GRUB menu, hold down SHIFT before Ubuntu starts to boot. A default GRUB2 menu is very plain-looking with Ubuntu, Advanced options for loading Ubuntu and a couple of Memory Test (memtest86+) options. If you’ve never tested your RAM before, or are having some glitchy OS issues, this is a great tool for testing RAM.

Une des choses que j'ai toujours aimées dans Linux, c'est le fait de pouvoir le personnaliser sans acheter des ajouts de sociétés tierces. Le premier piratage d'interface qui m'a mis un grand sourire aux lèvres était quand j'ai craqué ma Mythbox (MythTV) de façon à ce que l'amorceur de démarrage Lilo affiche un fond d'écran tiré de l'émission des Simpsons, avec le texte du choix des OS par-dessus ; c'est un de ces moments qui me rappellent le temps fantastique de l'art graphique ANSI BBS (https://fr.wikipedia.org/wiki/Art_ANSI).

J'étais tout excité à l'idée de personnaliser encore plus Lilo (LInux LOader, chargeur Linux), puis vint Grub (GRand Unified Bootloader, chargeur d'amorçage unifié). Au moment où Grub est sorti, j'étais en train de me creuser la tête en me demandant pourquoi corriger quelque chose qui semblait meilleur que le correctif ? Je suis sûr que plusieurs d'entre vous se sont interrogés devant plusieurs choix faits dans le mouvement Open Source, mais ce sont ces choix qui rendent le mouvement si génial.

Grub a évolué et le facteur cool est de retour. Je me réfère en fait à GRUB2, la version qui est comprise dans les distrib. les plus récentes d'*buntu. Spécifiquement, j'utiliserai la version GRUB 2.02~beta2-22ubuntu1 dans Lubuntu 14.04. Pour voir quelle version de GRUB2 vous avez, tapez :

grub-install -V ou grub-install –version

Si Ubuntu est le seul OS installé, GRUB2 n'affichera pas le menu GRUB ; il chargera directement Ubuntu. Pour afficher le menu GRUB, maintenez la touche MAJ enfoncée avant qu'Ubuntu commence son démarrage. Un menu GRUB2 par défaut est en texte brut, avec Ubuntu, des options avancées pour charger Ubuntu et une paire d'options de tests mémoire ((memtest86+). Si vous n'avez jamais testé votre RAM avant, ou si vous avez quelques problèmes techniques avec votre OS, c'est un excellent outil pour tester la RAM.

2

If you press e while the reverse video is over an option, you can edit that option. Just pressing e and modifying GRUB boot options saves the edit only for the current boot - but this is still useful. Editing how Ubuntu boots can be a lifesaver, I learned this the hard way when I installed Ubuntu server on a 1U server and a 24” LCD. When I went to boot the server on a 17” LCD it just kept going out of range. Holding down SHIFT to display the GRUB menu then ‘e’ editing the options you can set the gfxmode option to 800×600: # gfxmode $linux_gfx_mode gfxmode 800×600 Once the system booted I was able to edit the /etc/default/grub file and include: GRUB_GRFXMODE=”800×600” GRUB won’t update until you run: update-grub. After running update-grub, the change should be permanent. Just pressing e and modifying GRUB boot options saves the edit only for the current session.

Si vous appuyez sur e alors qu'une option est surlignée, vous pouvez modifier cette option. Si vous appuyez sur e et modifiez les options de lancement de GRUB, elles ne seront sauvegardées que pour ce lancement, mais c'est quand même utile. Savoir modifier la façon de lancer Ubuntu peut vous sauver la vie ; je l'ai appris à la dure quand j'ai installé un serveur dans un rack 1U avec un écran LCD 24“. Quand j'ai voulu démarrer le serveur avec un écran LCD 17”, l'affichage était hors du cadre. En appuyant sur MAJ pour afficher le menu, puis « e » pour passer en modification des options, vous pouvez régler l'option gfxmode sur 800 x 600 :

# gfxmode $linux_gfx_mode

gfxmode 800×600

Une fois le système lancé, j'ai été capable d'éditer le fichier /etc/default/grub et d'ajouter :

GRUB_GRFXMODE=”800×600”

Pour que GRUB se mette à jour il faut lancer : update-grub. Après avoir exécuté update-grub, la modification devient permanente. Appuyer simplement sur e et modifier les options de lancement de GRUB ne sauve la modification que pour la session courante.

3

The /etc/default/grub file is where you make all your GRUB2 changes, including adding a background image. To keep from infringing on copyright in FCM, I’ve chosen a picture I took from the back of a television we were trying to troubleshoot. Busy pictures tend not to be great backgrounds so I’ve blurred the photo a bit. I called the photo circuit.png, and saved it as a PNG image. You can save photographs as JPEG, but if you do, you’re limited to 8-bit and 256 colors. Saving in PNG enables the full range of 24/32bit color. To use the circuit.png photo I modified /etc/default/grub to include: GRUB_BACKGROUND=”/home/charles/Pictures/circuit.png” I had to run update-grub to make the change. When I ran update-grub, there was a message about GRUB_TIMEOUT=10 being incompatible when GRUB_HIDDEN_TIMEOUT=0 was set, so I also commented out: #GRUB_HIDDEN_TIMEOUT=0 Then I reran update-grub and rebooted. Sure enough the GRUB2 menu came up without pressing SHIFT (for 10 seconds), and my cool circuit image was in the background, but because of the light text it looked washed out. The black Ubuntu text on the grey bar doesn’t look bad, but I think we can do much better. But before we address the look of my theme, I want to touch on another annoyance, the blank screen before the Ubuntu splash screen. Those of you with really fast machines may not notice, but if you’re working with a slower machine, it can be a few seconds before there’s any sign of Ubuntu actually loading - to the unknowing eye it can look like Ubuntu just crashed to a blank screen. I’ve always liked seeing what’s actually loading. Long ago all the Linux distributions displayed what was loading during boot, but in the interest of not scaring away people from Linux, many distributions opted to blank the screen until their fancy splash screen loaded. To get Ubuntu to display what’s loading during the boot process, remove the word ‘quiet’ from the line that reads GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash” in the /etc/default/grub file – and don’t forget to update-grub.

Vous faites toutes les modifications de GRUB dans le fichier /etc/default/grub, y compris pour l'ajout d'une image de fond d'écran. Pour ne pas enfreindre les lois du copyright dans le FCM, j'ai choisi une image que j'ai prise de l'arrière d'un téléviseur que nous essayions de réparer. Comme les images trop chargées ne font pas des super fonds d'écran, je l'ai floutée un peu. J'ai appelé la photo circuit.png et je l'ai sauvée comme image PNG. Vous pouvez sauvegarder vos photos comme des JPG, mais si vous le faites, vous serez limité à 8 bits et 256 couleurs. La sauvegarde en PNG permet une étendue complète des couleurs en 24/32-bit. Pour utiliser la photo circuit.png, j'ai modifié /etc/default/grub pour inclure :

GRUB_BACKGROUND=”/home/charles/Pictures/circuit.png”

J'ai lancé update-grub pour que la modification soit prise en compte. Quand j'ai lancé update-grub, j'ai eu un message disant que GRUB_TIMEOUT=10 était incompatible avec GRUB_HIDDEN_TIMEOUT=0 activé ; aussi, j'ai mis en commentaire :

#GRUB_HIDDEN_TIMEOUT=0

Puis j'ai relancé update-grub et redémarré. Comme de bien entendu, le menu GRUB2 s'est affiché sans que j'appuie sur MAJ (pendant 10 secondes), et ma super image de circuit s'est affichée, mais, à cause du texte clair, cela paraissait délavé.

Le texte Ubuntu en noir sur fond gris ne semble pas mal, mais je pense que je peux faire beaucoup mieux. Cependant, avant d'examiner l'aspect de mon thème, je veux faire état d'un autre ennui, l'écran noir avant l'écran d'accueil d'Ubuntu. Ceux d'entre vous qui ont des machines rapides ne s'en aperçoivent pas, mais, si vous travaillez avec une machine plus lente, il peut se passer quelques secondes avant d'avoir une indication qu'Ubuntu est bel et bien lancé - pour un œil non exercé, l'écran noir peut ressembler à un plantage d'Ubuntu. J'ai toujours aimé voir ce qui est en cours de chargement. Il y a longtemps, toutes les distributions Linux affichaient ce qui se chargeait pendant le démarrage, mais, dans le but de ne pas effrayer les gens et les éloigner de Linux, beaucoup de distributions ont choisi de garder l'écran vierge jusqu'à ce que leur image raffinée d'accueil s'affiche. Pour qu'Ubuntu affiche se qui se charge pendant le processus de démarrage, enlevez le mot « quiet » de la ligne GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash” dans le fichier /etc/default/grub, et n'oubliez pas l'« update-grub ».

4

Now back to addressing our GRUB2 theme problem. The grey text doesn’t show very well on light colors. When I first set out to change the light text, my research led me to believe it would be a pretty easy task to accomplish by simply creating a theme file and making some font color adjustments to my theme file. Several hours later (in fact a whole other day working several hours into the night), I still didn’t have the results I wanted. Fonts I created using the grub-mkfont tool were not showing correctly, everything was spaced badly, and the complimentary colors I chose (complementary to green) were not looking so hot. A little more digging and I figured out how to just adjust the menu text, in the file /etc/grub.d/05_debian_theme. You have to find the text: if [ -z “${2}” ] && [ -z “${3}” ]; then echo “ true” fi I comment out echo “ true” and added: echo “ set color_highlight=white/light-blue” echo “ set color_normal=blue/black” Unfortunately, you’re limited to 16 colors. The article that finally helped me change only the menu colour was on The Geek Stuff: http://www.thegeekstuff.com/2012/10/grub-splash-image/ The resulting Grub menu ended up looking like the screenshot shown below.

Maintenant, revenons traiter notre problème du thème de GRUB2. Le texte en gris est peu visible sur des couleurs claires. La première fois que j'ai décidé de changer le texte clair, ma recherche m'a fait croire que ce serait une tache assez facile : la création d'un fichier de thème, puis la modification de la couleur de la police dans mon fichier de thème. Plusieurs heures plus tard (en fait, le lendemain en travaillant plusieurs heures tard dans la nuit), je n'avais toujours pas le résultat désiré. Les polices que je créais en utilisant l'outil grub-mkfont n'apparaissaient pas correctement, les espacements étaient mauvais, et les couleurs complémentaires que j'avais choisies (complémentaires au vert) n'étaient pas jolies du tout. Encore un peu de recherche et j'ai trouvé comment ajuster simplement le texte du menu, dans le fichier /etc/grub.d/05_debian_theme. Il faut trouver le texte :

if [ -z “${2}” ] && [ -z “${3}” ]; then

      echo "  true"

fi

J'ai commenté echo “ true” et j'ai rajouté :

echo “ set color_highlight=white/light-blue”

echo “ set color_normal=blue/black”

Malheureusement, vous êtes limité à 16 couleurs. L'article qui m'a finalement aidé à ne changer que la couleur du menu était sur The Geek Stuff : http://www.thegeekstuff.com/2012/10/grub-splash-image/

Le menu Grub résultant ressemblait à la capture d'écran ci-dessous.

5

Because 05_debian_theme is a GRUB2 script, I had to run update-grub for the results to take effect. The result wasn’t much better than the original theme because of the limited color choice and the busy background (plain color background works much better). I mentioned a theme file earlier. It turned out that creating a theme was a lot more complicated than it first looked, and that it was more about graphic elements than text elements. Before we create the theme we’ll set up a directory to hold our theme: cd /boot/grub sudo mkdir -p themes/circuit sudo touch themes/circuit/themes.txt

Parce que 05_debian_theme est un script GRUB2, j'ai dû lancer update-grub pour que les résultats soient pris en compte. Le résultat n'était pas vraiment meilleur que l'original à cause du choix limité de couleurs et du fond d'écran chargé (c'est beaucoup mieux avec un fond d'écran uni).

J'ai mentionné un fichier de thème un peu plus tôt. Il se trouve que créer un fichier thème est beaucoup plus compliqué qu'il n'y paraît, et qu'il y a plus à faire avec les éléments graphiques qu'avec les éléments de texte.

Avant de créer un fichier de thème, nous allons préparer un répertoire pour contenir notre thème :

cd /boot/grub

sudo mkdir -p themes/circuit

sudo touch themes/circuit/themes.txt

6

The -p switch for mkdir creates the parent directory if it doesn’t exist. On the test machine I was working on, there was no themes directory. The mkdir -p themes/circuit command created both the themes and circuit sub-directory all in one shot. The touch command created a blank file called themes.txt in /boot/grub/themes/circuit. Now we have to tell GRUB2 to load the themes file, we do this in /etc/default/grub by adding: GRUB_THEME=”/boot/grub/themes/circuit/theme.txt” Here’s what I added to my theme.txt file: title-font: “Ubuntu Bold 18” title-color: “EE00BB” desktop-image: “/home/charles/Pictures/circuit.jpg” +boot_menu { left = 10% top = 15% width = 85% height = 75% item_font = “Ubuntu Regular 12” item_color = “#631C53” selected_item_color = “#EAA6DB” }

Le commutateur -p de mkdir crée le répertoire parent s'il n'existe pas. Sur la machine de test que j'ai utilisée, il n'y avait pas de répertoire themes. La commande mkdir -p themes/circuit crée les deux sous-répertoires thèmes et circuit d'un seul coup. La commande touch crée un fichier vierge appelé themes.txt dans /boot/grub/themes/circuit. Maintenant, nous devons dire à GRUB2 de charger le fichier themes ; nous le faisons dans /etc/default/grub en ajoutant :

GRUB_THEME=”/boot/grub/themes/circuit/theme.txt”

Voici ce que j'ai ajouté à mon fichier theme.txt :

title-font: “Ubuntu Bold 18”

title-color: “EE00BB”

desktop-image: “/home/charles/Pictures/circuit.jpg”

+boot_menu {

left = 10%

top = 15%

width = 85%

height = 75%

item_font = “Ubuntu Regular 12”

item_color = “#631C53”

selected_item_color = “#EAA6DB”

}

7

The first line title-font: “Ubuntu Bold 18” defines the font to use for the GRUB2 title element. Unfortunately, defining which font to use in the menu is not as simple as picking a font Ubuntu can normally display; fonts have to be converted to .pf2 format and placed either in your theme folder or the provided /boot/grub/fonts folder, then symbolically linked to your theme folder (the recommended way to do it since you can reuse the font). Notice from the example above that I use Ubuntu Bold 18 (Ubuntu-B.ttf) and Ubuntu Regular 12 (Ubuntu-R.ttf). To create the .pf2 files, I first located the fonts responsible for Ubuntu Bold and Ubuntu Regular in /usr/share/fonts (they’re actually in /usr/share/fonts/truetype/ubuntu-font-family, but you’ll want to know about /usr/share/fonts so you can convert other font families). Then I copied the two files to my theme directory. cd /usr/share/fonts/truetype/ubuntu-font/family sudo cp Ubuntu-B.ttf Ubuntu-R.ttf /boot/grub/themes/circuit Then I ran the grub-mkfont tool with the following options: sudo grub-mkfont –verbose –range=0x0-0x7F –size=18 –output=/boot/grub/themes/circuit/Ubuntu-Bold-18.pf2 Ubuntu-B.ttf sudo grub-mkfont –verbose –range=0x0-0x7F –size=12 –output=/boot/grub/themes/circuit/Ubuntu-Regular-18.pf2 Ubuntu-R.ttf

À la première ligne, title-font: “Ubuntu Bold 18” définit la police à utiliser pour l'élément de titre de GRUB2. Malheureusement, définir la police à utiliser dans le menu n'est pas aussi simple que de choisir une police qu'Ubuntu peut normalement afficher ; les polices doivent être converties dans le format .pf2 et mises soit dans votre dossier de thème, soit dans le dossier existant /boot/grub/fonts, en les reliant ensuite symboliquement à votre dossier de thème (cette solution est recommandée car vous pourrez réutiliser ces polices). Notez dans l'exemple ci-dessus que j'utilise Ubuntu Bold 18 (Ubuntu-B.ttf) et Ubuntu Regular 12 (Ubuntu-R.ttf). Pour créer les fichiers .pf2, je commence par placer les polices en charge d'Ubuntu Bold et Ubuntu Regular dans /usr/share/fonts (elles sont réellement dans /usr/share/fonts/truetype/ubuntu-font-family, mais vous voudrez connaître /usr/share/fonts, de façon à pouvoir convertir d'autres familles de polices). Puis, j'ai copié les deux fichiers dans le répertoire de thème.

cd /usr/share/fonts/truetype/ubuntu-font/family

sudo cp Ubuntu-B.ttf Ubuntu-R.ttf /boot/grub/themes/circuit

Puis j'ai lancé l'outil grub-mkfont avec les options suivantes :

sudo grub-mkfont –verbose –range=0x0-0x7F –size=18 –output=/boot/grub/themes/circuit/Ubuntu-Bold-18.pf2 Ubuntu-B.ttf

sudo grub-mkfont –verbose –range=0x0-0x7F –size=12 –output=/boot/grub/themes/circuit/Ubuntu-Regular-18.pf2 Ubuntu-R.ttf

8

This created the font files in my theme directory in the preferred format. However, when I rebooted, I discovered the font files were not appearing as they should. I scoured Google some more – but no luck. I was about to give up, but then found the problem, the fonts were not showing because the GRUB_GFXMODE was set in /etc/default/grub to 640×480. Once I set this higher, and ran update-grub, the fonts took effect. You can specify a resolution and a fallback resolution like so: GRUB_GFXMODE=1024x768x32,640×480 With this adjustment (don’t forget to update-grub), GRUB2 changes to 1024×768 with 32-bit colors. If 1024×768 is unavailable, it goes back to the standard 640×480. Now the fonts displayed as they should. See image below. Again the menu doesn’t look great, but at least now the Ubuntu fonts worked. I mentioned earlier that there was a lot more to theming than changing the font size and style and the background image. There are several good resources that cover GRUB2 theming. If you’re comfortable with MVC and image editing, these resources will be a good help: A theming thread on Ubuntu Forums: http://ubuntuforums.org/showthread.php?t=1823915 Rosa desktop GRUB2 theming page: http://wiki.rosalab.ru/en/index.php/Grub2_theme_tutorial Ramki’s java blog GRUB2 page: http://www.ramkitech.com/2012/01/grub2-and-themes-customization.html

Ceci a créé le fichier de polices dans mon répertoire de thème dans le bon format. Cependant, quand j'ai redémarré, j'ai découvert que les fichiers de polices ne s'affichaient pas comme attendu. J'ai cherché du secours sur Google, mais sans succès. J'étais sur le point d'abandonner, mais j'ai alors décelé le problème : les polices n'apparaissaient pas parce que GRUB_GFXMODE était réglé à 640 x 480 dans /etc/default/grub. Une fois que j'ai agrandi ceci, et relancé update-grub, les polices ont été prises en compte. Vous pouvez spécifier une résolution standard et une de secours comme ceci :

GRUB_GFXMODE=1024x768x32,640×480

Avec cet ajustement (n'oubliez pas update-grub), GRUB2 change pour 1024 x 768 avec des couleurs sur 32 bits. Si 1024 x 768 n'est pas disponible, il retourne au standard de 640 x 480. Maintenant, les polices s'affichent comme attendu. Voyez l'image ci-dessous.

Encore une fois, l'apparence du menu n'est pas terrible, mais, au moins, les polices Ubuntu fonctionnent maintenant. J'ai indiqué plus tôt qu'il y avait beaucoup plus à faire dans les thèmes que de changer la taille et le style de la police ou l'image de fond d'écran. Il y a plusieurs excellentes ressources qui traitent des thèmes de GRUB2. Si vous êtes mal à l'aise avec la modification de MVC (Modèle-Vue-Contrôleur - https://fr.wikipedia.org/wiki/Modèle-vue-contrôleur) et des images, ces ressources vous seront très utile :

Un fil sur les thèmes dans les Forums Ubuntu : http://ubuntuforums.org/showthread.php?t=1823915

La page de Rosa sur les thèmes GRUB2 dans les PC de bureau : http://wiki.rosalab.ru/en/index.php/Grub2_theme_tutorial

La page sur GRUB2 dans le blog java de Ramki : http://www.ramkitech.com/2012/01/grub2-and-themes-customization.html

9

Ramki’s java blog and the Rosa desktop GRUB2 theming page go more into creating the graphical elements that you’ll need to create complex – but very cool-looking – GRUB2 themes. It’s also worth mentioning the 2008 GRUB Google Summer of Code page: http://grub.gibibit.com/. Unfortunately, all the themes are obsolete, but it might help further understanding of how to theme GRUB2 graphically. I hope I’ve provided some light on theming GRUB2, and shown some of the frustrations that someone new to theming GRUB2 can run into. In the end, I managed to get around some of the problems using some GIMP trickery. I modified my original circuit.png using the select tool to select an area where the boot-loader menu text would be displayed. I checked off the selection tool rounded corners option and chose 25 pixels. Then I dumped a black to dark-gray gradient in the selected area. I also set the item_color = “#FFFFFF” (white) in my /boot/grub/theme/circuit/theme.txt file for better visibility. I also adjusted the spacing by adding item_height=20 and item_spacing=10 to the same theme file. This hack led to a GRUB2 menu (shown below) that was a slight improvement in readability. Just after finishing this article, I found one more great GRUB2 resource on the Ubuntu web site located here: https://help.ubuntu.com/community/Grub2/Displays. This resource is a bit more complete and up-to-date for current versions of Ubuntu.

Le blog java de Ramki et la page de Rosa sur les thèmes GRUB2 dans les PC de bureau vont plus loin dans la création des éléments graphiques dont vous aurez besoin pour créer des thèmes GRUB2 complexes, mais ayant belle allure. Ça vaut le coup aussi de mentionner la page du 2008 GRUB Google Summer of Code (été de codage 2008 de Google GRUB) : http://grub.gibibit.com/. Malheureusement, tous les thèmes sont obsolètes, mais cela peut permettre de comprendre plus en détail comment faire graphiquement des thèmes de GRUB2.

J'espère avoir apporté quelques lumières sur les thèmes de GRUB2 et montré les frustrations que rencontre une personne novice dans les thèmes de GRUB2. À la fin, Je me suis arrangé pour contourner certains des problèmes en utilisant des astuces de GIMP. J'ai modifié le circuit.png original en utilisant l'outil sélection pour sélectionner une zone où le texte du menu du chargeur de démarrage serait affiché. J'ai décoché l'option des coins arrondis de l'outil de sélection et choisi 25 pixels. Puis, dans la zone choisie, j'ai déposé un gradient de couleurs du noir au gris foncé. Pour une meilleure visibilité, j'ai également réglé le item_color = “#FFFFFF” (blanc) dans le fichier /boot/grub/theme/circuit/theme.txt. J'ai aussi ajusté l'espacement en ajoutant item_height=20 et item_spacing=10 au même fichier de thème. Ces modifications ont donné pour résultat un menu GRUB2 (ci-dessous) qui était légèrement plus lisible.

Juste après avoir fini cet article, j'ai trouvé une autre très bonne ressource sur le site Ubuntu situé là : https://help.ubuntu.com/community/Grub2/Displays. Cette ressource est un peu plus complète et à jour pour les versions actuelles d'Ubuntu.

issue99/labo_linux.txt · Dernière modification : 2015/08/15 14:35 de andre_domenech