Skip to content

Instantly share code, notes, and snippets.

@williamhaley
Last active February 12, 2023 08:51
Show Gist options
  • Save williamhaley/e27fbcb3c818c30e832fb6189ff9aa5f to your computer and use it in GitHub Desktop.
Save williamhaley/e27fbcb3c818c30e832fb6189ff9aa5f to your computer and use it in GitHub Desktop.
GRUB2 Theme With grub-mkstandalone

Problem

grub-mkstandalone creates an image designed to be held in memory. grub-mkstandalone comes with a --themes flag that could be used to specify a theme, but depending on the modules installed, you may encounter this error like I did.

grub-mkstandalone: error: core image is too big (0x1d71b3 > 0x78000).

This means that the image generated by grub-mkstandalone was too large.

One Solution

Rather than try to embed the theme in the memdisk image generated by grub-mkstandalone, you can manually reference the theme in the grub.cfg file.

Note, your mileage may vary. Depending on the theme, you may need more modules or configuration than me.

For my example, I am using the stock starfield grub theme.

Example

Note: This is a trival example. It will not actually boot, but it can (or should) show you the working theme at the boot prompt

mkdir -p $HOME/live
touch $HOME/live/DEBIAN_CUSTOM
rsync -avr /usr/share/grub/themes/ $HOME/live/themes/
cat <<'EOF' >$HOME/live/grub.cfg

terminal_output gfxterm
insmod gfxmenu

search --set=root --file /DEBIAN_CUSTOM

insmod all_video
insmod vga

set default="0"
set timeout=30

loadfont /themes/starfield/dejavu_10.pf2
loadfont /themes/starfield/dejavu_12.pf2
loadfont /themes/starfield/dejavu_14.pf2
loadfont /themes/starfield/dejavu_16.pf2
loadfont /themes/starfield/dejavu_bold_14.pf2
insmod png
set theme=/themes/starfield/theme.txt
export theme

menuentry "Debian Live" {
    linux /vmlinuz boot=live quiet nomodeset
    initrd /initrd
}
EOF
grub-mkstandalone \
    --format=i386-pc \
    --output=$HOME/live/core.img \
    --install-modules="linux normal iso9660 biosdisk memdisk search tar ls png gfxmenu" \
    --modules="linux normal iso9660 biosdisk search png gfxmenu" \
    --locales="" \
    --fonts="" \
    --themes="" \
    "boot/grub/grub.cfg=$HOME/live/grub.cfg"
cat \
    /usr/lib/grub/i386-pc/cdboot.img \
    $HOME/live/core.img \
> $HOME/live/bios.img
rm -f $HOME/live/debian-custom.iso && \
xorriso \
    -as mkisofs \
    -iso-level 3 \
    -full-iso9660-filenames \
    -volid "DEBIAN_CUSTOM" \
    --grub2-boot-info \
    --grub2-mbr /usr/lib/grub/i386-pc/boot_hybrid.img \
    -eltorito-boot \
        boot/grub/bios.img \
        -no-emul-boot \
        -boot-load-size 4 \
        -boot-info-table \
        --eltorito-catalog boot/grub/boot.cat \
    -output "${HOME}/debian-custom.iso" \
    -graft-points \
        "${HOME}/live" \
        /boot/grub/bios.img=$HOME/live/bios.img
@williamhaley
Copy link
Author

virtualbox_test_01_10_2018_23_52_21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment