screen brightness resets to max after reboot (linux)

Running ubuntu 19.04 with nvidia-graphics-drivers-418 official drivers. I can adjust backlight brightness on my notebook, but when I reboot or poweroff and turn on again, brightness resets to maximum each single time (100). On Windows 10 doesn’t happen, it keeps the previous session backlight level.
I believe this is more a software rather than a hardware thing, any possibility to get it fixed? It’s quite a bit annoying.

The driver doesn’t fiddle with the brightness, the state should be saved/restored by the systemd-backlight service. Might have to be adjusted for your hardware:

I’ts some ubuntu bug then.

It’s a known issue:

Are there more than one backlight controls, i.e. what’s the output of
systemctl list-units --no-pager |grep “systemd-backlight”

I have two graphics cards on the MSI notebook, the Intel graphics provided by the intel hq, and the gtx 1080, which can be enabled or disabled on the BIOS, setting called “MSI VGA MODE”, and can be either “MSI IGPU MODE” or “MSI DGPU MODE”.

When DGPU enabled (GTX 1080), this is the result:

systemctl list-units --no-pager |grep "systemd-backlight" 
  systemd-backlight@backlight:acpi_video0.service                                                            loaded active     exited    Load/Save Screen Backlight Brightness of backlight:acpi_video0               
  systemd-backlight@backlight:nvidia_0.service                                                               loaded active     exited    Load/Save Screen Backlight Brightness of backlight:nvidia_0

Try masking one of them, e.g.
sudo systemctl mask systemd-backlight@backlight:nvidia_0.service
and check if brightness save/restore works. If not, unmask it and mask the other one, test again.

Neither of them work.

In Ubuntu 20.04.2 LTS I solved this problem by creating a cron job:

sudo crontab -e

and including this line at the end of the file:

@reboot (sleep 2 ; echo 80 > /sys/class/backlight/nvidia_0/brightness) &

I found that 2 seconds was enough time to override Nvidia’s reset timing at boot. You can adjust the brightness level (80) to your own preference.

1 Like

Fantastic job, however 2 seconds for me didn’t make the cut, tried 10 and worked perfect. Now I would like to know how to restore brightness that was previously set just before reboot. Any idea? The issue would be to save the brightness to a file before halt/shutdown, either from user interface or command line.

1 Like

This would be great for sure. Not sure of how to do it though at this point, will keep an eye on a solution.

Just found out that an additional fix is needed: even though the code above fixes brightness at boot, it won’t do it when the computer wakes up from sleep/hibernation, Nvidia resets brightness to max again. To fix this, create in addition the following script in a file in the /lib/systemd/system-sleep/ folder:

#!/usr/bin/env bash
case $1 in
echo 80 > /sys/class/backlight/nvidia_0/brightness

1 Like

#!/usr/bin/env bash
[[ $1 = post ]] && echo 80 > /sys/class/backlight/nvidia_0/brightness

just shorter …

cat "$retrieve_file" > "$destination_file"

How to retrieve it… exchange retrieve and destination file.
You could set it on boot i.e. as a one shot systemd unit depending on like graphical-target.

This is how I achieved to restore brightness for my nvidia after power off / reboot:

1–Save brightness–
Create a file in /etc/rc6.d/ starting with K99, so it’s executed latest in shut down:
sudo touch /etc/rc6.d/K99-nvidia-save-brightness
sudo chmod +x /etc/rc6.d/K99-nvidia-save-brightness
Put this content inside that file:

cat /sys/class/backlight/nvidia_0/actual_brightness > /etc/acpi/nvidia-brightness

Brightness will be saved to nvidia-brightness file.

2–Restore brightness after reboot-

sudo crontab -e

Add / edit to it:

@reboot (sleep 10 ; cat /etc/acpi/nvidia-brightness > /sys/class/backlight/nvidia_0>

Thanks to Dr_Cool and this helpful page:
Execute command before shutdown/reboot [duplicate]

Now this has to be improved for sleep/hibernation/wake. Ideally brightness would be saved to /etc/acpi/nvidia-brightness (or any other file) each time the brightness is modified. I’m not sure if use that file or file inside my home folder. Which is the proper way to do it?