How to add a command permanently to grub2

If you add this code to /boot/grub/custom.cfg (creating the file if it doesn't already exist) then it will be executed just before the grub menu is displayed.

I don't know what exactly those outb commands are doing so I have no idea if it is safe to run them at all, or if running them will interfere with display of the grub menu, so do this at your own risk.


Honestly, to prevent an update to grub from destroying your /boot/grub/custom.cfg I would highly advice you to, at the GRUB prompt, hit e to edit the default boot menu:

If all is successfull, which usually involves mutating the line, in my case of a MBP 8 2:

A. Boot USB Drive -

linux /casper/vmlinuz.efi file=/cdrom/preseed/ubuntu.seed boot=casper quiet splash ---

to

linux /casper/vmlinuz.efi file=/cdrom/preseed/ubuntu.seed boot=casper radeon.modeset=0 i915.modeset=1 i915.lvds_use_channel_mode=2 i915.lvds_use_ssc=0 ---

B. Ubuntu should boot, and display a normal graphics screen.

After finishing the installation, repeat A from above.

C Once booted from the HD, to which you just installed Ubuntu, from the Live USB stick,

  1. Edit sudo vi /etc/grub.d/00_header
    • And insert: outb 0x728 1 outb 0x710 2 outb 0x740 2 outb 0x750 0

after the line, by searching for gfx, which reads: set gfxmode=${GRUB_GFXMODE}. An excerpt of the snippet is below:

set gfxmode=${GRUB_GFXMODE} load_video insmod gfxterm

After this procedure /etc/grub.d/00_header should look like: set gfxmode=${GRUB_GFXMODE} outb 0x728 1 outb 0x710 2 outb 0x740 2 outb 0x750 0 load_video insmod gfxterm

  1. Issue update-grub

This way, next time you run sudo apt update && sudo apt upgrade and there happens to be a grub upgrade, your install will not shit the bed.

Cheers rivanov