Debian 9.1 (stretch) with proprietary nvidia-driver and uvesafb

Debian 9.1 (stretch) with proprietary nvidia-driver and uvesafb

So it’s 2017 and I can’t believe I had to get my hands this dirty to put this to work, but it finally works: I have high resolution text console while using the proprietary nvidia-driver! Don’t get me wrong: the steps are easy, but the mere fact I had to do this is what annoys me. Why don’t the proprietary nvidia-drivers deliver a beautiful framebuffer console out-of-the-box like nouveau does? Anyway…

If you got to this post, chances are you have done your fair share of searches, tried different suggestions from many different Forums and/or Stack Overflow answers but is still strugling. Also, if you know what this post is related to, chances are you actually need/want a framebuffer console, so I assume you can get around the console and editing system files. That being said, I’ll keep this tutorial very straightforward and not get into many details explaining how to do basic stuff.

Well let’s get to it, then!

NOTE: I usually do these things on a root console, so you won’t see me use sudo on my commands. If you don’t feel comfortable doing that, just remember to put sudo before every command you see here.

Commands have dark background and begin with a #  indicating that I’m on a root shell. Anything else is either the output of a command or the content of a file and have white background.

You’ll need two packages: v86d and hwinfo. Since this tutorial is for Debian:

# apt update
# apt install v86d hwinfo -y

After that, run:

# hwinfo --framebuffer

The output in my case was:

# hwinfo --framebuffer
02: None 00.0: 11001 VESA Framebuffer
[Created at bios.459]
Unique ID: rdCR.XCOohx2LF9A
Hardware Class: framebuffer
Model: "NVIDIA GP104 Board"
Vendor: "NVIDIA Corporation"
Device: "GP104 Board"
SubVendor: "NVIDIA"
SubDevice:
Revision: "Chip Rev"
Memory Size: 16 MB
Memory Range: 0xd1000000-0xd1ffffff (rw)
Mode 0x0301: 640x480 (+640), 8 bits
Mode 0x0303: 800x600 (+800), 8 bits
Mode 0x0305: 1024x768 (+1024), 8 bits
Mode 0x0307: 1280x1024 (+1280), 8 bits
Mode 0x0311: 640x480 (+1280), 16 bits
Mode 0x0312: 640x480 (+2560), 24 bits
Mode 0x0314: 800x600 (+1600), 16 bits
Mode 0x0315: 800x600 (+3200), 24 bits
Mode 0x0317: 1024x768 (+2048), 16 bits
Mode 0x0318: 1024x768 (+4096), 24 bits
Mode 0x031a: 1280x1024 (+2560), 16 bits
Mode 0x031b: 1280x1024 (+5120), 24 bits
Mode 0x0345: 1600x1200 (+1600), 8 bits
Mode 0x0346: 1600x1200 (+3200), 16 bits
Mode 0x034a: 1600x1200 (+6400), 24 bits
Mode 0x034b: 3840x2160 (+3840), 8 bits
Mode 0x034c: 3840x2160 (+7680), 16 bits
Config Status: cfg=new, avail=yes, need=no, active=unknown

Take note of the resolution and color depth you want for your console. Even though my screen is 3840×2160 (4K) I went with a combination of 1600×1200-16 for GRUB (line 27) and 3840×2160-16 for the console itself (line 30). For the console I applied a bigger font so I could actually go with the native resolution for my screen. More on this later, keep reading!

Next step is to create a new file and edit two existing ones.

First of all, create the file /etc/initramfs-tools/conf.d/splash with the following content:

FRAMEBUFFER=y

Next, edit /etc/initramfs-tools/modules and append this, but with the resolution you chose for your console. In my case:

# List of modules that you want to include in your initramfs.
# They will be loaded at boot time in the order below.
#
# Syntax:  module_name [args ...]
#
# You must run update-initramfs(8) to effect this change.
#
# Examples:
#
# raid1
# sd_mod
uvesafb mode_option=3840x2160-16 mtrr=3 scroll=ywrap

Now let’s set the configuration on the GRUB file both for the Kernel and for GRUB itself. Edit the file /etc/default/grub and look for the highlighted lines below. Input the info as you see, respecting the resolution you chose for GRUB and the one for the Linux Console.

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX="video=uvesafb:mode_option=3840x2160-16,mtrr=3,scroll=ywrap"
GRUB_BACKGROUND="/usr/share/wallpapers/asus_rog.png"

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
# GRUB_GFXMODE=3840x2160x16
GRUB_GFXMODE=1600x1200x16
GRUB_GFXPAYLOAD_LINUX=3840x2160x16

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"

Line 10 is for the Kernel, instructing it to use uvesafb and giving it the same parameters we put on the initramfs file before.

Line 25 is the resolution for the GRUB screen itself (where you choose the operating system to boot). As I previously said, I went with 1600×1200 (16 bits) because it looks better for me (and for some reason 24 bits didn’t work here and it fallback to VESA 640×480). Choose whatever you want, based on what is available at your system.

Line 26 is the resolution GRUB will apply when handing control over to Linux. Keep in mind that many tutorials about improving the console resolution will tell you to use keep on this parameter. That is for when you want to use the same resolution you put on GRUB_GFXMODE.

Attention: note that the syntax for uvesafb both on the initramfs file and on line 10 above use a dash to separate the resolution and color depth, while on GRUB_GFXMODE and GRUB_GFXPAYLOAD_LINUX you must use x.

Ok, now that we must instruct initramfs and GRUB that those files were modified. To do this, run:

# update-initramfs -k all -u
# update-grub2

Output will be something like this, depending on your Kernel version, operating systems you have installed on your computer and other GRUB settings, so bare in mind your mileage may vary:

# update-initramfs -k all -u
update-initramfs: Generating /boot/initrd.img-4.9.0-3-amd64

# update-grub2
Generating grub configuration file ...
Found background: /usr/share/wallpapers/asus_rog.png
Found background image: /usr/share/wallpapers/asus_rog.png
Found linux image: /boot/vmlinuz-4.9.0-3-amd64
Found initrd image: /boot/initrd.img-4.9.0-3-amd64
Found Windows 10 on /dev/nvme0n1p1
done

And that’s it. You can go on and reboot and see both GRUB and your text console with high resolution!

But before I consider this tutorial finished, let me give you a tip if you also used a very high resolution on your console like I did and now you have tiny fonts there: to solve this, reconfigure your console and tell it to use a different, bigger font.

To do that, run:

# dpkg-reconfigure console-setup

Given I am using 3840×2160 on the text console, here is my suggestion for answers to the questions you’ll be asked when running above command in case you use the same resolution:

  • Encoding to use on the console: UTF-8
  • Character set to support: Latin1 and Latin5  (choose what fits your case best)
  • Font for the console: TerminusBold
  • Font size: 12×24 (framebuffer only)

Settings are applied immediately. Enjoy! 😎

3 thoughts on “Debian 9.1 (stretch) with proprietary nvidia-driver and uvesafb

  • Thanks. I wasn’t clear on how to switch to uvesafb. Couple of notes though: the command to update initramfs’s is of course update-initramfs, not initramfs. Also I don’t think it’s a good idea to update the initramfs for all kernels until you know your updates work…

    Anyways, switching to uvesafb didn’t solve my problem: grub is fine but my monitor goes black after the first messages from kernel. I can login blindly and run startx. Then when in X I can switch to virtual console and if using vesafb or uvesafb, everything is fine. With VGA console even that doesn’t work.

    So, without X I have no working console. If I ever screw up so that X can’t start, the situation is bad. This is with Debian 9, distro kernel 4.9.82-1+deb9u3, Nvidia drivers 384.111. I have an old 3.16 kernel installed too where I do have a console so I guess I’ll be keeping that around as a fallback.

  • Leave a Reply

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

    This site uses Akismet to reduce spam. Learn how your comment data is processed.