43

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.

1

8 Answers 8

53

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.)
7
  • 4
    I'd like to note that setterm -blank X did not work for me from within tmux, but worked perfectly when I exited tmux before running the command.
    – Cody Hess
    Aug 5, 2014 at 1:47
  • 2
    If you are using grub2 as a bootloader, you could add this kernel parameter in /etc/default/grub GRUB_CMDLINE_LINUX_DEFAULT="consoleblank=0" and then update your grub config with grub[2]-mkconfig -o /boot/grub/grub.cfg. Oct 30, 2014 at 7:39
  • 1
    3] for setterm -powerdown is only the half true: setterm -powerdown 3 | hexdump -c returns 033 [ 1 4 ; 3 ]. Unsure what should interprete this escape sequence... Jan 8, 2015 at 12:36
  • 1
    Depending on your distribution and where you want the change to take effect, some of these options may not work. I found that setterm in rc.local works great for RHEL 5 and 6, but not 7.
    – David C.
    Nov 24, 2015 at 17:10
  • 2
    Since linux 4.12 the consoleblank default is 0, i.e. disabled: tty: Disable default console blanking interval
    – Stefan
    Jul 8, 2022 at 10:08
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).

6
  • 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? Jun 14, 2010 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.
    – Catherine
    Jun 14, 2010 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.) Jun 19, 2010 at 6:43
  • 1
    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.
    – Catherine
    Jun 19, 2010 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. Jun 19, 2010 at 16:58
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.

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

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.

1
  • 2
    RHEL7 uses systemd; rc.local is not connected to a terminal by default. I think you can add </dev/tty1 >/dev/tty1 or something to make it work
    – sourcejedi
    Jul 7, 2018 at 18:04
2

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:

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.

1
  • 3
    This is about console screen blanking, not Gnome screensavers.
    – basic6
    Jul 3, 2015 at 8:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .