6

I'm trying to manually install a background image for grub on a bootable flash drive. Since the drive only boots ISO's and has no installed OS, I can't take advantage of scripts such as update-grub to do this for me and the posts regarding editing /etc/default/grub don't apply to my situation. I've seen How to put a background image on GRUB? but it doesn't apply for the reasons I've mentioned. I've managed to get all my ISO's to boot properly but I'm stuck on applying the background image. Here's the relevant section of my grub.cfg the rest is all menu entries that work properly (falling back to text mode).

set timeout=10
set default=0
set root=(hd0,msdos1)
### BEGIN background setup ###
function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}
load_video
insmod gfxterm
insmod part_msdos
insmod png
GRUB_TERMINAL=gfxterm
GRUB_GFXMODE=auto
GRUB_BACKGROUND="splash.png"
### END background setup ###

The background image is a 640x480 PNG file (which I scaled to size with gimp) Using GRUB 2.02 Beta2

Further research indicates that this part:

GRUB_TERMINAL=gfxterm
GRUB_GFXMODE=auto
GRUB_BACKGROUND="splash.png"

uses variables that are used by the update scripts and belong in /etc/default/grub and don't appear in this fashion in grub.cfg so I'm certain those lines at least are wrong.

EDIT: I've made some adjustments but still no joy. Here's a pastebin of the relevant section (I excluded the irrelevant menu entries as they work fine in text mode and aren't the problem)

2

You need to add the next line to your grub.cfg before the menus. Since it is custom made and you're not going to use update-grub you shouldn't have any problem:

 background_image /boot/Your_image.png

Now, if you want to have a different background for your distros, you just need to add the line in the menu. For instance, this is the part where my menus start; as you can see I have a default background before the menus so that when grub starts it has a background, and after that each menu/submenu has its own background:

background_image /boot/SolusOS-splash.png

set color_normal=white/black
set color_highlight=black/white

submenu "Debian 8.1 -->"{
     submenu "Debian 8.1 i386 -->"{         
            background_image    /boot/DebianLava-splash.png         
            set iso=/boot/ISOs/debian-live-8.1.0-i386-gnome-desktop.iso
          ....

EDIT: Here are my search path entries (mind the uuid is my usb's ID) don't know if this might be your issue:

set boot_uuid=D042-8A53    
set root_uuid=D042-8A53

search --fs-uuid $root_uuid --set=root
search --fs-uuid $boot_uuid --set=grub_boot
if [ $boot_uuid == $root_uuid ]
then
    set grub_boot=($grub_boot)/boot
else
    set grub_boot=($grub_boot)
fi
  • So if I'm following you, you are saying that I can use background images on submenus in this fashion. Is that correct? I'm just shooting for a single background image for all ISOs. Do you get the same results whether EFI or Legacy boot? – Elder Geek Jan 24 '17 at 21:02
  • Exactly. I have a different background for Debian distros, another one for Kali, another one for TAILs and so on. You need to put one background before the menus otherwise you won't have a default starting background, then you put the specific ones inside the submenus and you get your distro's specific background. I haven't tried EFI, just legacy but I guess it shouldn't matter as long as grub has access to the file you specify as the background image. – YoMismo Jan 25 '17 at 8:05
  • I've made some mods and while I still have a functional boot, I'm not getting the background image. (just text mode) Here's my current grub.cfg (everything prior to the irrelevant working menu entries. I'm quite sure I'm missing something simple.. Any ideas? – Elder Geek Jan 25 '17 at 18:00
  • Also note that I tried setting background image just as you have it and also with set= with and without quotes around the image path/name. I've confirmed that I have root set correctly by using the search --label parameter. – Elder Geek Jan 25 '17 at 18:06
  • I have added to the answer my search since it is quite different from yours. As you can see I have also set the grub_boot besides root, maybe that is the problem and the image is searched according to grub_boot instead root. – YoMismo Jan 26 '17 at 8:14
0

Since my coding skills were clearly not up to this task I developed a method to resolve this issue by temporarily installing a live Lubuntu system to the flash drive and utilizing Daniel Richter most excellent grub customizer to give myself a working starting point. I systematically went through the code commenting out lines and sections that I thought might be unnecessary for my purposes, testing changes as I went along. An example with comments (without the menu entries) can be found here for those who may be interested in the process. Below is the tested section of code (used for Legacy Boot) after editing that I ended up with after removing the majority of the comments and unneeded sections. It appears that the majority of my problems were related to improper handling of linux_gfx_mode, terminal_output and background_image(and setting root). As I surmised in my edit the variables are expressed differently in the grub.cfg file than they are in the grub scripts. I don't doubt that this could be improved upon and as I discover simplifications I will edit them in.

  set have_grubenv=true
  load_env
   set timeout=10 #added
   set default=2 #added
  menuentry_id_option=""
export menuentry_id_option
function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}
#if [ x$feature_default_font_path = xy ] ; then
#font=unicode
#else
##Scrapped if-then-else above required? - NO?
insmod part_msdos
insmod ext2
search --no-floppy --set=root --label freedom
    font=/boot/grub/fonts/unicode.pf2
fi
if loadfont $font ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  set locale_dir=/boot/grub/locale
  set lang=en_US
  insmod gettext
fi
terminal_output gfxterm
insmod part_msdos
insmod ext2
search --set=root --label freedom
### Begin Background setup ###
insmod png
set menu_color_normal=yellow/black
set menu_color_highlight=black/light-gray
if background_image /boot/grub/splash.png; then
  true
else
  set menu_color_normal=green/black
  set menu_color_highlight=black/light-gray
fi
### END Background setup ###

### BEGIN setup graphics ###
function gfxmode {
    set gfxpayload="${1}"
    if [ "${1}" = "keep" ]; then
        set vt_handoff=vt.handoff=7
    else
        set vt_handoff=
    fi
}
if [ "${recordfail}" != 1 ]; then
  if [ -e ${prefix}/gfxblacklist.txt ]; then
    if hwmatch ${prefix}/gfxblacklist.txt 3; then
      if [ ${match} = 0 ]; then
        set linux_gfx_mode=keep
      else
        set linux_gfx_mode=text
      fi
    else
      set linux_gfx_mode=text
    fi
  else
    set linux_gfx_mode=keep
  fi
else
  set linux_gfx_mode=text
fi
export linux_gfx_mode
### End setup graphics ###

Sources:

https://answers.launchpad.net/~danielrichter2007

https://ubuntuforums.org/showthread.php?t=1195275

https://www.gnu.org/software/grub/manual/grub.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.