Score:0

Display brightness resets after rebooting

in flag

I am working on a XMG Core 15 with Ubuntu 20.04. (kernel 5.11.0.27-generic since the newer ones cause problems with my screens) and a NVIDIA GeForce RTX 2060 (NVIDIA driver 470) and AMD Ryzen 7 4800H. My problem is that every time I reboot my laptop, the display brightness resets to the minimum but the actual screen brightness is maximum. If I double check in settings the slider on brightness is in the minimum position. The strange thing is if I plug in or out the power cable the screen brightness jumps to the value in the settings. It is no big problem but it is really annoying. My question is now, how can I prevent it from resetting the brightness every reboot and set the brightness to a specific value. I hope I have described the problem in an comprehensible way.

If you need additional information feel free to ask. I am glad for every help of you.

Thanks and best regards, Daniel

Update #1. After undo the first step and do the steps from Update #1 the brightness still resets after rebooting. I did the following modifications:

  • Create a file -rwxr-xr-x 1 root root 180 Feb 7 19:20 set_brightness.sh* in /etc/rc.local with the following content:

    #!/bin/sh
    #. Set specific brightness level to work around bug
    #. See /etc/systemd/system/set_brightness.service
    #.
    sleep 15; echo 255 | tee /sys/class/backlight/amdgpu_bl0/brightness

  • Create second file -rw-r--r-- 1 root root 172 Feb 7 19:23 set_brightness.service in /etc/systemd/system with the following content:

    [Unit]

    Description=Set screen brightness to work around bug

    [Service]

    Type=oneshot

    ExecStart=/bin/sh /etc/rc.local/set_brightness.sh

    [Install]

    WantedBy=multi-user.target

The status looks as follow:

(base) daniel@xmg-daniel:/etc/systemd/system$ systemctl status set_brightness.service
● set_brightness.service - Set screen brightness to work around bug
     Loaded: loaded (/etc/systemd/system/set_brightness.service; disabled; vendor preset: enabled)
     Active: inactive (dead)

Output of ls -al /sys/class/backlight/ :

total 0
drwxr-xr-x  2 root root 0 Feb  7 19:49 .
drwxr-xr-x 84 root root 0 Feb  7 19:49 ..
lrwxrwxrwx  1 root root 0 Feb  7 19:49 amdgpu_bl0 -> ../../devices/pci0000:00/0000:00:08.1/0000:06:00.0/backlight/amdgpu_bl0

Some other remarks: With the first modifications the slider of the brightness was set to the same position as before rebooting also the actual brightness was the same as before rebooting, but after pluging in or out the power cable the brightness was set automatically to minimum. Also with this modification my bluetooth turned on automatically after rebooting although I turned it off everytime. Undoing the first modifications and doing update #1 the bluetooth issue was solved but it looks like the workaround is not working correctly.

After doing the steps from @heynnema mentioned in the comments I have the following output for systemctl status set_brightness.service:

● set_brightness.service - Set screen brightness to work around bug
     Loaded: loaded (/etc/systemd/system/set_brightness.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Mon 2022-02-07 20:14:00 CET; 7s ago
    Process: 4546 ExecStart=/bin/sh /etc/rc.local/set_brightness.sh (code=exited, status=0/SUCCESS)
   Main PID: 4546 (code=exited, status=0/SUCCESS)

Feb 07 20:13:45 xmg-daniel systemd[1]: Starting Set screen brightness to work around bug...
Feb 07 20:14:00 xmg-daniel sh[4549]: 255
Feb 07 20:14:00 xmg-daniel systemd[1]: set_brightness.service: Succeeded.
Feb 07 20:14:00 xmg-daniel systemd[1]: Finished Set screen brightness to work around bug.

But the problem is still there. When plugging in or out the power cable the brightness switches automatically to minimum.

Sorry for the bad formatting of my update, I wanted to code sample the content of the two files but somehow it is not working ...

WinEunuuchs2Unix avatar
in flag
May be overkill but you can use [eyesome](https://github.com/WinEunuuchs2Unix/eyesome) to automatically set your brightness and color temperature when resuming from suspend. **Disclaimer:** I wrote the app.
Score:1
ru flag

What happens is at boot time (and shutdown time), /lib/systemd/system/[email protected] tries to restore (save) the backlight levels, and it doesn't always perform this action correctly. Hence the lowered screen brightness after a boot. cat the file if you wish to see its contents. Type man systemd-backlight to get more background information.

Edit /etc/default/grub...

sudo -H gedit /etc/default/grub

Find the line that looks like this:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

Edit it to look like this:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash systemd.restore_state=0"

Then:

sudo update-grub

reboot

Update #1:

This may work better than the kernel line mod from above. It'll take a little playing to get it going in your config, but I think you've got the skills required :-)

  • first, undo the mods from above

  • see if a file called /etc/rc.local exists on your computer

    • ls -al /etc/rc.local
  • if it doesn't exist, create a folder at /etc/rc.local

    • sudo mkdir /etc/rc.local
  • if it does exist, talk to me before proceeding

  • drop this into the /etc/rc.local folder, and name it set_brightness.sh


#!/bin/sh
# Set specific brightness level to work around bug
# See /etc/systemd/system/set_brightness.service
#
sleep 15; echo 80 | tee /sys/class/backlight/dell_uart_backlight/brightness

Note: You'll need to change the dell_uart_backlight in the pathname for your own configuration

Note: If you have a slow system, you may need to increase the sleep timer

Note: 80 is the desired brightness setting

It should look like this:

-rwxr-xr-x   1 root root   189 Jan 17 15:57 set_brightness.sh
  • drop this into the /etc/systemd/system/ folder, and name it set_brightness.service

[Unit]
Description=Set screen brightness to work around bug

[Service]
Type=oneshot
ExecStart=/bin/sh /etc/rc.local/set_brightness.sh

[Install]
WantedBy=multi-user.target

It should look like this:

-rw-r--r-- 1 root root 172 Sep 27 16:24 /etc/systemd/system/set_brightness.service
  • sudo systemctl enable set_brightness.service

  • then reboot

And this status:

$ systemctl status set_brightness.service

○ set_brightness.service - Set screen brightness to work around bug
     Loaded: loaded (/etc/systemd/system/set_brightness.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Thu 2022-02-03 20:13:23 PST; 1 day 10h ago
    Process: 1102 ExecStart=/bin/sh /etc/rc.local/set_brightness.sh (code=exited, status=0/SUCCESS)
   Main PID: 1102 (code=exited, status=0/SUCCESS)
        CPU: 23ms

Feb 03 20:13:08 al-Inspiron-7700-AIO systemd[1]: Starting Set screen brightness to work around bug...
Feb 03 20:13:23 al-Inspiron-7700-AIO sh[3320]: 80
Feb 03 20:13:23 al-Inspiron-7700-AIO systemd[1]: set_brightness.service: Deactivated successfully.
Feb 03 20:13:23 al-Inspiron-7700-AIO systemd[1]: Finished Set screen brightness to work around bug.

Update #2:

Both mods didn't solve the problem. Both mods removed.

However, booting to a Ubuntu Live 21.10 solves the problem, but the user cannot upgrade at this time due to some other software issues.

CFDaniel avatar
in flag
Thank you @heynnema! It almost solved my problem. The slider in settings is set to max after rebooting but if I plug in or out the power cable it still switches back to minimum. Do you also know how to solve this problem?
heynnema avatar
ru flag
@CFDaniel See Update #1 in my answer. Maybe it'll work better.
heynnema avatar
ru flag
@CFDaniel Status please...
CFDaniel avatar
in flag
Hello @heynnema and sorry for late reply. There is no file/folder called rc.local, there are only folders like rc0.d, rc1.d and so on. Can I then continue with the next steps as you described?
heynnema avatar
ru flag
@CFDaniel Yes. Carry on. Did you undo the first mod? Report back.
CFDaniel avatar
in flag
Hi @heynnema I updated my question, sorry for bad formatting, I don't know why code sampling is not working for the two files ...
heynnema avatar
ru flag
Edit your question and show me `ls -al /sys/class/backlight/`. Also, the formatting on the service file looks wrong... it may just be the edit. And why the 255 value? And the service is disabled.
CFDaniel avatar
in flag
Why is it formatting so weird? I copy the text and then I click code sampling for the whole text. I updated the question with some more information. Formatting is still weird, sorry @heynnema I put 255 in because it is the maximum brightness, at least that was the value which was in brightness before.
heynnema avatar
ru flag
So if you `sudo cat /sys/class/backlight/amdgpu_bl0/brightness` you can see the value go from 0 to 255 when you move the brightness slider, yes?
CFDaniel avatar
in flag
yes, I can confirm @heynnema
heynnema avatar
ru flag
Do `sudo systemctl enable set_brightness`, then `sudo systemctl start set_brightness`, then `sudo systemctl status set_brightness`. I'll update my answer a bit later...
heynnema avatar
ru flag
That looks better. I read your update. Let's try this test. Set the brightness slider to mid-point. Confirm the value in `/sys/class/backlight/amdgpu_bl0/brightness` and it should be something less than 255. Then `sudo systemctl start set_brightness`. Recheck the value in `/sys/class/backlight/amdgpu_bl0/brightness` and it should be 255, and the brightness slider should be back at maximum, yes?
CFDaniel avatar
in flag
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/133943/discussion-between-cfdaniel-and-heynnema).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.