44

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.

quack quixote
  • 43,504

8 Answers8

58

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 (The kernel's command-line parameters):

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

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.)
quack quixote
  • 43,504
12

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

wfaulk
  • 6,307
Catherine
  • 16,610
3

On my systems (various releases of RedHat Enterprise Linux), I have found that different approaches are needed.

For my RHEL 5 and 6 systems, I am able to add the line

/bin/setterm -blank 0 -powerdown 0 -powersave off

to /etc/rc.local. This disables the console screen blanking at system startup.

I found that this does not work on RHEL 7 systems. On RHEL7, running setterm from rc.local causes an error to be generated:

setterm: $TERM is not defined.

The command works from an interactive shell, where $TERM is defined (as linux). If I force setterm to use it:

/bin/setterm -term linux -blank 0 -powerdown 0 -powersave off

Then I get a different error:

setterm: cannot (un)set powersave mode: Inappropriate ioctl for device

Even though the same command works fine from an interactive session. Setting the consoleblank kernel parameter worked.

On RHEL7, edit /etc/default/grub and append consoleblank=0 to the GRUB_CMDLINE_LINUX parameter. Then run grub2-mkconfig -o /boot/grub2/grub.cfg and reboot.

I haven't tried setting consoleblank on RHEL5 or 6.

David C.
  • 1,077
3

Linux Console Private CSI Sequences

To set sleep mode/screensaver entering time (where X is a time in minute; 0 = never):

(from serial console)

echo -e '\033[9;X]' > /dev/tty1    

or (from framebuffer console)

echo -e '\033[9;X]'    

or to set it at each boot, use /etc/inittab:

tty1::sysinit:echo -e '\033[9;X]'

refs:

yurenchen
  • 585
3

If anyone is looking for another possible solution for Debian (possibly not Ubuntu):

In /etc/kbd/config, look for a setting called "BLANK_TIME":

# screen blanking timeout.  monitor remains on, but the screen is cleared to
# range: 0-60 min (0==never)  kernels I've looked at default to 10 minutes.
# (see linux/drivers/char/console.c)
BLANK_TIME=30

Change it to 0, this will disable it:

BLANK_TIME=0

Tested on Debian 6 and 7.

basic6
  • 2,837
2

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";
1

It appears that Linux Mint has their own driver for the AMD Ryzen video and it has a problem with blanking the video after a short time. After trying all the suggestions from the forum with no success, I noticed on the information that AMD uses Nvidia drivers, so I downloaded a Linux driver from Nvidia and installed it. The video works fine now.

-2

Adding gnome-screensaver-command --exit to my .profile file fixed this problem for me on Debian Linux (Wheezy).

Thought I would add this to help others who are pulling their hair out trying to stop screen-blanking.

A checkbox titled "Dim screen to save power" is malfunctioning. Even unchecked, it will STILL blank the screen according to the selected inactivity time.

UPDATE: I actually needed sleep 30 && /usr/bin/gnome-screensaver-command --exit & to make it work properly. The GNOME screensaver seems to start long after .profile has been processed.

phuclv
  • 30,396
  • 15
  • 136
  • 260