Change Grub2 background image, language and font size

AIO Boot uses the Grub2 default theme for the fastest boot speed. Instead, you can change the background, language, and font size of Grub2.

Introduction

AIO Boot has used the default theme of Grub2 since its initial release. It is quite nice, lightweight and of course is best suited for Grub2. AIO Boot has too many menus, and it has hotkeys support for quick access to a menu, the hotkey is in square brackets. This helps you to quickly boot into the operating system.

There are two ways that you can change the background, language, and font for the AIO Boot’s Grub2. Run AIOCreator.exe and change it in Settings, or boot into Grub2 and change it in the Help menu (press the z key). In this article I will share the Grub2 scripts I wrote for AIO Boot.

Grub2 background image, language and font size

After changing the background image, language and font for Grub2, these values are saved. In the code below, I will use the save_env command to save the bg, lang and font variables to the grubenv file. If you have not run AIOCreator.exe yet, rename /AIO/grub/_grubenv to /AIO/grub/grubenv. When booting into Grub2, you just need to check the value of these variables. If so then use, otherwise set by default.

Background image

To display the background image for Grub2, just use the background_image command.

background_image "/AIO/grub/themes/splash.png"

By default, the wallpaper will be made to fit the screen resolution. If you want to keep the size of the background image, add a “normal” value for the “-m” parameter.

background_image -m normal "/AIO/grub/themes/splash.png"

This is the Grub2 script to change the background image.

submenu "Change Background" {
	insmod regexp
	echo "Getting the list of files in \"/AIO/grub/themes\". Please wait..."
	for file in /AIO/grub/themes/*; do
		if ! test -f "$file"; then continue; fi
		if [ "$file" == "/AIO/grub/themes/${bg}" ]; then continue; fi
		regexp -s filename "/AIO/grub/themes/(.*)" "$file"
		if [ -z "$havefile" ]; then set havefile="1"; fi
		menuentry "${filename}" {
			bg="$1"
			background_image "${prefix}/themes/${bg}"
			save_env bg
			configfile ${prefix}/grub.cfg
		}
	done
	if [ -z "$havefile" ]; then
		esccont "Please copy all your PNG, JPG and JPEG files to the \"/AIO/grub/themes\" folder."
	else
		unset havefile
		menuentry "Return to the Main menu" {
			configfile ${prefix}/grub.cfg
		}
	fi
	unset filename
}

When you access the above menu, it will list all the files in the /AIO /grub/themes directory (except for the current background image). Then choose one of those files as the background image for Grub2. If the background image not showing, its size may not fit. You also need to load the necessary modules first, jpeg for .JPG and .JPEG, png for .PNG.

insmod jpeg
insmod png

Languages

Grub2 supports 38 languages. Grub2 language files are located in the locale directory. Here is a Grub2 script that shows 37 languages (except for the current language), just select one of the menus to change the language.

submenu "Change Language" {
	insmod regexp
	for langstr in "vi=Tiếng Việt" "en=English" "ast=Asturian; Bable; Leonese; Asturleonese" "ca=català" "zh_CN=中文 (Simplified)" "zh_TW=中文 (Traditional)" "da=dansk" "nl=Dutch" "[email protected]=English - Arabic"				\
					"[email protected]=English - Cyrillic" "[email protected]=English - Greek" "[email protected]=English - Hebrew" "[email protected]=English - Piglatin" "[email protected]=English - Quot"			\
					"eo=Esperanto" "fi=Finnish" "fr=français" "gl=Galego" "de=Deutsch" "[email protected]=German - Hebrew" "de_CH=German - SWITZERLAND (CH)" "hu=magyar"				\
					"hr=hrvatski jezik" "id=Bahasa Indonesia" "it=Italiano" "ja=日本語" "lt=lietuvių kalba" "nb=Norsk Bokmål" "no=Norwegian" "pl=Polish" "pt_BR=Português" "pa=Panjabi" "ru=русский" "sr=српски језик"	\
					"sl=Slovenian" "es=Español" "sv=Svenska" "tr=Türkçe" "uk=Українська"; do
		regexp -s 2:langname -s 1:langcode '(.*)=(.*)' "$langstr"
		if [ "$langcode" == "$lang" ] -o [ -z "$lang" -a "$langcode" == "en" ] -o [ "$langcode" != "en" -a ! -e /AIO/grub/locale/${langcode}.mo ]; then continue; fi
		menuentry "${langname}" "$langcode" {
			lang="$2"
			save_env lang
			configfile ${prefix}/grub.cfg
		}
	done
	menuentry "Return to the Main menu" {
		configfile ${prefix}/grub.cfg
	}
}

If the Grub2 language file does not exist, the language will not be listed.

Fonts

AIO Boot uses Unicode fonts (unicode.pf2) to support all 38 languages. Available in two sizes, Small and Large, for the English language, AIO Boot uses DejaVuSansMono fonts for large sizes.

if [ "$font" == "unicode-small" ]; then fontmenu="Switch to larger font"; else fontmenu="Switch to smaller font"; fi
menuentry "${fontmenu}" {
	if [ "$font" != "unicode-small" ]; then font=unicode-small;
	elif [ -z "$lang" ]; then font=DejaVuSansMono-large; else font=unicode-large; fi
	save_env font
	configfile ${prefix}/grub.cfg
}

Use the grub-mkfont command to create font files for Grub2.

You may need to modify and improve the Grub2 code before using it. Leave a comment if you have any questions.

Share this...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPin on PinterestShare on RedditShare on TumblrShare on VKBuffer this pageDigg thisEmail this to someoneFlattr the authorPrint this pageShare on StumbleUponShare on Yummly