43

I've got an Ubuntu server that boots up in text mode. It rarely has a screen or keyboard attached to it, but when I do attach a screen, I usually have to attach a keyboard too, because the darn console mode screen saver will be on and I'll need to hit a key to see what's going on.

I'm aware that the setterm command can disable this, but it's a per-session thing. How can I make it so the machine never ever blanks the screen in text mode, even when it's first booted up and sitting at the login prompt?

raldi
  • 987
  • 4
  • 11
  • 13
  • Seems to be nicely answered over at askubuntu: http://askubuntu.com/questions/138918/how-do-i-disable-the-blank-console-screensaver-on-ubuntu-server – Roy Oct 15 '12 at 20:12
  • I wrote of two different approaches that I needed for various RHEL distributions. One of them may help you with Ubuntu: http://superuser.com/a/1004931/197972 – David C. Nov 24 '15 at 17:29

6 Answers6

23

In Ubuntu 12.10 and earlier the console-tools package allows console options to be controlled.

To turn off screen blanking and powerdown, set BLANK_TIME and POWERDOWN_TIME to 0 in /etc/console-tools/config. If you'd prefer not to modify the config file, the same effect can be achieved by creating a new file in /etc/console-tools/config.d containing the following:

BLANK_TIME=0
POWERDOWN_TIME=0

The name of the file in config.d must consist entirely of upper and lower case letters, digits, underscores, and hyphens.

Phil Ross
  • 7,009
  • 2
  • 23
  • 19
  • How you know that? I've been scouring the Internet all morning looking for the documentation for /etc/console-tools and haven't been able to find any. – raldi May 01 '10 at 21:28
  • 10
    Word of warning with this: I installed console-tools on ubuntu server 12.04, did the above config and it completely tanked it... Not sure what I did wrong, but if it happens to anyone else (and you're crap at servers like me!), boot to recovery -> root prompt -> mount -o remount,rw / -> apt-get remove console-tools -> reboot – BaronVonKaneHoffen Sep 20 '12 at 12:47
  • This does not exist on ubuntu 18.04 :( - any alternatives? – Roman Gaufman Nov 09 '18 at 19:18
17

Or you use /etc/kbd/config to set up (depends on your system, what is installed)

BLANK_TIME=0
BLANK_DPMS=off
Thomas Creutz
  • 171
  • 1
  • 2
15

The parameter is controlled via the kernel command line, using setterm merely alters the runtime settings. To disable it system wide you can alter your kernel boot command line by appending it with "consoleblank=0" in your boot configuration (grub/lilo).

If something during boot setterm's it then it will override the value.

Matthew Ife
  • 22,927
  • 2
  • 54
  • 71
  • 3
    As seen on http://superuser.com/questions/152347/change-linux-console-screen-blanking-behavior ! – codehead Oct 18 '12 at 13:14
  • Using grub2 it could be added in /etc/default/grub `GRUB_CMDLINE_LINUX_DEFAULT="consoleblank=0"` and then updating grub config with `grub[2]-mkconfig -o /boot/grub/grub.cfg`. Or it could be embedded in built-in kernel command line while configuring and compiling kernel manually. – user3132194 Oct 30 '14 at 07:44
8

If you add the setterm command to /etc/rc.local, it should take effect for all virtual consoles, whether or not a user is logged into them. E.g.:

setterm -blank 0
James Sneeringer
  • 6,755
  • 23
  • 27
  • That doesn't seem to actually work in rc.local. – raldi May 01 '10 at 20:09
  • It's worked for me in the past on RedHat-type systems. It could be that Debian/Ubuntu load `rc.local` at a slightly different time than RH. Sorry about that. – James Sneeringer May 01 '10 at 21:33
  • Does not work on CentOS 6.3. Screen continues to blank out after 10 minutes. – Michael Hampton Oct 13 '12 at 04:16
  • 1
    I found that this worked for RHEL 5 and 6 (`/bin/setterm -blank 0 -powerdown 0 -powersave off`), but not for 7. Success or failure probably depends on your distribution and the console environment at the time rc.local is executed. – David C. Nov 24 '15 at 17:31
  • I get this < ~$ sudo setterm -blank 0 setterm: terminal xterm-256color does not support --blank – Roman Gaufman Nov 09 '18 at 19:19
4

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";
Chris Pick
  • 201
  • 1
  • 4
  • Your answer would be a lot better if you actually described what is going on here. Just giving huge command like that with no explanation isn't very useful. – Zoredache Oct 13 '12 at 03:01
  • @Zoredache you're right, I've added an explanation. Thanks for the feedback. – Chris Pick Jan 24 '13 at 01:37
2
daxroc
  • 274
  • 1
  • 7