Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How do I change the screen blanking behavior on Linux virtual terminals?

For example, if I switch to a VT from X, login, and leave the system alone for 5 minutes or so, the screen will blank like a screensaver. It comes back with any keypress, like a screensaver.

Mostly I just want to change the timeout, but I'm also interested in other settings.

If it helps, one of my systems is running Ubuntu 10.04 with the stock graphics drivers. fbset shows the console using the radeondrmfb framebuffer device.

share|improve this question
1  
Hope this helps you, I found this when I met the same question askubuntu.com/questions/138918/… –  user168558 Oct 29 '12 at 5:22
add comment

3 Answers 3

setterm from @whitequark's answer is a reasonable userspace tool, but it's not the whole story.

The default console blanking behavior is baked into the kernel at compile time. It is configurable at boot time with the paramater consoleblank=, or in userspace with setterm. From the kernel documentation (kernel-parameters.txt):

consoleblank=  [KNL] The console blank (screen saver) timeout in
               seconds. Defaults to 10*60 = 10mins. A value of 0
               disables the blank timer.

Here are the options, their defaults on my Ubuntu system, and their spheres of influence:

  • setterm -blank [0-60]; always reports 0 when queried; effective when run on a real VT; affects all real TTYs; not effective when run in screen sessions on a VT.
  • setterm -powerdown [0-60]; always reports "3]" (??); doesn't seem to have any effect. Ubuntu kernels don't enable APM_DISPLAY_BLANK, and this could be related.
  • consoleblank=N; defaults to 600 (10 minutes); affects all real VTs; affects screen sessions in a VT; no way to set while running.

So my options for changing the default is one of the following:

  1. Add setterm -blank X (X in minutes, 0 to disable) to a shell init file like .bashrc.
  2. Add setterm -blank X to /etc/rc.local.
  3. Add consoleblank=Y (Y in seconds, 0 to disable) to the kernel commandline by adding it to the parameter lists in /etc/default/grub, either GRUB_CMDLINE_LINUX or GRUB_CMDLINE_LINUX_DEFAULT. (Don't forget to update-grub.)
share|improve this answer
add comment

Try setterm -blank $minutes (or pass 0 to disable); -powersave option may also be related. setterm has a plenty of other useful options, too.

If you want to set these attributes on system startup, consider writing an initscript. This is just a script placed in /etc/init.d directory. Let it be called setterm:

#!/bin/sh
[ "$1" == "start" ] || exit 0 # only initialize everything when called as /etc/init.d/setterm start
for term in /dev/tty[0-9]*; do # select all ttyNN, but skip ttyS*
    setterm -blank 0 >$term <$term
    setterm -powersave off >$term <$term
done

Then make it executable:

# chmod +x /etc/init.d/setterm

And finally, create the /etc/rcX.d symlinks (the Debian way):

# update-rc.d setterm defaults

(If you'll get tired of that behavior, do # update-rc.d -f setterm remove. Note that -f must be the first argument).

share|improve this answer
    
hrm. seems useful for on-the-fly, tho it seems on my test Ubuntu system it's actually the -powerdown setting that's in effect. what about setting an on-boot, system-wide default? is running setterm -blank X or setterm -powerdown Y in /etc/rc.local (or ~/.bashrc) reasonable? –  quack quixote Jun 14 '10 at 17:25
1  
Yes, but only if rc.local actually works. (Recent upstart migration screwed up some things, through it apparently exists and works on my system.) Otherwise you should create an initscript. That's easy: in our case, it must initialize everything when passed start as first argument, and do nothing otherwise. I'll describe that in my answer. –  whitequark Jun 14 '10 at 17:36
    
the command setterm -blank X >/dev/ttyN doesn't seem to work, so i don't think the initscript concept will work. ran across a boottime parameter tho and did some more research. i seem to be wrong about -powerdown and -powersave; haven't fully tested but those aren't working on my system. setterm -blank X works, only from a real VT, and affects all VTs, so running once via /etc/rc.local is reasonable. (Upstart doesn't take away rc.local, just the /etc/rcX.d stuff.) –  quack quixote Jun 19 '10 at 6:43
    
Ahem. Seems that setterm emits escape sequences on stdout, but checks TTY type with stdin: I just checked, and setterm ... >/dev/ttyN </dev/ttyN works as intended. –  whitequark Jun 19 '10 at 14:31
    
that makes sense, and it works (from a real TTY), but what's the point of using that syntax at all? (1) still doesn't work from within screen (or potentially other PTYs), which is where specifying a /dev/ttyN would be useful; (2) setting one VT affects all, so no need for the initscript loop. –  quack quixote Jun 19 '10 at 16:58
show 1 more comment

If you are running a newer Ubuntu that uses upstart, you can use:

for file in /etc/init/tty*.conf; do tty="/dev/`basename $file .conf`"; echo "post-start exec setterm -blank 0 -powersave off >$tty <$tty" | sudo tee -a "$file"; done

A little explanation of what's going on here:

Newer Ubuntu versions use upstart for system startup. With upstart, the Linux consoles are setup with config files stored within /etc/init. The command above starts by iterating over each of those config files:

for file in /etc/init/tty*.conf;

The tty's upstart config file name in $file is used to build the name of the tty device:

tty="/dev/`basename $file .conf`";

An upstart "post-start" command is built that runs "setterm" to disable screen blanking and power saving after the tty has been started:

echo "post-start exec setterm -blank 0 -powersave off >$tty <$tty"

And finally that command is appended to the upstart config file:

| sudo tee -a "$file";
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.