After every resume from screen-lock, sleep, or suspend, my laptop screen is very dim. If I type Fn+F6, then the screen jumps to 100% brightness instantly. (F5 and F6 are my brightness control keys.)
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal
$ lspci -nnk | grep -EA3 VGA
01:00.0 VGA compatible controller [0300]: NVIDIA Corporation Device [10de:25b8] (rev a1)
Subsystem: Lenovo Device [17aa:22d8]
Kernel driver in use: nouveau
Kernel modules: nvidiafb, nouveau
$ sudo lshw -c video
*-display
description: VGA compatible controller
product: NVIDIA Corporation
vendor: NVIDIA Corporation
physical id: 0
bus info: pci@0000:01:00.0
logical name: /dev/fb0
version: a1
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress vga_controller bus_master cap_list rom fb
configuration: depth=32 driver=nouveau latency=0 mode=1920x1080 visual=truecolor xres=1920 yres=1080
resources: iomemory:400-3ff iomemory:410-40f irq:199 memory:ab000000-abffffff memory:4000000000-40ffffffff memory:4100000000-4101ffffff ioport:3000(size=128) memory:ac080000-ac0fffff
$ sudo lshw | grep -i lenovo
product: 20YU002HUS (LENOVO_MT_20YU_BU_Think_FM_ThinkPad P17 Gen 2i)
vendor: LENOVO
configuration: administrator_password=disabled chassis=notebook family=ThinkPad P17 Gen 2i power-on_password=disabled sku=LENOVO_MT_20YU_BU_Think_FM_ThinkPad P17 Gen 2i uuid=4C043C28-3F2B-B211-A85C-940FFC06910B
vendor: LENOVO
vendor: LENOVO
Before screen-lock, sleep, or suspend:
$ cat /sys/class/backlight/nv_backlight/actual_brightness
100
After screen-lock, sleep, or suspend:
$ cat /sys/class/backlight/nv_backlight/actual_brightness
33
I'm entering lock mode by any of the following:
- By inactivity
- From command line with:
xdg-screensaver lock
- From drop-down menu by clicking:
Lock
I'm entering sleep/suspend mode by any of the following:
- From command line with:
systemctl suspend
- From drop-down menu by clicking:
Power Off/Log Out
>Suspend
Take note that after resume from lock/sleep/suspend, the content of /sys/class/backlight/nv_backlight/actual_brightness
is 33
, not 100
.
To achieve full brightness again, I only have to type Fn+F6 once. I find this a bit odd, because typically, if the brightness is that low, it would take several key presses. For example, to go from 30
to 100
, it would normally be seven key presses.
Also, you'll notice in the Settings/Power
window that the brightness level indicates it's at 100%, both before and after lock/sleep/suspend.
Finally, you'll notice that I have the setting, Dim Screen When Inactive
, disabled.
In my attempt to come up with some sort of solution, I installed xbacklight
with the idea that I could use it in a script to automatically reset my brightness. But this had no affect.
I also attempted the following commands, but the brightness levels don't change, and I'm unable to write to the file. Perhaps this is the wrong approach.
$ sudo chmod 644 /sys/class/backlight/nv_backlight/actual_brightness
$ sudo tee /sys/class/backlight/nv_backlight/actual_brightness <<< 100
100
tee: /sys/class/backlight/nv_backlight/actual_brightness: Input/output error
$ sudo su
# echo 100 > /sys/class/backlight/nv_backlight/actual_brightness
bash: echo: write error: Input/output error
Why is this symptom happening, and how do I fix it? Ideally, I would prefer to not incorporate a script that runs at login. This seems like treating the symptom and not the cause.
UPDATE
I attempted the two following suggested solutions, but neither worked.
Suggestion 1 - Systemd service
Create file:
$ cat /etc/systemd/system/nvidia-backlight-sleep [Unit] Description=Fix Nvidia backlight after suspend Before=sleep.target StopWhenUnneeded=yes [Service] Type=oneshot RemainAfterExit=yes ExecStart=/bin/bash -c "cat /sys/class/backlight/nv_backlight/actual_brightness > /run/previous_nv_backlight_brightness" ExecStop=/bin/bash -c "sleep 1; cat /run/previous_nv_backlight_brightness > /sys/class/backlight/nv_backlight/brightness" [Install] WantedBy=sleep.target
Reload systemd daemons:
sudo systemctl daemon-reload
Enable service:
sudo systemctl enable nvidia-backlight-sleep
Suggestion 2 - Create script in /lib/systemd/system-sleep
Create file:
$ cat /lib/systemd/system-sleep/nvidia-backlight-sleep #!/bin/bash case $1 in post) sleep 1 echo 50 > /sys/class/backlight/nv_backlight/brightness ;; esac
Make executable:
sudo chmod 755 /lib/systemd/system-sleep/nvidia-backlight-sleep
I was able to solve my problem by switching from the open-source
nouveau
driver to the proprietarynvidia-driver-535
. This can be installed from either the command line or through the GUI. I chose to install it through the GUI.After a reboot, you can see that the Nvidia driver is in use:
Additionally, along with the installation of the driver, a utility called
nvidia-settings
is installed. Run that withsudo nvidia-settings
and the following window displays:Another utility app that is installed with the Nvidia driver is System Management Interface,
nvidia-sma
:Finally, I can lock or suspend my laptop and the screen backlight brightness settings are retained. Whereas before the value was saved in
/sys/class/backlight/nv_backlight/actual_brightness
, the new driver saves the value in/sys/class/backlight/nvidia_0/actual_brightness
:In conclusion, I think that there's a bug with the
nouveau
driver that is incorrectly saving and recalling theactual_brightness
value. For some reason, it always resumed from lock or sleep/suspend with a value of33
.It seems like your Nvidia driver isn't remembering the backlight value even though your GNOME does. Let's work around this with a sleep hook:
Paste the following into
/etc/systemd/system/nvidia-backlight-sleep-askubuntu-1505827-1004020.service
Run
sudo systemctl daemon-reload
Run
sudo systemctl enable nvidia-backlight-sleep-askubuntu-1505827-1004020.service
actual_brightness
isn't the writable one so we need to use thebrightness
file. You can also adjust thesleep 1
in case it doesn't work or if you want it to be restored quicker./lib/systemd/system/[email protected]
is responsible for saving at shutdown/startup while the GPU driver itself is responsible for suspend/resume.Alternative solution
If that doesn't work, we can hardcode more things:
Disable and remove the other solution
Paste the following into
/lib/systemd/system-sleep/nvidia-backlight-sleep-askubuntu-1505827-1004020
sudo chmod 755 /lib/systemd/system-sleep/nvidia-backlight-sleep-askubuntu-1505827-1004020