38

Is it possible to set the default display brightness so you don't have to re-adjust it everytime you reboot? My laptop display is killing my eyes at the login screen already because it starts at 100% brightness every time.

5
  • Try this askubuntu.com/questions/481413/… Jul 6, 2014 at 21:30
  • 1
    @jeremy why don't you accept the ans as my answer seems to be a valid one Dec 15, 2014 at 19:25
  • @Jeremy Can you mark one of the answers as accepted? It's good for your profile stats, too. Apr 1, 2016 at 17:44
  • @Stormvirux That question is a duplicate of this one, since it was asked later. (Hence my flag on the other question).
    – wjandrea
    Jun 13, 2017 at 19:54
  • 1
    @wjandrea age does not matter - views, votes and quality are more important. But I am voting to leave open since the other question is more specific (and dupe-all-the-vaguely-similar-posts-that-already-have-answers is not a strategy I like...)
    – Zanna
    Jun 14, 2017 at 4:28

6 Answers 6

26

Review of solutions and offering a (hopefully) better one

Previous solutions

/sys/-based : good for console

@gan

This works echo 5 > /sys/class/backlight/acpi_video0/brightness but does not play well with X. More specifically, X is not aware about your preferred settings and you may end up needing to set the brightness manually again at least once, similar to bug #1042359 .

setpci-based : system-dependent, dangerous

@erickjohncuevas

Solutions based on things like setpci -s 01:00.0 F4.B=50 are dangerous. There, 01:00.0 is actually an ID targeting a particular board on the PCI bus. And it is system-dependent. That means blindly following this may write configuration registers on some other boards where it may mean anything, from just nothing to crashing the system at some point in the future. Anyway it does not play well with X either.


Proposed solution

Advantages/drawbacks

The solution below has these advantages:

  • plays nice with X which is fully aware of the settings chosen
  • is more readable, thus maintainable
  • does not contain system-specific address, etc, and as a result may work on a wider range of hardware (e.g. where kernel does not know about backlight, or that don't even use PCI-based video board, think Ubuntu for ARM )

It assumes: Ubuntu using lightdm (that is 11.10 and beyond)

It only sets backlight when lightdm starts. But it can be combined with the /sys-based solution above if you really need to set backlight earlier.

The solution

Copy-paste of these commands should do what you need (sudo will probably ask your password).

  1. Install xbacklight if it is not already installed (it is a small package).

    sudo apt-get install xbacklight
    

    You should test xbacklight on the command-line to see if it works. For example:

    xbacklight = 100 ; sleep 2 ; xbacklight = 30
    

    Try to figure out a suitable value for your hardware and lighting conditions.

  2. Create a small script running xbacklight.
    You can change the =30 into another value if you wish.
    The || true ensures that if xbacklight fails for any reason, X can still start.

    sudo bash -c '{
        echo "#!/bin/bash"
        echo "xbacklight =30 || true"
    } >> /etc/lightdm/display-setup-script.sh '
    
  3. Make the script executable

    sudo chmod a+rx /etc/lightdm/display-setup-script.sh
    
  4. Instruct lightdm to run the script when starting X.
    Specifically, this adds a line display-setup-script in a lightdm configuration file, but only if there is not one already.

    if grep -ri ^display-setup-script /etc/lightdm/
    then 
      echo "There may be already a display-setup-script. It may already do what you need. Else please adjust manually" ; 
    else 
      if [[ -d /etc/lightdm/lightdm.conf.d ]]
      then
        # Ubuntu 13.10 and above have lightdm.conf.d. 14.04 *only* has lightdm.conf.d.
        DEST_CONF_FILE=/etc/lightdm/lightdm.conf.d/20-default-brightness.conf
      else
        # Ubuntu 12.04, 12.10, 14.10 do not have lightdm.conf.d, so we change main configuration file
        DEST_CONF_FILE=/etc/lightdm/lightdm.conf
      fi
      echo "Writing into $DEST_CONF_FILE"
      sudo bash -c "{ 
          echo '[SeatDefaults]' ; 
          echo display-setup-script=/etc/lightdm/display-setup-script.sh ; 
      } >> $DEST_CONF_FILE" ; 
    fi
    

May be tested by restarting lightdm from a root session on the console. Or, more simply, by rebooting.

Tested on Ubuntu 12.04, 12.10, 13.10, 14.04, 14.10, 16.04.

Please provide feedback about your experience.

8
  • 1
    On a freshly installed Ubuntu 12.10, copy-paste of the lines above just works. Jan 2, 2013 at 15:38
  • Works for me too.
    – Pawelmhm
    Sep 21, 2013 at 11:01
  • On a freshly installed Xubuntu 13.10, copy-paste of the lines above just works. Nov 7, 2013 at 5:41
  • Adjusted just now for Ubuntu 14.04, tested, works. If xbacklight fails, does not prevent X from starting. Jul 6, 2014 at 21:46
  • 1
    Works on 14.10. (Strangely enough, Ubuntu 14.10 reverts to having /etc/lightdm/lightdm.conf but not /etc/lightdm/lightdm.conf.d. This solution still works anyway.) Aug 13, 2015 at 9:45
9

source

Actually echoing some value to doesn't help in the brightness as the value will differ from system to system.

First you need to set the brightness of the screen to the level comfortable to you, which can easily be done in System SettingsBrightness & Lock or by using the function keys.

Now go to /sys/class/backlight/<folder> (my folder is intel_backlight)

screen shot of the folder

In this folder you can see the actual_brightness file and the max_brightness file. (If you have made any changes to the brightness after opening this file, don't forget to refresh (using Ctrl+R or F5) to see the actual current settings.)

Now we need the same value as in the brightness every time we start our system. This can be done by changing every time the value in this folder at the startup. We need to change the rc.local file.

First type these commands in the terminal (which can be opened by searching for Terminal in the dash or by pressing Ctrl+Alt+T):

sudo -i
gedit /etc/rc.local

and add the line

echo 900 > /sys/class/backlight/intel_backlight/brightness

Replace 900 with whatever value you need (that is, the value you got from the above procedure). Also replace intel_backlight with the folder name from /sys/class/backlight/.

For example, my /etc/rc.local:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
rfkill block bluetooth
echo 900 > /sys/class/backlight/intel_backlight/brightness

exit 0

As an aside, I added the line rfkill block bluetooth to my rc.local file as I don't use Bluetooth at all but Ubuntu starts Bluetooth every time it reboots (even if the Bluetooth was off before). You can also add it, and just in case you want to use Bluetooth you can always start it again, even if this line is in your rc.local).

Don't change the value of exit 0 in the ending. If that line doesn't exist, add it.

Now even if you have restarted the system you will have the same value that you need.

Be careful to not put a brightness value greater than max_brightness, as that will throw you an error saying that it is an invalid argument.

5
  • 1
    Thanks dhanvi. This not only solve brightness problem but bluetooth as well.
    – VRR
    Apr 4, 2015 at 13:34
  • the rfkill block bluetooth i have added it to the this file as i don't want to on my Bluetooth every time i started a system hope this too helped you :) Apr 5, 2015 at 14:05
  • 1
    This is an excellent post. Thanks for sharing this method! I'd already used this to stop bluetooth starting up every time - and can confirm it works. Aug 20, 2015 at 21:29
  • Didnt work for me on Ubuntu 20.1 Jul 11, 2021 at 13:03
  • Didn't work for me on Ubuntu 22.04
    – Maurycyt
    Sep 23 at 17:32
3

It isn't default. Whenever I reboot my brightness is set to 100%. Then I set the brightness with command:

$ echo 5 | sudo tee /sys/class/backlight/acpi_video0/brightness
1
  • 3
    Changing the permission of /sys is a very bad approach as /sys is actually a virtual FS provided by kernel itself, changing permission of /sys has various security implications. Use sudo to write to the file if needed..
    – heemayl
    Aug 19, 2015 at 20:43
1

Have you look at redshift? It's designed for another purpose (make the screen less bluish at night), but it might solve your problem as well.

To install:

sudo apt-get install redshift

My configuration file (~/.config/redshift.conf):

[redshift]
;temp-day=5700
;temp-night=4600
brightness-day=1.0
brightness-night=0.75
gamma=0.8
adjustment-method=vidmode
location-provider=manual

[manual]
lat=63.81415
lon=20.41742

If you change brightness-day and brightness-night to a value you like and set temp-day and temp-night to the same value, you will effectively use redshift to set your brightness only.

To make redshift autostart at login, select Applications/System tools/Preferences/Startup applications/Add. Name: redshift. Command: /usr/bin/redshift.

4
  • Not sure what you mean. redshift changes the color temperature of the screen and it may also change its brightness. Aug 25, 2015 at 5:57
  • brightness doesn't work as you think see this jonls.dk/redshift and known bugs and limitations Aug 27, 2015 at 6:34
  • 4
    Redshift has a brightness adjustment setting, but it does not work the way most people might expect. In fact it is a fake brightness adjustment obtained by manipulating the gamma ramps, which means that it does not reduce the backlight of the screen. Preferable only use it if your normal backlight adjustment is too coarse-grained. Aug 27, 2015 at 6:34
  • Good idea though. Do we have similar apps that actually work. Reducing the gamma during the night or before sleeping is extremely important
    – nyxee
    Jan 9, 2017 at 22:43
1

Once you have your preferred brightness set, you can follow the answer by N0rbert here: Brightness is reset to Maximum on every Restart. In summary:

sudo add-apt-repository ppa:nrbrtx/sysvinit-backlight
sudo apt-get update
sudo apt-get install sysvinit-backlight

sudo service sysvinit-backlight status # Show current brightness levels and values saved in files
sudo service sysvinit-backlight start # Set saved levels from files
sudo service sysvinit-backlight stop # Save current levels to files
-5

This should do the trick:

System settings -> Screen -> Brightness

Use the slider to adjust default setting.

enter image description here

3
  • 13
    Doesn't "stick" for reboots, at least for me on Precise (12.04) for an HP Envy Ultrabook
    – hobs
    Aug 11, 2012 at 18:14
  • 1
    Same with Acer Aspire One Nov 11, 2014 at 13:40
  • As this answer does not work for anybody, please delete it. This will also reverse the negative reputation from the downvotes.
    – user364819
    Jun 13, 2017 at 21:13

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