Monday, April 28, 2014

Is your getty (tty) a black screen?

For those running Linux who have ever been without a graphical user interface (GUI) have most likely gotten to know and love getty's. Getty is short for "get teletype", it's a program that manages physical or virtual terminals (TTY's). When it detects a connection, it prompts for a username and runs the 'login' program to authenticate the user.

Within Ubuntu based distributions there are a total of 7 tty consoles that a user can log into but note that tty7 has the X server running on it. If you ever want to get back to your GUI desktop from a tty console than you would merely hold ctrl and alt and then hit the f7 key and that should lead you to your desktop assuming your X server is properly configured and running. You get to getty consoles by holding ctrl and alt keys and then hitting the function number key that corresponds to the getty console you want to use, f1 is getty 1. So if you wanted to log into a console at tty4, you would hold ctrl and alt and then hit the f4 key. You can see how many getty's your system has running by issuing the following command
ps aux | grep tty
I am running Xubuntu 13.10 and this is the output of the above command
root      1071  0.0  0.0  23016   968 tty4     Ss+  19:09   0:00 /sbin/getty -8 38400 tty4
root      1079  0.0  0.0  23016   960 tty5     Ss+  19:09   0:00 /sbin/getty -8 38400 tty5
root      1098  0.0  0.0  23016   968 tty2     Ss+  19:09   0:00 /sbin/getty -8 38400 tty2
root      1099  0.0  0.0  23016   972 tty3     Ss+  19:09   0:00 /sbin/getty -8 38400 tty3
root      1102  0.0  0.0  23016   968 tty6     Ss+  19:09   0:00 /sbin/getty -8 38400 tty6
root      1261  3.8  1.8 262128 152288 tty7    Rs+  19:09   0:23 /usr/bin/X -core :0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
root      1391  0.0  0.0  77984  2184 tty1     Ss   19:09   0:00 /bin/login --    
ubu       2812  0.0  0.0  30108  4016 tty1     S+   19:10   0:00 -bash
ubu       3339  0.0  0.0  25424  1668 pts/0    S+   19:14   0:00 man getty
ubu       3416  0.0  0.0  16644   948 pts/4    S+   19:19   0:00 grep --color=auto tty

Tty consoles are best used for when you're uninstalling a graphics driver because you can't uninstall a driver that's in use by your X server. For example, I use the Nvidia binary from their website so after I download the .run file I go to tty1, stop my X server by stopping lightdm, run the .run file with root privileges and then when it's done installing I will restart the computer using sudo shutdown -r now so that it restarts the computer using the newly installed driver.

The black tty consoles are usually caused because the graphical text-mode resolution set at boot is not compatible with your video card but there may be other reasons that I am unaware of. I will show you how to use uvesafb (it's a framebuffer) and get a high resolution console so that you can actually use them and they aren't just a black screen of nothing.

It involves installing a package and changing your grub config file as well as some other files. Everyone's video card will support different resolutions so if a resolution isn't working for you than try a lower one until you get text within your tty consoles. If you don't want to just guess than you can use vbeinfo from within grub which will show you the resolutions that are supported. So when grub appears, hit the 'c' key and then type in vbeinfo and hit enter. If your grub doesn't normally appear than you can get it to show by holding the shift key while your computer boots. Note down the largest screen resolution that you would like your tty consoles to be. Mine was 1680x1050.

Let's get to fixing. Open a terminal. The first command is to install the v86d package so that we can use  uvesafb.
sudo apt-get install v86d
Next we need to edit the grub config file.
gksudo gedit /etc/default/grub
This will open the grub config file using the text editor called gedit. If you're using Xubuntu substitute gedit with mousepad or leafpad and if using Kubuntu then your text editor is kate I believe. Now that you're in the grub config file you need to make the following 3 different lines look like mine but using your resolution.
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset video=uvesafb:mode_option=1680x1050-24,mtrr=3,scroll=ywrap"
GRUB_CMDLINE_LINUX="vga=0x0369"
GRUB_GFXMODE=1680x1050
You'll need to look up your vga code for the resolution you want to use, google is your friend here. Once you're done make sure you save the file and then close it. Now we need to update the kernel modules file. Using the following command
gksudo gedit /etc/initramfs-tools/modules
Within that file you want to add the following line
uvesafb mode_option=1680x1050-24 mtrr=3 scroll=ywrap
Again make sure you save the file before closing it. Now we need to tell the system to use the framebuffer for your splash screen by issuing the following command. If you're not using a splash screen than I don't believe you need to perform this step. Despite me removing quiet and splash from my kernel boot line because I like seeing scrolling text in case there are any errors I still performed this step but it's up to you. This command will create a file in that location with that 1 line in it of FRAMEBUFFER=y
echo FRAMEBUFFER=y | sudo tee /etc/initramfs-tools/conf.d/splash
Now that we have updated the config files we need to get those cofigurations into each bootable kernel and we do that by issusing the following commands
sudo update-grub2
sudo update-initramfs -u
And that's it, if you restart your machine you should now have 6 high resolution consoles to use, tty1 thru tty6.

No comments: