Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Q: How to change values in /sys/class/power_supply ?

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
macguru
Posts: 13
Joined: 2018-09-13 18:09

Q: How to change values in /sys/class/power_supply ?

#1 Post by macguru »

Hi,

How to change values in /sys/class/power_supply?

This doesn’t work when executed as root, get permission error.
echo 68000000 > /sys/class/power_supply/BAT0/capacity_full_design

chmod (as root) u+w /sys/class/power_supply/BAT0/capacity_full_design
doesn't work because of denied permissions, even chattr can't be used.

Code: Select all

lsattr: Inappropriate ioctl for device While reading flags on
May be is possible to set it in /etc/sysctl.conf, rc.local or with grub boot parameters?

Thanks in advance for any help.
Last edited by macguru on 2018-09-14 05:13, edited 1 time in total.

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: Q: How to change values in /sys/class/power_supply ?

#2 Post by bw123 »

I never had much luck writing to anything under /sys it is not a normal fs. There may be some way to get at some of the things there through /proc/sys? https://en.wikipedia.org/wiki/sysfs

I don't see how trying to fool the kernel that you have a good battery would be helpful? If it's dead it's dead.
resigned by AI ChatGPT

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: Q: How to change values in /sys/class/power_supply ?

#3 Post by debiman »

you probably shouldn't, and won't be able to make it persistent.

Code: Select all

mount | grep /sys
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
(...)
https://www.startpage.com/do/dsearch?qu ... inux+sysfs

macguru
Posts: 13
Joined: 2018-09-13 18:09

Re: Q: How to change values in /sys/class/power_supply ?

#4 Post by macguru »

bw123 wrote:I never had much luck writing to anything under /sys it is not a normal fs. There may be some way to get at some of the things there through /proc/sys? https://en.wikipedia.org/wiki/sysfs

I don't see how trying to fool the kernel that you have a good battery would be helpful? If it's dead it's dead.
I reconditioned battery with new high-capacity cells, yet EEPROM chip holds old (and incorrect info). Unfortunately, have no hardware to reflash EEPROM.

macguru
Posts: 13
Joined: 2018-09-13 18:09

Re: Q: How to change values in /sys/class/power_supply ?

#5 Post by macguru »

I followed symlinks and finally changed write attributes of one of the /sys/class files. Notebook left in another location, so I had to experiment with stationery PC and another /sys/class variable, but anyway, if it works, it should work anyway with notebook.

All as root (not sudo)

# cd /sys/class/hwmon/hwmon0
# ls -la
-rw-rw-rw- 1 root root 4096 Sep 14 10:03 temp1_crit
# cat temp1_crit
106000

# echo 105000 > temp1_crit
-bash: echo: write error: Input/output error

# getfattr -d -m - temp1_crit
temp1_crit: system.posix_acl_access: Operation not supported
temp1_crit: system.posix_acl_default: Operation not supported

PS. May be its possible to alter these variables through udev ?

macguru
Posts: 13
Joined: 2018-09-13 18:09

Re: Q: How to change values in /sys/class/power_supply ?

#6 Post by macguru »

Wrote udev rule in /etc/udev/rules.d

Code: Select all

ACTION=="add|change", KERNEL=="BAT*", SUBSYSTEM=="power_supply", ATTR{energy_full_design}="*", MODE="0664"
ACTION=="add|change", KERNEL=="BAT*", SUBSYSTEM=="power_supply", ATTR{energy_full_design}="68000000"
Reloaded rules.

Code: Select all

# udevadm control --reload; udevadm trigger; cat /sys/class/power_supply/BAT1/energy_full_design
47520000 # old value

# udevadm test /sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT1

ATTR '/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT1/energy_full_design' writing '68000000' /etc/udev/rules.d/62-adjust-battery-capacity.rules:5
error opening ATTR{/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT1/energy_full_design} for writing: Permission denied
OK, then, probably thus udev rule have to be copied to initramfs.
Moved to /usr/lib/dracut/modules.d/95udev-rules/96-battery-adjust.rules

Edited dracut module setup script:

Code: Select all

# nano /usr/lib/dracut/modules.d/95udev-rules/module-setup.sh
# My custom rule for battery
prepare_udev_rules 96-battery-adjust.rules
inst_rules “$moddir/96-battery-adjust.rules”

# dracut -fv
My script still not included in initramfs, no error messages in the output.
What went wrong? Thanks in advance.

CwF
Global Moderator
Global Moderator
Posts: 2636
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 192 times

Re: Q: How to change values in /sys/class/power_supply ?

#7 Post by CwF »

macguru wrote: This doesn’t work when executed as root, get permission error.
echo 68000000 > /sys/class/power_supply/BAT0/capacity_full_design
When this does work then;
May be is possible to set it in /etc/sysctl.conf,
should work like

Code: Select all

/sys/class/power_supply/BAT0/capacity_full_design = 68000000
But I'm thinking this should not work! Back in the day I had a toughbook I looked at this. Panasonic had a nice utility for cycling the battery, short and long, and it did indeed update the battery status and then better estimate discharge. BUT, I'm pretty sure the utility talked to some chip and the results stored essentially in firmware.

Since I'm thinking the OS may read once at boot there is not a use case for a user to change it. Some magic utility needs to write to the bios/firmware. At the OS level without such utility the only option may be to figure out how to ignore it. Or look to the vendor/manufacturer of your gadget for a battery calibrator utility

macguru
Posts: 13
Joined: 2018-09-13 18:09

Re: Q: How to change values in /sys/class/power_supply ?

#8 Post by macguru »

May be is possible to set it in /etc/sysctl.conf,
should work like

Code: Select all

/sys/class/power_supply/BAT0/capacity_full_design = 68000000
But I'm thinking this should not work! Back in the day I had a toughbook I looked at this. Panasonic had a nice utility for cycling the battery, short and long, and it did indeed update the battery status and then better estimate discharge. BUT, I'm pretty sure the utility talked to some chip and the results stored essentially in firmware.

Since I'm thinking the OS may read once at boot there is not a use case for a user to change it. Some magic utility needs to write to the bios/firmware. At the OS level without such utility the only option may be to figure out how to ignore it. Or look to the vendor/manufacturer of your gadget for a battery calibrator utility
I checked, this variable not listed in sysctl -a, thus, it can't be changed this way, unfortunately.

The culprit is a battery controller board with EEPROM.
In order to reflash it one needs a special hardware, not expensive, yet meaningless to purchase in this particular case. Its not possible to overwrite battery EEPROM from notebook.

I reconditioned battery with new finest quality Li-Ion cells which have 1.59 times larger capacity compared to the old ones.

Battery calibration won't help (already verified), because power manager counts on old capacity.
Another option is to buy third-party high-capacity battery, which composed of dirty cheap s*** cells, and as my experience suggests, advertised numbers are close to fake.

So the only meaningful way is to hack udev/power manager, yet I didn't expected it would be so cumbersome.

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: Q: How to change values in /sys/class/power_supply ?

#9 Post by debiman »

macguru wrote:I reconditioned battery with new finest quality Li-Ion cells which have 1.59 times larger capacity compared to the old ones.
so you changed the actual battery cells only, but the chip inside the battery does not know that and still thinks the old cells are in there.
that sucks.
i hope you can fix it with udev; another approach could be through /proc?
https://www.simplified.guide/linux/view ... nformation

where do you actually need this? power management?

one problem i still see is how to get the actual capacity?

maybe this search can help.

macguru
Posts: 13
Joined: 2018-09-13 18:09

Re: Q: How to change values in /sys/class/power_supply ?

#10 Post by macguru »

Yes, problem is with charging and discharging, battery doesn't run at full capacity.

I don't know for sure if power manager reads values from /proc or /sys, if someone knows, please suggest. I running MATE Desktop, it uses Gnome power manager GUI, which I suppose is a front-end of UPower.

BTW, here what is written
https://askubuntu.com/questions/913768/ ... my-battery
that
/proc/acpi/battery is now /sys/class/power_supply/

I know its possible to include kernel modules with "dracut --add-drivers xxx-kernel-module-name", but how to include udev rules, which dracut config file needs to be edited?
Googling didn't help, one men advised to edit "/usr/lib/dracut/modules.d/95udev-rules/module-setup.sh", I did, and my udev rule is still not in initramfs.

macguru
Posts: 13
Joined: 2018-09-13 18:09

Re: Q: How to change values in /sys/class/power_supply ?

#11 Post by macguru »

I included my custom udev rules into initramfs.
/etc/dracut.conf.d/my-udev-battery.conf
install_items+="/etc/udev/rules.d/62-adjust-battery-capacity.rules”

its there - "dracut -vf" logs succesful inclusion.

/etc/udev/rules.d/62-adjust-battery-capacity.rules
### Rule start ###
ACTION=="add|change", KERNEL=="BAT*", SUBSYSTEM=="power_supply", ATTR{energy_full_design}="*", MODE="0664"
ACTION=="add|change", KERNEL=="BAT*", SUBSYSTEM=="power_supply", ATTR{energy_full_design}="68000000"
### Rule end ###

Unfortunately
cat /sys/class/power_supply/BAT1/energy_full
still displays old value.

Even tried to add grub boot parameter, no luck.
power_supply.energy_full_design=68000000

reinob
Posts: 1189
Joined: 2014-06-30 11:42
Has thanked: 97 times
Been thanked: 47 times

Re: Q: How to change values in /sys/class/power_supply ?

#12 Post by reinob »

macguru wrote:I included my custom udev rules into initramfs.
/etc/dracut.conf.d/my-udev-battery.conf
install_items+="/etc/udev/rules.d/62-adjust-battery-capacity.rules”

its there - "dracut -vf" logs succesful inclusion.

/etc/udev/rules.d/62-adjust-battery-capacity.rules
### Rule start ###
ACTION=="add|change", KERNEL=="BAT*", SUBSYSTEM=="power_supply", ATTR{energy_full_design}="*", MODE="0664"
ACTION=="add|change", KERNEL=="BAT*", SUBSYSTEM=="power_supply", ATTR{energy_full_design}="68000000"
### Rule end ###

Unfortunately
cat /sys/class/power_supply/BAT1/energy_full
still displays old value.

Even tried to add grub boot parameter, no luck.
power_supply.energy_full_design=68000000
AFAIK the output (content) of /sys/class/power_suppy/*/energy* are read off the hardware (battery controller), so it doesn't make any sense to "write".

The /proc and /sys "filesystems" merely expose some variables which may or may not be writable (configurable).
It's as if you wanted to change the CPU temperature by merely "writing" on /sys/cpu/temp (or whatever the actual path may be).

Post Reply