Making GRUB ask for VBE mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
qookie
Member
Member
Posts: 72
Joined: Sun Apr 30, 2017 12:16 pm
Libera.chat IRC: qookie
Location: Poland

Making GRUB ask for VBE mode

Post by qookie »

Hello! I'm working on my OS. I've been able to get different video modes by setting Multiboot flags. I have been wondering how do you get GRUB to ask what video mode to choose. Contents of grub.cfg
Setting the GRUB_GFXMODE and GRUB_GFXPAYLOAD doesn't work(when the video mode specified in Multiboot header cannot be found, it defaults to 640x480 in QEMU and VirtualBox). Sorry for my bad English, I'm not a native English speaker. Thanks in advance.
Working on managarm.
no92
Member
Member
Posts: 307
Joined: Wed Oct 30, 2013 1:57 pm
Libera.chat IRC: no92
Location: Germany
Contact:

Re: Making GRUB ask for VBE mode

Post by no92 »

There are a number of ways to do it, although it is not clear to me which one you're looking for exactly.

First off, as you mentioned, you can request a resolution in your Multiboot flags. This is hardcoded in the binary, therefore not really good in terms of letting the user choose a resolution.

As you rightfully state, you can set (read: request) a resolution using a GRUB variable: it is called 'gfxpayload'. For me, this overrides my Multiboot2-header resolution. Typically, I use it as:

Code: Select all

menuentry "MyOS" {
    multiboot2 /path/to/my/kernel
    set gfxpayload=1920x1080x32
    boot
}
You can create multiple entries using different resolutions, letting the user choose one of the predefined options in GRUB. To clean things up, use a submenu for that. Here's how I do it.

If you want ultimate flexibility, you can let the user input the values. Use GRUB's read command for this. After that, you can construct the resolution and set gfxpayload to that value.

I haven't done this, but IIRC it looks something like this:

Code: Select all

menuentry "custom" {
    echo "width:"
    read __width
    echo "height:"
    read __height
    <your commands>
    set gfxpayload=${__width}x${__height}x32
    boot
}
User avatar
qookie
Member
Member
Posts: 72
Joined: Sun Apr 30, 2017 12:16 pm
Libera.chat IRC: qookie
Location: Poland

Re: Making GRUB ask for VBE mode

Post by qookie »

Thank you very much @no92. This was exactly what I was looking for. I must have been doing something incorrectly before.
Working on managarm.
Post Reply