Sunday, February 13, 2011

Configure Grub2 Background Image, Resolution and Colors

Here is a method that worked for me to configure Grub2 under Debian 6.0 Squeeze.

First as root or sudo edit /etc/grub.d/05_debian_theme

Add the following somewhere near the top of the file:
set_custom_theme(){
# Set custom color theme.
echo "${1}set menu_color_normal=light-cyan/black"
echo "${1}set menu_color_highlight=white/light-blue"
echo "${1}set color_normal=white/black"
echo "${1}set color_highlight=white/light-blue"
}

menu_color_ changes the colors within the grub selection menu, while color_ changes outside the barrier. If you set black as the second color in any of the entries, for example: menu_color_normal=light-cyan/black grub will make it transparent. You can check here to see a list of available colors.

At the very bottom of 05_debian_theme add the following:
set_background_image "/path/to/your/boot/image.png" ||
set_custom_theme

Remember to select an image that is the same size as you will define in your grub boot screen resolution in the next step, save the file after you are done.

Now as root or sudo edit /etc/default/grub
You might want to modify GRUB_DEFAULT=0, this is the default boot selection, if you want another entry to boot first change it here. GRUB_TIMEOUT=5 is the default timeout before boot of the selected entry in seconds.

GRUB_GFXMODE=1024x768 sets the resolution of grub2 (I think if you add an x after resolution and a mode [e.g. 1024x768x24] you can define the color depth mode, I could be wrong), make sure the background image you set previously is the same size. Also you might want to edit GRUB_GFXPAYLOAD_LINUX=keep and also make sure it is set as =keep. This option will retain your selected resolution during the boot process.

Finally for all your changes to work, as root or sudo you must do update-grub. This will generate a /boot/grub/grub.cfg using your settings.

I honestly hate grub2, it works well for booting operating systems, but it is really disorganized, you can do things a number of ways and it doesn't always work. There is no consistency or easy way to modify everything through a single file, like in the original grub. This method worked for me but took me a while to figure out. If you set your colors under set_default_theme() in /etc/grub.d/05_debian_theme or in /etc/default/grub like a lot of people tell you to, you will discover in (At least under Debian 6.0) your /boot/grub/grub.cfg they get ignored when you have selected a background and revert to a default grey color scheme. This is why I create a custom set_custom_theme() function.

Here is my /etc/grub.d/05_debian_theme and /etc/default/grub, for reference purposes.

No comments: