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

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.

Similar Posts

  • Chinese Charactor Configuration on Fedora 11

    最新的更新版本请看: Fedora 中文字体设置. 使用Linux时我个人倾向使用英文环境系统,而Fedora11在英文环境下中文字体有时会不太好看,经常遇到需要字体优化美化的问题。 以下是我的配置方案,经测试效果还算不错,解决了Fedora 11 中文字体难看的问题: 方案1:使用uming和ukai字体,即AR PL UMing CN等。 关键是使用的字体包如下: 首先要安装这两个字体: cjkuni-ukai-fonts cjkuni-uming-fonts 然后配置一下~/.fonts.conf文件. 使sans-serif serif monospace字体中文使用uming/ukai即可. 我的.fonts.conf文件可以从这里下载(两种选择, 我喜欢前者): https://github.com/zma/config_files 使用Liberation和uming/ukai字体: .fonts.cofn.liberation 使用dejavu和uming/ukai字体: .fonts.conf.dejavu 下载后放到自己的$HOME下改名为.fonts.conf就可以了。 使用uming字体效果如下(请放大后看效果): 方案2:安装文泉驿字体,这个非常简单,安装相应包即可了。 如果喜欢其它的字体选择性的安装上就可以了,只要注意只安装自己需要的就行了。有人使用微软雅黑字体,首先这是侵权的,其次开源的字体做得其实已经很不错了。 最后将字体平滑选项打开, KDE和gnome都有相关设置方法。 以上内容只是针对使用xft字体系统的设置。对于使用核心字体系统的X程序来说字体依然会出现很丑的情况。 下面是针对emacs的设置方法: 首先需要安装这个字体包: xorg-x11-fonts-misc 注意到在中文系统下emacs的中文显示非常好,而在英文环境中去非常差,我们可以利用这一点,在运行emacs前首先将系统环境设为中文即可。 在~/bin/下建立一文件ema 内容如下: #!/bin/bash rm -f ~/.emacs ln -s ~/.emacs.x ~/.emacs LANG=zh_CN.UTF-8 emacs –fullheight -r $* 然后加入执行权限即可: chmod +x…

  • Installing and Configuring 32-bit Firefox on 64-bit Linux (Fedora)

    On a x86-64 64 bit Linux system, sometimes we may want to use the 32 bit Firefox, although the support to 64 bit Firefox is getting much better. Just for needed ones, this post introduces how to install 32 bit Firefox on 64 bit Linux (Fedora as the example). Install 32-bit firefox First, install firfox.i686…

  • Alternatives to goto in bash

    As we know: There is no goto statement support in bash. goto is useful for certain situations, especially for debugging. So, is there any alternative mechanisms to goto in bash? Robert Copeland gave an interesting hacking to this problem: http://bobcopeland.com/blog/2012/10/goto-in-bash/ The idea is like the self-modifying code. But the difference is to generate a piece…

  • Setting Up Standalone (Local) Hadoop

    Hadoop is designed to run on [[hadoop-installation-tutorial|hundreds to thousands of computers]] inside cluster. However, Hadoop is configured to run things in a non-distributed mode as a single Java process by default. This is specially useful for debugging since distributed debugging is really a nightmare. This post introduces how to set up a standalone Hadoop environment….

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 *