155

The brightness of my laptop is reset to max on every restart. I tried the solution provided at this website but had no luck.

This command

cat /sys/class/backlight/acpi_video0/max_brightness

Returns

cat: /sys/class/backlight/acpi_video0/max_brightness: No such file or directory

Then I found that I don't have a folder named acpi_video0, but a folder called intel_backlight:

screenshot of /sys/class/backlight/intel_backlight in Nautilus

Every time I increase or decrease the brightness using the brightness control keys, the values in brightness and actual_brightness get updated.

Is there any method I could follow to set the brightness to a fixed value on every boot and vary it as and when I need it using the brightness control keys?

wjandrea
  • 14,236
  • 4
  • 48
  • 98
b-ak
  • 4,350

20 Answers20

120

You could try adding a line to /etc/rc.local that will set the desired brightness level. To edit the file, run

sudo -H gedit /etc/rc.local

and add the following

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

so that the end result looks like this

#!/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.

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

exit 0

Substitute X by the desired brightness level.

In case /etc/rc.local doesn't exist, as is the case with new Ubuntu releases, you'll need to create it, and make eecutable with the following commands:

printf '%s\n' '#!/bin/bash' 'exit 0' | sudo tee -a /etc/rc.local
sudo chmod +x /etc/rc.local

PS: Alternatively, there may be /sys/class/backlight/acpi_video0/brightness instead of the above. Brightness levels vary wildly, and may range from 0 to 10 or to 1000. To find the maximum value, try

cat /sys/class/backlight/acpi_video0/max_brightness
or
cat /sys/class/backlight/intel_backlight/max_brightness
mikewhatever
  • 32,638
  • I just want to understand things around here. This change, is it because I have Intel HD3000 graphics ?? – b-ak Jun 16 '12 at 10:59
  • 5
    Probably. Different computers will have different entries in /sys/class/backlight/, and figuring out the right location, basically, solved the problem. – mikewhatever Jun 16 '12 at 13:28
  • 9
    X is the desired brightness level on a scale of 0-10 or 0-100? – Rakib Oct 14 '12 at 15:37
  • 9
    Depends. Different models have different scales. I only had to deal with 0-7. Check the current level by running cat /sys/class/backlight/intel_backlight/brightness. It's a good idea to experiment with several values, if you aren't sure which one is right. – mikewhatever Oct 14 '12 at 23:33
  • 2
    Doesn't work for me in 12.04? –  Jul 01 '13 at 18:11
  • better solution this one: http://askubuntu.com/questions/66751/how-do-i-set-default-display-brightness – Akronix May 10 '14 at 10:38
  • 1
    mine scales from 0-937 – osa Jun 03 '14 at 19:01
  • After fighting with this issue over several nights, this saves my life. – Jingguo Yao Oct 31 '14 at 18:48
  • Mine goes from 287 to 4882. How oddly specific. – The Unknown Dev Feb 06 '16 at 01:28
  • I have rc0.d ~ rc5.d in /etc, could anyone tell me which directory I should put this script into? – Searene Dec 05 '16 at 12:23
  • HP 250 G6, Intel Backlight, scales from 0 - 7125 – Felipe Francisco Oct 19 '17 at 10:49
  • It would be cleaner to install sysfsutils and append an entry class/backlight/intel_backlight/brightness = 100 (or whatever your preferred brightness value is) to /etc/sysfs.conf. – David Foerster Apr 08 '18 at 08:47
  • 1
    Different computers can have different hardware due to which you should check /sys/class/backlight/ directory for your hardware. For me /sys/class/backlight/nvidia_0/actual_brightness worked! – Ashish Jun 26 '20 at 03:03
  • No rc.local in Ubuntu 20.04 LTS – fikr4n Jun 09 '21 at 05:24
  • When I navigated to sys/class/backlight I m getting 2 directories with Soft Links pointing to some other files as follows :

    lrwxrwxrwx 1 root root 0 Sep 7 12:13 amdgpu_bl0 -> ../../devices/pci0000:00/0000:00:08.1/0000:05:00.0/backlight/amdgpu_bl0

    lrwxrwxrwx 1 root root 0 Sep 7 12:13 nvidia_wmi_ec_backlight -> ../../devices/pci0000:00/PNP0C14:00/wmi_bus/wmi_bus-PNP0C14:00/603E9613-EF25-4338-A3D0-C46177516DB7/backlight/nvidia_wmi_ec_backlight

    Both folders have actual_brightness and max_brighness values. Not sure which one to edit

    – user76170 Sep 07 '22 at 07:06
  • @user76170 That's a tricky one. Do you have both AMD and Nvidia GPUs? Which one is in use? I'd try AMD first. – mikewhatever Sep 07 '22 at 16:26
  • created a /etc/rc.local new file using sudo and wrote this : echo 150 > /sys/class/backlight/amdgpu_bl0/brightness (trying this with AMD first). When I saved and restarted Ubuntu, the brightness level hadn't reduced. Then I checked the values by navigating to folder /sys/class/backlight/amdgpu_bl0. and tried checking brightness using vim brightness. It displays 255. and beneath shows file is read-only. – user76170 Mar 17 '23 at 17:54
25

I converted my small script for saving and restoring backlight (brightness) level to Ubuntu package. It is located in my PPA and named sysvinit-backlight.
It contains sysvinit init-script, placed in /etc/init.d/sysvinit-backlight.
It is compatible with Ubuntu 12.04 LTS and 14.04 LTS.

For newer versions of Ubuntu my PPA is not needed as they use builtin systemd-backlight service.

You can install my script with the following commands:

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

You can remove it by

sudo apt-get purge sysvinit-backlight

Please note: if you have installed the previous version of my script, please remove it by

sudo rm /etc/rc?.d/?25backlight /etc/init.d/brightness /etc/rc?.d/?25brightness

The script functionality is:

  • save backlight (brightness) levels of all video adapters and keyboard on reboot and shutdown (runlevel 0 and 6)
  • load backlight (brightness) levels for all video adapters and keyboard on boot (runlevels S, 1, 2, 3, 4 and 5)

The script options are:

  • sudo service sysvinit-backlight status (show current brightness levels and saved in files values)
  • sudo service sysvinit-backlight start (set saved levels from files)
  • sudo service sysvinit-backlight stop (save current levels to files)

You can contact me here or on launchpad.

N0rbert
  • 99,918
  • 4
    I reported a bug about including such initscript to default Ubuntu installation - http://bugs.launchpad.net/bugs/1270579. – N0rbert Jan 19 '14 at 13:41
  • Works perfectly for my Dell laptop on Ubuntu 14.04. As the laptop has a on-chip graphics adapter plus another adapter (that is used by default), I just had to change /acpi_video0/ to /acpi_video1/. – BurninLeo Sep 19 '14 at 16:03
  • This script is practical. Worked for me too on my lenovo flex 2. I think it should also be included in default Ubuntu or Linux mint installs. – answerSeeker Oct 25 '15 at 03:16
  • This script no longer works in 16.04+ – answerSeeker Jun 21 '17 at 03:33
  • answerSeeker This script should not work in 16.04+, it is unneeded here. Use standard systemd-backlight@.service. – N0rbert Jun 24 '17 at 15:48
  • @N0rbert there's systemd-backlight@backlight: in 20.04 but inactive (dead) – fikr4n Jun 09 '21 at 05:27
24

Easiest way:

  1. Open a terminal window.

  2. Type in the following command then hit Enter after it.

    sudo apt-get install xbacklight
    
  3. Open the Startup Applications Preferences menu.

  4. Click the Add button and add the following information:

    • Name: Brightness
    • Command: xbacklight -set 60
  5. Replace 60 with whatever brightness level you prefer.

Source: Set Startup Display Brightness

wjandrea
  • 14,236
  • 4
  • 48
  • 98
Din
  • 2,081
  • 5
  • 19
  • 20
14

Before try workarounds in rc.local, it is worth to try the following:

  • adding simple: quiet splash acpi_backlight=vendor to grub looks to be enough on my configuration.

    1. sudo gedit /etc/default/grub
    2. replace
      GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
      with
      GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset acpi_backlight=vendor"

    3. sudo update-grub and reboot.

worked on:

  • Ubuntu 12.04 LTS (Asus U31SD-XH51 )
  • Ubuntu 14.04 LTS (Dell 14z)
  • Ubuntu 14.04 LTS (Lenovo g500, remove nomodeset and it will work fine)
Casonade
  • 196
  • 2
    more details http://www.ubuntuka.com/ubuntu-command-line-tricks-set-1/: sudo gedit /etc/default/grub and replace GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" to GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset acpi_backlight=vendor" – tbicr Jun 07 '14 at 05:40
  • Unfortunately it breaks the brightness adjustment from the fn keys on 14.04. – NoBugs Jun 29 '14 at 02:20
  • works for me as well on 14.04 ... fn keys for brightess were not working also previously so ... – Postadelmaga Jul 03 '14 at 09:08
  • This seemed to work fine - for one reboot (even the Fn keys on my Dell laptop worked). But after another reboot the Fn keys brightness did not affect the screen any more. And worse: The wakeup after standby (suspend to RAM) stopped working with a dark screen. – BurninLeo Sep 19 '14 at 15:37
  • GRUB_CMDLINE_LINUX_DEFAULT="nomodeset acpi_backlight=vendor" works for me – Sumit Sep 01 '21 at 09:25
  • Doesnt work in Ubuntu 22.04. Brightness gets resetted to maximum on restart. I have a Dell G15 Ryzen Edition Laptop – user76170 Sep 07 '22 at 07:03
6

I modified the code in /etc/rc.local like this:

Get maximum brightness:

$ cat /sys/class/backlight/intel_backlight/max_brightness
4882

Run gksudo gedit /etc/rc.local and edit the file:

#!/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.

echo 4882 > /sys/class/backlight/intel_backlight/brightness
exit 0

That worked for me.

wjandrea
  • 14,236
  • 4
  • 48
  • 98
  • 4
    I don't get it, what would that do? It's already maximum by default. – JMCF125 Aug 29 '13 at 22:49
  • You should use cat /sys/class/backlight/intel_backlight/brightness 168 instead. I use 168 because my eyes don't hurt at that brightness level – answerSeeker Sep 18 '15 at 16:15
6

Install xbacklight (sudo apt-get install xbacklight) and add

xbacklight -set x

(where 'x' = 0 to 100 desired brightness) to the startup applications via dashboard. For example:

xbacklight -set 50
Eric Carvalho
  • 54,385
Brandex
  • 488
  • 1
  • 7
  • 13
4

The solutions offered here are somehow system-dependent.

A good design is to have one place that takes care of system-dependent details and provide a unified interface. It seems that currently the kernel does not offer such an easy interface through /sys. At X level, though, there is one : xbacklight.

A solution based on xbacklight is offered on How do I set default display brightness?, for 11.10 and up.

Plus, it should not have the problems reported on some areas (e.g. http://ubuntuguide.net/how-to-save-screen-brightness-settings-in-ubuntu-12-04-laptop ) that wrong brightness comes back in some situations.

3

How to debug backlighting:

https://wiki.ubuntu.com/Kernel/Debugging/Backlight

Unfortunately just adding acpi_backlight=vendor doesn't seem to save the default value for my 12.04 Lenovo G575.

grantbow
  • 976
2

I use a Sony Vaio S model and hybrid graphics. I disabled my ATI G card and so my intel HD 3000 serves as my only g card.

I found that setting the brightness value to the file actual_brightness in the intel_backlight folder will help. and the other wont.

for me my minimum brightness value is 236 and maximum is 4648, so you may set a value anywhere between this.

so try this:

echo 236 > /sys/class/backlight/intel_backlight/actual_brightness
wjandrea
  • 14,236
  • 4
  • 48
  • 98
2

My laptop is Compaq Presario CQ62 111TU, installed Ubuntu 12.04. The Following steps worked for me well.

  1. Adjust the screen brightness to your preferred level.
  2. Open Terminal and enter cat /sys/class/backlight/intel_backlight/actual_brightness and take down the value.
  3. Enter cat /sys/class/backlight/acpi_video0/actual_brightness and take down the value.
  4. Enter sudo gedit /etc/rc.local and add these before the last line exit 0 in gedit:

    echo ValueFromStep2 > /sys/class/backlight/intel_backlight/brightness
    echo ValueFromStep3 > /sys/class/backlight/acpi_video0/brightness
    

save and enjoy.

My settings are shown below

#!/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.

echo 478 > /sys/class/backlight/intel_backlight/brightness
echo 0 > /sys/class/backlight/acpi_video0/brightness

exit 0
Eric Carvalho
  • 54,385
  • This worked great for me. All I needed was the /sys/class/backlight/acpi_video0/brightness line. – bmaupin Nov 15 '13 at 16:44
2

I find N0rbert's solution to be the best one, as the script that he's provided allows to restore your previous brightness level on startup.

Although, there was a small modification that I had to introduce to his solution to make it work. Instead of creating symbolic links that he's mentioned, I've provided the following:

ln -s /etc/init.d/brightness /etc/rc0.d/S25backlight
ln -s /etc/init.d/brightness /etc/rc2.d/S25backlight
ln -s /etc/init.d/brightness /etc/rc6.d/S25backlight

Notice, that instead of rcS.d, I've added a symbolic link to rc2.d, which is a runlevel for "Graphical multi-user with networking" (see more). I believe that the reason why the former one doesn't work for me is Ubuntu overriding brightness level after it has been set up by the /etc/init.d/brightness script during S runlevel.

With that subtle change, restoring brightness level works like a charm, especially for Ubuntu 14.04 LTS on Lenovo ThinkPad L540.

falconepl
  • 263
  • 4
  • 10
1

No need to fall into scripting and coding.

Just follow these simple steps:

If screen brightness is stuck at maximum every startup, install xbacklight (sudo apt-get install xbacklight) and add "xbacklight -set x" (where 'x' = 0 to 100 desired brightness) to the startup applications via dashboard. For example, "xbacklight -set 50".

I have set brightness for my laptop to 30.

Source: https://help.ubuntu.com/community/AsusZenbookPrime [Search for word "brightness" and read related paragraphs on this source page.]

Enjoy!!

mikewhatever
  • 32,638
1

I added the following into /etc/rc.local, to manage the display brightness and keyboard backlit and it works perfectly

...
echo 30 | sudo tee /sys/class/backlight/acpi_video0/brightness
echo 3 | sudo tee /sys/devices/platform/applesmc.768/leds/smc::kbd_backlight/brightness

exit 0
j3ffyang
  • 187
1

Use this command to discover your current brightness level:

cat /sys/class/backlight/intel_backlight/brightness

Then, edit rc.local file using this command:

gksudo gedit /etc/rc.local

Add this line before exit 0 line:

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

If this don't solve the problem, can be that something in your system is overwriting the brightness level. Then, you can try add a sleep command to delay the execution of the previous command:

(sleep 10 && echo X > /sys/class/backlight/intel_backlight/brightness)

Source

1

This works on ubuntu 16.10

Create a file brightness.service in /lib/systemd/system with the following contents(Change 100 to whatever brightness you want, roughly it's between 0 ~ 1000).

[Unit]
Description=Lower default brightness

[Service]
ExecStart=/usr/bin/zsh -c "echo 100 > /sys/class/backlight/intel_backlight/brightness"

[Install]
WantedBy=multi-user.target

Enable it.

sudo systemctl enable brightness.

Restart. It will work.

Searene
  • 4,350
0

It is well worth checking the max_brightness files for the absolute maximum values in /sys/class/backlight/intel_backlight and /sys/class/backlight/acpi_video0 directories to avoid setting unusable values.

My Dell Inspiron 5720 uses maximum values of 4882 and 100 respectively. I have set these to 2508 and 52 to prolong battery life. ACPI value in this case is equivalent to the percentage of the maximum brightness.

Editing rc.local works for me. I added comments to clarify how the values were determined. set required brightness with function keys and read values in brightness or actual_brightness files in each of the above Intel / ACPI directories.

0

For mint mate 17, you can set the default brightness by following steps:

  • sudo apt-get install dconf-tools
  • Applications -> System Tools -> dconf tools,
  • search for backlight, find and change following options:

    • brightness-ac
      brightness when use AC powser (charged),
    • brightness-dim-battery
      brightness when use battery (not charged),
Eric
  • 492
0

all replies are helpful but didnt help me what i was trying to achieve. i wanted pre-defined levels of brightness for battery and ac power.

  1. use laptop mode tools from here laptop mode tools
  2. edit the conf file for brightness and replace [values] with the values you want. like "echo 1" for battery.wiki

works for me :)

aish
  • 141
  • 4
0

This is yet another workaround

$ sudo dd if=/dev/tty of=/sys/class/backlight/intel_backlight/brightness
3000

Press Ctrl+D

less typing for fumble fingers...

wjandrea
  • 14,236
  • 4
  • 48
  • 98
0

Change default brightness level in Ubuntu 14. 04 LTS / Brightness is reset to Maximum on every Restart on Ubuntu 14.04 LTS

Here is what i found out.

In my case I had both the folders.

And when I changed the default brightness level, it took the change from the file in the folder acpi_video0. i.e. from the second line of code.

Here is the code that will be helpful for setting the default brightness level for Ubuntu 14.04 LTS.

#!/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.
#
#
#
#if you are changing the default brightness in Ubuntu 14.4 LTS
#the brightness under the folder acpi_video0 is important.
#Because brightness is set from that folder and not from intel_backlight
#(in case of my PC. It may very in others)
#That means you can omit the first echo line.
#However the command lines are given if any one has some problem and doesnot
#have the acpi_video0 folder
echo 1020 > /sys/class/backlight/intel_backlight/brightness
#Under the above given address the range of brightness is from 0 to 4648.
echo 3 > /sys/class/backlight/acpi_video0/brightness
#Under the above given address the range of brightness is from 0 to 7.
exit 0
Greeny
  • 1