每次从屏幕锁定、睡眠或挂起状态恢复后,我的笔记本电脑屏幕都会很暗。如果我输入Fn+ F6,屏幕会立即跳转到 100% 亮度。(F5和F6是我的亮度控制键。)
$ 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
锁屏、睡眠或挂起之前:
$ cat /sys/class/backlight/nv_backlight/actual_brightness
100
屏幕锁定、睡眠或挂起后:
$ cat /sys/class/backlight/nv_backlight/actual_brightness
33
我通过以下任一方式进入锁定模式:
- 通过不活动
- 从命令行使用:
xdg-screensaver lock
- 从下拉菜单中点击:
Lock
我通过以下任一方式进入睡眠/挂起模式:
- 从命令行使用:
systemctl suspend
- 从下拉菜单中点击:
Power Off/Log Out
>Suspend
注意从锁定/睡眠/挂起恢复后, 的内容/sys/class/backlight/nv_backlight/actual_brightness
是33
,而不是100
。
要再次达到最大亮度,我只需输入一次Fn+ F6。我觉得这有点奇怪,因为通常情况下,如果亮度这么低,需要按几次键。例如,要从 变为30
,100
通常需要按七次键。
此外,您会在Settings/Power
窗口中注意到,无论是在锁定/睡眠/挂起之前还是之后,亮度级别都显示为 100%。
最后,您会注意到我已禁用设置Dim Screen When Inactive
。
为了尝试找到某种解决方案,我安装xbacklight
时想到可以在脚本中使用它来自动重置亮度。但这没有效果。
我还尝试了以下命令,但亮度级别没有改变,而且我无法写入文件。也许这是错误的方法。
$ 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
为什么会出现这种症状?我该如何解决?理想情况下,我宁愿不加入登录时运行的脚本。这似乎是治标不治本。
更新
我尝试了以下两个建议的解决方案,但都没有效果。
建议 1 - Systemd 服务
创建文件:
$ 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
重新加载 systemd 守护进程:
sudo systemctl daemon-reload
启用服务:
sudo systemctl enable nvidia-backlight-sleep
建议 2 - 在/lib/systemd/system-sleep
创建文件:
$ 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
使可执行文件:
sudo chmod 755 /lib/systemd/system-sleep/nvidia-backlight-sleep
答案1
我能够通过从开源nouveau
驱动程序切换到专有驱动程序来解决我的问题nvidia-driver-535
。这可以从命令行或通过 GUI 安装。我选择通过 GUI 安装它。
- 在活动, 搜索 ”司机”,然后点击“附加驱动程序“ 图标。
- 这 ”软件与更新”窗口将打开到“附加驱动程序“ 标签。
- 我选择了“使用来自 nvidia-driver-535 (专有) 的 NVIDIA 驱动程序元包“并点击”应用更改“
- 我重启了电脑
重新启动后,您可以看到 Nvidia 驱动程序正在使用:
$ 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
version: a1
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress vga_controller bus_master cap_list rom
configuration: driver=nvidia latency=0
resources: iomemory:400-3ff iomemory:410-40f irq:200 memory:ab000000-abffffff memory:4000000000-40ffffffff memory:4100000000-4101ffffff ioport:3000(size=128) memory:ac080000-ac0fffff
此外,在安装驱动程序的同时,nvidia-settings
还会安装一个名为的实用程序。使用以下命令运行该实用程序sudo nvidia-settings
,将显示以下窗口:
与 Nvidia 驱动程序一起安装的另一个实用程序应用程序是系统管理界面nvidia-sma
:
$ nvidia-smi
Tue Feb 27 21:32:15 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.161.07 Driver Version: 535.161.07 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 NVIDIA RTX A2000 Laptop GPU Off | 00000000:01:00.0 On | N/A |
| N/A 38C P8 7W / 60W | 411MiB / 4096MiB | 1% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| 0 N/A N/A 1344 G /usr/lib/xorg/Xorg 39MiB |
| 0 N/A N/A 2153 G /usr/lib/xorg/Xorg 114MiB |
| 0 N/A N/A 2282 G /usr/bin/gnome-shell 83MiB |
| 0 N/A N/A 7710 G /usr/lib/firefox/firefox 153MiB |
+---------------------------------------------------------------------------------------+
最后,我可以锁定或挂起笔记本电脑,并且屏幕背光亮度设置会保留。之前将值保存在 中/sys/class/backlight/nv_backlight/actual_brightness
,而新驱动程序将值保存在 中/sys/class/backlight/nvidia_0/actual_brightness
:
$ cat /sys/class/backlight/nvidia_0/actual_brightness
100
总之,我认为驱动程序存在错误nouveau
,无法正确保存和调用该actual_brightness
值。出于某种原因,它总是从锁定或睡眠/挂起状态恢复,并且值为33
。
答案2
似乎您的 Nvidia 驱动程序没有记住背光值,而您的 GNOME 可以。让我们使用睡眠钩子来解决这个问题:
将以下内容粘贴到
/etc/systemd/system/nvidia-backlight-sleep-askubuntu-1505827-1004020.service
[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
跑步
sudo systemctl daemon-reload
跑步
sudo systemctl enable nvidia-backlight-sleep-askubuntu-1505827-1004020.service
actual_brightness
不是可写的,所以我们需要使用该文件。如果它不起作用或者您希望它更快地恢复,brightness
您也可以调整。负责在关机/启动时保存,而 GPU 驱动程序本身负责暂停/恢复。sleep 1
/lib/systemd/system/[email protected]
替代解决方案
如果这不起作用,我们可以对更多内容进行硬编码:
禁用并删除其他解决方案
将以下内容粘贴到
/lib/systemd/system-sleep/nvidia-backlight-sleep-askubuntu-1505827-1004020
#!/bin/bash case $1 in post) sleep 1 echo 50 > /sys/class/backlight/nv_backlight/brightness ;; esac
sudo chmod 755 /lib/systemd/system-sleep/nvidia-backlight-sleep-askubuntu-1505827-1004020