Page 1 of 1

[Answered] GRUB2 "Hacking"

Posted: Wed Aug 10, 2016 12:23 pm
by Octacone
Hello peeps.
Is there a way to hack GRUB2 so it sets wanted video mode only when you type custom command inside your shell?

Re: GRUB2 "Hacking"

Posted: Wed Aug 10, 2016 12:53 pm
by Roman
I'm not a GRUB2 user, but AFAIK there is a command for that, "gfxmode" maybe. If you really want to extend GRUB's functionality you can a write a plugin.

Re: GRUB2 "Hacking"

Posted: Wed Aug 10, 2016 1:12 pm
by Octocontrabass
GRUB2 uses the firmware to change video modes. For the legacy BIOS case, you can mostly return the computer to the state it was in when the firmware loaded GRUB2 the first time. For the UEFI case, GRUB2 exits boot services when it loads your OS the first time, which means there's no firmware for it to use the second time around.

For the amount of effort that would take, you may as well reboot every time you want to change the video mode.

If you really want to change the video mode from within your OS, you should write a native driver. (Or, if you're truly masochistic, write a PCI option ROM interpreter and all of the necessary PCI-related driver infrastructure.)

Re: GRUB2 "Hacking"

Posted: Wed Aug 10, 2016 1:31 pm
by Octacone
Octocontrabass wrote:GRUB2 uses the firmware to change video modes. For the legacy BIOS case, you can mostly return the computer to the state it was in when the firmware loaded GRUB2 the first time. For the UEFI case, GRUB2 exits boot services when it loads your OS the first time, which means there's no firmware for it to use the second time around.

For the amount of effort that would take, you may as well reboot every time you want to change the video mode.

If you really want to change the video mode from within your OS, you should write a native driver. (Or, if you're truly masochistic, write a PCI option ROM interpreter and all of the necessary PCI-related driver infrastructure.)
I don't use UEFI. I just want to know if I can force GRUB to switch from default text mode to high resolution mode after my kernel has loaded, when I want it.

Re: GRUB2 "Hacking"

Posted: Wed Aug 10, 2016 1:45 pm
by Octocontrabass
All new PCs have UEFI.

Once your kernel is loaded, GRUB is gone. If you want GRUB, you have to load it again, and GRUB will restart your kernel from the beginning.

Re: GRUB2 "Hacking"

Posted: Wed Aug 10, 2016 1:55 pm
by Octacone
Octocontrabass wrote:All new PCs have UEFI.

Once your kernel is loaded, GRUB is gone. If you want GRUB, you have to load it again, and GRUB will restart your kernel from the beginning.
Okay, so I guess that writing native VBE driver is my best bet.

Re: [Answered] GRUB2 "Hacking"

Posted: Wed Aug 10, 2016 4:30 pm
by SpyderTL
octacone wrote:Okay, so I guess that writing native VBE driver is my best bet.
VBE is really only going to be available in 16-bit real mode, so a VBE driver is kind of a bad idea as well.

Your VBE driver would have to switch back to 16-bit mode, call the VBE interrupts, and then switch back to 32-bit mode. Alternately, you could write a virtual machine that runs 16-bit code in 32-bit mode, but this is probably overkill if you only want to be able to switch graphics modes.

Until you write your own native 32-bit video driver(s), your best bet is to just pick a graphics mode, and let GRUB do the switch for you at boot time.