I have suspend/hibernate, and also a battery monitor
Thursday, 20. August 2009, 21:08:00
Thus I think I finally need a battery monitor and suspend/hibernate. And that's what I've done this week!
batterymon
People might remember that I didn't have a battery monitor on my system. Actually, whenever I needed to check the battery status, I ran:
watch -d -n 10 cat /proc/acpi/battery/BAT0/* /proc/acpi/ac_adapter/AC0/state
Although that command kinda works, it's far from the best solution.
Then I've found a little Python program called batterymon. It's just a small systray icon that shows how much battery I have, and also if I'm connected to AC or not. In other words, a basic battery monitor, with all the features you expect to have on any battery-powered device.
batterymon is very minimalistic and has no dependencies other than PyGTK. This is perfect for me, since my desktop is also very minimalistic: I don't have Gnome, KDE, Xfce... That's true, I have no full desktop environment! All I have is Compiz as my window manager and a slightly modified version of fbpanel to hold the clock and the system tray, nothing else.
batterymon icons
Unfortunately, the default themes that came with batterymon weren't good enough. Both of them (default and gnome) were very pretty, but also very hard to see. So hard that I needed to pass the mouse over batterymon icon in order to display the tooltip.
Then I decided I wanted to create my own battery graphics. I'm not an artist, I'm very bad with graphics, but this task is so simple that I thought I could do it. And then I've done it!

You can download the original battery.svg file, which was drawn in Inkscape and then exported to Gimp, broken to layers and saved as battery.xcf, and then finally exported to individual .PNG images. You can also download the battery_charge_icons.tar.bz2 tarball, which contains all these files.
Feel free to use these graphics on your own project, just give me some credit. (Creative Commons Attribution-ShareAlike)
I've just submitted my iconset to batterymon issue tracker.
hibernate, suspend, sleep states
You know what's cool with notebooks? Telling them to sleep (in order to save battery) and later waking them up when you need. Such things are supposed to be fast, and are also supposed to restore the system to the exact same state it was right before sleeping.
I must admit, all MacBooks can sleep/hibernate so well that it is very transparent and very fast to the final user. Unfortunately, PCs can't be as fast as that, but I will be happy enough to have any kind of working sleep/hibernate on my Gentoo/Linux notebook.
How to configure it
I followed the Gentoo official Power Management Guide, and it really worked as advertised. I got it working at the first try!
In summary, I've installed gentoo-sources kernel (I don't know if it works on vanilla-sources, and I didn't want to try), configured a few options in the kernel and in grub (as described in the guide), emerged hibernate-script, added the cleanup script to the boot runlevel (rc-update add hibernate-cleanup boot), and slightly tweaked /etc/hibernate/common.conf. Just that, nothing more.
How to use it
To hibernate to RAM, I just run (as root) hibernate-ram. A few seconds later, it's done! The power-on LED will be blinking very slowly, and any keypress will wake up the system. (and waking it up also takes just a few seconds)
To hibernate to disk, I run (as root) hibernate. This takes a relatively long time, as all RAM will be written to disk. I think this takes almost the same amount of time as shutting down the system. To wake up, I press the power button, which will start the BIOS, then run Grub, load the kernel, and then restore the RAM contents. This also takes a long time, but the advantage is to have your desktop back to the same state it was.
And that's it! Very simple and easy. Basically, all the default configuration worked. I'm really impressed by how easy it was, and how well it worked. I can't say it's flawless, because I've not used it long enough.
Configuring the laptop's sleep button
I've also configured acpid to hibernate when I press the sleep button on my notebook (in my case, Fn+F1). I just created a file /etc/acpi/events/button_sleep with the following contents:
event=button[ /]sleep action=/etc/acpi/actions/button_sleep.sh %e
And then created a small shell script /etc/acpi/actions/button_sleep.sh that just calls hibernate (or hibernate-ram). And set chmod +x on that script. And also restarted acpid daemon after making changes to /etc/acpi/events/*
That's all, and that's also simple!
Now, what I want to do is show a dialog asking to hibernate to RAM or to disk upon pressing the sleep button. Unfortunately, I still don't know how to do this (because that script runs as root by acpid).









How to use Quote function: