How to Configure Linux Kernel Video Mode for 32-bit and 16-bit Boot Protocols

Posted on In Linux

The Linux kernel has a generic driver for a graphic framebuffer named vesafb on intel boxes. It provides a nice large console for most of modern displays.

Setting VESA modes for Linux kernel with 32-bit and 16-bit boot protocol are different. We introduce both methods here.

Linux kernel with 32-bit boot protocol

For machine with some new BIOS other than legacy BIOS, such as EFI, LinuxBIOS, etc, and kexec, the 16-bit real mode setup code in kernel based on legacy BIOS can not be used, so a 32-bit boot protocol needs to be defined.

– from THE LINUX/x86 BOOT PROTOCOL

The modes can be set by adding ‘video=…’ to the kernel boot parameter.

The syntax is like this (ref: Kernel Mode-setting):

video=<conn>:<xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd]

For Grub2, this can be added by 2 steps.

Edit ‘/etc/default/grub’ and edit the line for ‘GRUB_CMDLINE_LINUX’. For example, to set the video mode to 1024×800 with 32-bit color depth:

GRUB_CMDLINE_LINUX="rd.md=0 rd.lvm=0 rd.dm=0 KEYTABLE=us rd.luks=0 LANG=en_US.UTF-8 video=1024x800-32"

After editing the file, generate the new configuration file for grub2 following https://www.systutorials.com/how-to-regenerate-grub2-config-file-on-linux/.

Add to ‘/etc/default/grub’:

GRUB_GFXMODE=1024x800x32
GRUB_GFXPAYLOAD_LINUX=keep
GRUB_TERMINAL=gfxterm

Then, make the new Grub2 config file following

Linux kernel with 16-bit boot protocol

Switching VESA modes of Linux kernel at boot time can be done by using the “vga=… kernel boot parameter. This parameter accept the decimal value of Linux video mode numbers instead of VESA video mode numbers. The Linux video mode number can be easily derived from the VESA number.

The video mode number of the Linux kernel is the VESA mode number plus 0×200.

Linux_kernel_mode_number = VESA_mode_number + 0x200

Here are some of the VESA mode numbers:

    | 640x480  800x600  1024x768 1280x1024
----+-------------------------------------
256 |  0x101    0x103    0x105    0x107
32k |  0x110    0x113    0x116    0x119
64k |  0x111    0x114    0x117    0x11A
16M |  0x112    0x115    0x118    0x11B

So the table for the Kernel mode numbers are:

    | 640x480  800x600  1024x768 1280x1024
----+-------------------------------------
256 |  0x301    0x303    0x305    0x307
32k |  0x310    0x313    0x316    0x319
64k |  0x311    0x314    0x317    0x31A
16M |  0x312    0x315    0x318    0x31B

The decimal value of the Linux kernel video mode number can be passed to the kernel in the form “vga=YYY“, where YYY is the decimal value.

Update: vga=ask is not supported by GRUB2. Use the new method as follows to find out supported video modes. The method is credited to suggested by Sebastian.

Just edit a GRUB menu entry when booting, remove everything and enter “vbeinfo” and Ctrl+x to execute it. The VESA modes output looks like this:

VBE info: version: 2.0 OEM software rev 1.0
total memory: 4096 KiB
List of compatible video modes:
Legend: P=Packed pixel, D=Direct color, mask/pos=R/G/B/reserved
0x101: 640 x 480 x 8 Packed
0x110: 640 x 480 x 15 Direct, mask: 5/5/5/1 pos: 10/5/0/15
...
Configured VBE mode (vbe_mode) = 0x101

Press any key to continue ...

Press a key and Esc and you’re back in the boot menu.

Instead of the YYY decimal value, the “vga” parameter also accept “ask” which will list all the Linux kernel mode numbers and let the user select one. You can used it if you want to be asked every time booting Linux. It can also be used to find the best Linux video mode on your console.

The best way for configuring the “vga=YYY” parameter is following these steps.

First, add “vga=ask” parameter to the Linux kernel entry in grub configuration file /boot/grub/grub.conf. Like this:

kernel /vmlinuz-2.6.32.16-141.fc12.i686 ro root=/dev/mapper/VolGroup-LogVol00 vga=ask

Second, reboot Linux and hit return when the kernel ask for the vga mode. Then select one mode from the list and remember the Linux mode number which is a hexdecimal value in the format YYY. You can also get more choice by entering “scan“.

Last, calculate the decimal value of the Linux video mode number. This simple python command can be used:

python -c "print 0xYYY"

YYY is the hexdecimal value you got.

Then change “ask” in grub configuration file to the decimal value calculated.

Here is a list of usually used Linux mode number and the decimal value if you like to choose one directly:


320×200 640×400 640×480 800×500 800×600 896×672 1024×640 1024×768 1280×1024
4 bits 770 (302) 774 (306)
8 bits 768 (300) 769 (301) 879 (36F) 701 (303) 815 (32F) 874 (36A) 773 (305) 775 (307)
15 bits 781 (30D) 801 (321) 784 (310) 880 (370) 787 (313) 816 (330) 875 (36B) 790 (316) 793 (319)
16 bits 782 (30E) 802 (322) 785 (311) 881 (371) 788 (314) 817 (331) 876 (36C) 791 (317) 794 (31A)
24 bits 783 (30F) 803 (323) 786 (312) 882 (372) 789 (315) 818 (332) 877 (36D) 792 (318) 795 (31B)
32 bits 804 (324) 809 (329) 883 (373) 814 (32E) 819 (333) 878 (36E) 824 (338) 829 (33D)

Update on Apr. 29, 2015: add vbeinfo method suggested by Sebastian; suggest grub2-regen-cfg.bash for regenerating Grub2 config file instead of the manual way.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

9 comments

      1. Yes, sure, just edit a GRUB menu entry when booting, remove everything and enter “vbeinfo” and Ctrl+x to execute it. The VESA modes output looks like this:


        VBE info: version: 2.0 OEM software rev 1.0
        total memory: 4096 KiB
        List of compatible video modes:
        Legend: P=Packed pixel, D=Direct color, mask/pos=R/G/B/reserved
        0x101: 640 x 480 x 8 Packed
        0x110: 640 x 480 x 15 Direct, mask: 5/5/5/1 pos: 10/5/0/15
        ...
        Configured VBE mode (vbe_mode) = 0x101

        Press any key to continue ...

        Press a key and Esc and you’re back in the boot menu.

        But there is no guarantee that the displayed modes will actually work. E.g. in my QEMU/KVM VM here it is displayed that 0x117 is compatible but when setting “vga=0x317” everything remains black. So I have to set “vga=0x316” for 1024×768.

  1. So, kernel parameters have nothing to do with grub. Grub just passes them to the kernel. Therefore, grub can’t support or not support kernel parameters. Additionally, why would you convert to decimal when the kernel supports passing the parameter as hex? Just preface it with 0x such as: vga=0x31E. This reads like a how to article written by someone who doesn’t know what they are doing.

    1. > grub can’t support or not support kernel parameters.

      Grub2 does parse and manipulate the kernel parameters – https://www.gnu.org/software/grub/manual/grub/grub.html#gfxpayload . Discussions in https://wiki.debian.org/GrubTransition#fnref-231bbb76472490d8f289f110d30d2d982e08a663 too as a reference. The wording in this post was indeed not accurate and may need to be refined when I got some time for it.

      > why would you convert to decimal when the kernel supports passing the parameter as hex? Just preface it with 0x such as: vga=0x31E.

      Using decimal numbers is the safer way – https://www.kernel.org/doc/Documentation/svga.txt , although it is not common to see LILO now.

      1. This is a great article! It’s exactly the info I was looking for. The vga codes in decimal notation were a real help to me! :up:

        On the other hand, don’t pay any attention to those full of themselves. Let them write their own articles. They won’t. Because that would be work and shallow criticisms mean no effort.

        Thank you for sharing your knowledge and your time freely as you do. Regards!

Leave a Reply

Your email address will not be published. Required fields are marked *