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 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 How to Regenerate Grub2 Config file on Linux

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×200640×400640×480800×500800×600896×6721024×6401024×7681280×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 bits781 (30D)801 (321)784 (310)880 (370)787 (313)816 (330)875 (36B)790 (316)793 (319)
16 bits782 (30E)802 (322)785 (311)881 (371)788 (314)817 (331)876 (36C)791 (317)794 (31A)
24 bits783 (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.

About Eric Zhiqiang Ma

Eric Zhiqiang Ma is interested in operating systems and distributed computing and processing systems. Find Eric on Facebook, Twitter, LinkedIn and Google+. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

4 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.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>