Monday, September 14, 2009

GRUB 2, graphical boot tips to set the desired VGA console mode.

Yes, everyone wants graphics, or better, the ability to customize things to suit different situations. I have always suggested programmers regarding interfaces and programs in genre to let the user be comfortable to set and change almost every aspect of program GUI, at least icons, fonts, backgrounds and often ii found some programs being too customizable, on the contrary.

Let’s take a look at GRUB 2, also called grub-pc by updates that the Debian distro suggests. GRUB 2 is the successor of the GRUB bootloader, commonly shipped within the majority Linux distributions. Basically i will cover only some graphical aspects that GRUB 2 seems to be strong with: customization of fonts, background, console modes directly set by GRUB 2 itself, no more limitation to the resolution of 640×480 pixels at startup, can be used bigger background pictures also at the resolution of 1650×1050 pixels.

Our favorite kernel parameter vga=791 for example, is now deprecated (if using GRUB 2), and it’s a little tricky to set correctly the console mode. The configuration file for GRUB 2 is now called grub.cfg in place of the old menu.lst whose we were addicted, but resides in the same directory /boot/grub. Things are very distribution specific i think, but remain the fact that configuration changes rely on the grub.cfg file that we have to alter in some way. Debian is putting the defaults into /etc/default/grub where you can find and set common used parameter easy to understand.

"For example i use Debian within VirtualBox at a resolution of 1280×800 for the console and also for the Xorg server. If you want you to start with this resolution also for GRUB 2 (remember in the past was very limited this feature, and if you are using VirtualBox or other virtualization programs the annoying result was in resizing the window and than enlarging upon the system goes into graphical mode, for example, with the splash screen: usplash, splashy and others), very nice, no more discrepancies between modes: the line to change into the /etc/default/grub file is GRUB_GFXMODE=1280×800 and then issuing update-grub. The resulting action is to write the line set gfxmode=1280×800 into the grub.cfg file."

We are half a way to our objective, to change also the resolution of our console. We need two conditions, the terminal must be set to insmod vbe line MUST be present in your configuration file (this ensure correct console mode settings, if you note this instruction is almost identical to load a kernel module) and the option gfxpayload=keep MUST be set. This will keep our 1280×800 resolution also for the console, YEAH! no more resizing on VirtualBox! and this is not the end. Someone reported that adding gfxpayload=my_resolution will be able to set a different resolution for the console instead of having the same of the GRUB 2 menu, sincerely i have not tested it. Why i have not tested it? The strong point is that to change grub.cfg requires a little more effort than editing it with a text editor, because all your changes will be discarded when you run the command update-grub.

/boot/grub/grub.cfg excerpt :

set gfxmode=1280x800
set gfxpayload=keep
insmod gfxterm
insmod vbe

update-grub reads the configuration stored in the /etc/default/grub file an the scripts that resides into the /etc/grub.d directory at least on Debian (i suppose is the same for other distributions). To set the option gfxpayload=keep i had to modify one of this file cause i discovered that this line MUST be the next after the gfxmode one, like you can note above.

You have to find the file or script responsible to change the content of your grub.cfg configuration file and append the appropriate line, after the gfxmode sentence, gfxpayload=keep to keep the same resolution of the GRUB 2 menu for the console (wider resolutions result in smaller console fonts). In my case i had to edit the script 00_header stored into the /etc/grub.d directory.

There are other scripts into this directory, responsible to set other parameters, like theme (background picture an font color), distribution and custom OS. To change the background image of your GRUB 2 menu is almost the same process, find the script or configuration file that change the attribute of the background_image instance of the grub.cfg, and change the line pointing to the image (usually a .png or .tga file) with the one you like, i have tested it with a resolution of 1650×1050 pixels modifying the script 05_debian_theme, in my case, stored into /etc/grub.d directory as well.

Related Links

GRUB 2 – http://www.gnu.org/software/grub/grub-2.en.html

GRUB Wiki – http://grub.enbug.org

via GRUB 2, graphical boot tips to set the desired VGA console mode. – iNTBlog.

Annunci