Application tools, terminal sudo and wifi freeze when pc runs on battery.

Teklehaimanot

Member
Joined
Aug 5, 2023
Messages
37
Reaction score
6
Credits
267
Hi everyone,

I have been experiencing difficulty with debian 12. Problem occurs when the pc is turn on with battery. The terminal command sudo does not respond and the tools installed such as vscode, and internet browsers ( firefox and google chrome) and wifi donot work. But I noticed something, when I plug in the AC power adapter, the problems mentioned disappear. I am wondering what the problem might be? Some of you might experience similar problem in the past and I would like to hear from you.

Thank you.
 


a starting point may be a battery health check
from the terminal run upower -i /org/freedesktop/UPower/devices/battery_BAT0
 
Some info would really help. Distro? Laptop make? The output of sudo -i when AC is connected vs disconnected. If there's no error message, just a hang, it could be ACPI settings or firmware itself. My CPU is throttled from around 70-80% battery life. If @Brickwizard is right and your battery is dying, that would explain a lot regarding simply hanging. That's why it's important to always post the outputs and supply system info.
 
Thank you very much @Fanboi and @Brickwizard for your feedbacks. My pc is thinkpad p15 gen2 and it is new. Debian 12, linux 6.1.0-17-amd64 is installed. The result of running " upower -i /org/freedesktop/UPower/devices/battery_BAT0":

1733997687819.png

I also suspect that the battery is dying because it does not last long after it is fully recharged.
Additional information about my system:

Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 39 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: GenuineIntel
Model name: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz

I hope this will help to understand the situation and suggestion solution.

Thank you.
 
Last edited:
Could you tell us whether is hangs on sudo or whether there's an error message? That'd help a lot in determining what's affected.


Also, battery looks okay. Don't expect capacity to ever be 100%. As to why:
I thought my battery was dying on this machine 8 years back and I found a post on another forum to check it, it was 94.xx or 96.xx, can't remember but 8 years use, 9 years since manufacture down the line, I just rechecked and I'm on 81.xx. Your's is half my age (asuming you bought it 2020 as the CPU model suggests), so it's not too bad, but it's gonna die long before mine will have. Planned obsolescence is not just OS updates that are too big for your smartphone or MS telling you your PC is too old, it's also hardware, which is why most batteries in electronics are built-in.

I will give you a hint on LiPo batteries and increasing their life: try not to discharge them below 30%, try keep that at 40%. Just like how an LA battery should never hit below 40% (though 50% is ideal max DoD). I keep my laptop plugged in most of the time, so the only issue with my battery is that it's loose, but that's nothing duct tape won't solve (duct tape solves everything, including chips in kitchen counter tops, lol).
So I think your ACPI settings may be off. Your Laptop's modern enough that in your BIOS you should be able to set CPU throttling, etc. for each 10% step in battery discharge manually. You may want to look into that if hanging is the case.

Edit: I see you said "doesn't respond" vis a vis sudo so I assume you meant hangs. Also I see you'd mentioned you distro. So unless you edited your OP, guess my bad.
 
Last edited:
Last edited:
I also suspect that the battery is dying because it does last long
Your battery is a pattern part, not withstanding you have not yet done 200 cycles, you should get a minimum of 1000
 
Could you tell us whether is hangs on sudo or whether there's an error message? That'd help a lot in determining what's affected.


Also, battery looks okay. Don't expect capacity to ever be 100%. As to why:
I thought my battery was dying on this machine 8 years back and I found a post on another forum to check it, it was 94.xx or 96.xx, can't remember but 8 years use, 9 years since manufacture down the line, I just rechecked and I'm on 81.xx. Your's is half my age (asuming you bought it 2020 as the CPU model suggests), so it's not too bad, but it's gonna die long before mine will have. Planned obsolescence is not just OS updates that are too big for your smartphone or MS telling you your PC is too old, it's also hardware, which is why most batteries in electronics are built-in.

I will give you a hint on LiPo batteries and increasing their life: try not to discharge them below 30%, try keep that at 40%. Just like how an LA battery should never hit below 40% (though 50% is ideal max DoD). I keep my laptop plugged in most of the time, so the only issue with my battery is that it's loose, but that's nothing duct tape won't solve (duct tape solves everything, including chips in kitchen counter tops, lol).
So I think your ACPI settings may be off. Your Laptop's modern enough that in your BIOS you should be able to set CPU throttling, etc. for each 10% step in battery discharge manually. You may want to look into that if hanging is the case.

Edit: I see you said "doesn't respond" vis a vis sudo so I assume you meant hangs. Also I see you'd mentioned you distro. So unless you edited your OP, guess my bad.
Thank you very much @Fanboi for sharing your knowledge and experience. I often leave the AC power adapter plugged in after the battery is fully recharged. Does this also degrade the battery? and either a way to automatically turn off the pc when the state of discharge is 40%?
 
I often leave the AC power adapter plugged in after the battery is fully recharged. Does this also degrade the battery?
if you are using a genuine charger from your laptop maker then it will have a charge sensor that cuts off when fully charged, if yo have a compatible pattern part , then it depends on the quality, in theory they should have the same system, but i have some serious doubts about some of the cheaper replacements.
What most people fail to do is proof the battery when new [this applies to any rechargeable battery] they normally come with around 50% charge, what you should do is use the power in the battery until the machine self powers off, then fully recharge it fully [but not using it whilst it charges] then use the machine until it powers off and go through the recharge routeen again, DO THIS 3 or 4 Times before you start part charging,
 
Thank you very much @Fanboi for sharing your knowledge and experience. I often leave the AC power adapter plugged in after the battery is fully recharged. Does this also degrade the battery? and either a way to automatically turn off the pc when the state of discharge is 40%?
Batteries:
No, leaving it plugged in will not degrade your battery, there is a built-in charge controller (usually in the laptop) and smart monitor (usually in the battery -- providing the stats from earlier).
Since your battery is LiPo (Lithium Polymer), it's best never to discharge it. Unlike NiCad (Nickel Cadmium), which has a "charge memory" as it were (and thus should be discharged completely before charging), LiPo batteries are shipped holding a charge to ensure they do not deteriorate. The longer a LiPo battery is left discharged below ecommended DoD, the harder it is to hold a charge. So it will depend of battery type how to manage it.

Power Management Settings:
You can set up notifications and actions in the "Power Management" which will vary from Desktop Environment unless you installed a non-integrated one or setup a shell/python/etc. script.
For example, under XFCE: it's in Menu > "Settings" > "Power Manager". Now go to the "System" tab and make sure to click "On Battery" then look for "Critical Power", Critical power level XX % (you can set what's "Critical" here. Then below it, "On Critical Power" there's a drop-down box for selecting different actions like Sleep.
Note, as I said, this varies. For example, Gnome3 or KDE may be very different, but you'll get the same net result. If you need guidance for a specific DE, let us know.
 
Thank you very much @Fanboi for sharing your knowledge. I tried to configure the Power Manager, however every time I set the critical power to same value such as 40%, it resets afterwards. Do you have any idea why this happens?

1734548925353.png
 
Hey @Teklehaimanot so I found the same issue. It will only accept a percent of <= 20% -- don't ask why. Anyway, I made you a background script to run:

Bash:
#! /bin/bash

# Run in the background
while true; do
    # Polling rate. I figure checking every 10 minutes will suffice.
    sleep 10m
    # Suppose I should break this up for neatness, but meh...
    # Remove the getter, everything in $(), and assign it a variable on the line above IF you need to play case/elif
    if [ $(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep "percentage" | cut -d':' -f2 | tr -cd '0-9') -le 40 ]
    then
        # Shutdown, suspend, notify-send, xbacklight, whatever
        systemctl suspend
    fi
done

Save it as /usr/local/bin/batteryctl -- use sudo nano /usr/local/bin/batteryctl.sh and paste the code and press ctrl + o then ctrl + x.
Next make it executable: sudo chmod a+x /usr/local/bin/batteryctl.sh.
As a normal user, you can now run it by typing batteryctl.sh & in the terminal.
To permanently run it each time you log in, go to "Startup Applications", Click the "+", Choose "Custom Command" and then just enter something like "Battery Saver" in the "Name" field and "batteryctl.sh" in the "Command" field, choose "Add". Make sure it's checked to run. On XFCE, it's the same process, Just "Settings" > "Applications & Auto start" and the "Application Auto start" tab.

Hope that helps.

* PS: This is an oversimplified script and setup. You can add error-handling and sanity checks as needed and if you want, add in on /opt/<your scripts> and make a symlink to /usr/local/bin without the .sh extension (which is canonically correct) or in ~/.local/lib/<your scripts> and similarly linked to ~/.local/bin/.
 
Last edited:
Hey @Teklehaimanot so I found the same issue. It will only accept a percent of <= 20% -- don't ask why. Anyway, I made you a background script to run:

Bash:
#! /bin/bash

# Run in the background
while true; do
    # Polling rate. I figure checking every 10 minutes will suffice.
    sleep 10m
    # Suppose I should break this up for neatness, but meh...
    # Remove the getter, everything in $(), and assign it a variable on the line above IF you need to play case/elif
    if [ $(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep "percentage" | cut -d':' -f2 | tr -cd '0-9') -le 40 ]
    then
        # Shutdown, suspend, notify-send, xbacklight, whatever
        systemctl suspend
    fi
done

Save it as /usr/local/batteryctl -- use sudo nano /usr/local/batteryctl.sh and paste the code and press ctrl + o then ctrl + x.
Next make it executable: sudo chmod a+x /usr/local/batteryctl.sh.
As a normal user, you can now run it by typing batteryctl.sh & in the terminal.
To permanentl run it each time you log in, go to "Startup Applications", Click the "+", Choose "Custom Command" and then just enter something like "Battery Saver" in the "Name" field and "batteryctl.sh" in the "Command" field, choose "Add". Make sure it's checked to run. On XFCE, it's the same process, Just "Settings" > "Applications & Auto start" and the "Application Auto start" tab.

Hope that helps.

* PS: This is an oversimplified script and setup. You can add error-handling and sanity checks as needed and if you want, add in on /opt/<your scripts> and make a symlink to /usr/local/bin without the .sh extension (which is canonically correct) or in ~/.local/lib/<your scripts> and similarly linked to ~/.local/bin/.
Thanks for the script @Fanboi . Yet to try.
It may be worth placing the script in /usr/local/bin/ rather than /usr/local/, since
/usr/local/bin is normally in the PATH by default, e.g. on this machine:
Code:
$ echo $PATH
/home/ben/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin
whereas /usr/local is normally just a list of directories, and here with one link:
Code:
$ ls -F /usr/local
bin/  etc/  games/  include/  lib/  man@  sbin/  share/  src/

I see in the PS in post #13 the reference to /usr/local/bin, so it may just be typo in the main text.
 
Last edited:
Thanks for the script @Fanboi . Yet to try.
It may be worth placing the script in /usr/local/bin/ rather than /usr/local/, since
/usr/local/bin is normally in the PATH by default, e.g. on this machine:
Code:
$ echo $PATH
/home/ben/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin
whereas /usr/local is normally just a list of directories, and here with one link:
Code:
$ ls -F /usr/local
bin/  etc/  games/  include/  lib/  man@  sbin/  share/  src/

I see in the PS in post #13 the reference to /usr/local/bin, so it may just be typo in the main text.
Lol, yes, thanks for the catch. I messed that one up when I just copy-pasted the first instance... Copy-pasting is a badhabit! A badhabit I tell you. A badhabit that I should stop. I'll edit.
 


Top