My current laptop is a ThinkPad Edge E130 and I really like it, except for a terribly annoying bug which affects lots of Linux distributions (possibly all of them): if you shutdown your distro, you might have your laptop rebooting instead of shutting down as expected. If you don’t even know that this bug exists, you might experience bad situations like shutting down your pc, put it in your bag and then realize, many hours later, that the battery of your laptop is gone. Of course this is something that actually happened to me.
It’s still not clear where the bug comes from, since it affects many different ThinkPad models and even some non-ThinkPad laptops (e.g. some Acer models). That’s why you may find lots of solutions in the web, but which one is the right one? Some people reports that the bug is defeated by installing the
laptop-mode-tools package. According to other people there are some kernel modules to be removed just before the shutdown.
I’ve finally managed to find the right fix for the ThinkPad Edge E130 and I will share it in this post.
I’ve tested it on a Debian Sid system which uses
systemd as init manager. It should also work for other
Step 1: the solution
The solution that makes the ThinkPad always shutting down as requested is a simple bash script with the following content:
This script has to be run just before the system shutdown in order to fix the bug. What does the script actually do? It’s hard to tell, but somehow the kernel takes a complete power-management control and is able to make a working shutdown. The value
on written by the script overwrites many existing
auto values, and probably one (or more) of them causes the bug.
Step 2: creating the solution
You can put the above script wherever you want. In this example we’ll use
/usr/local/bin/shutdown-fix.sh. You just have to make sure to make it executable:
Step 3: installing the solution
The script has to be run before the system shutdown. In the
systemd world, this means that you have to create a custom
service which executes the script at the right moment.
You should create a
shutdown-fix.service file in either
/etc/systemd/system/ or in
/usr/lib/systemd/system with the following content:
ExecStart entry is executed on system startup and that’s why we use
/bin/true, which does nothing. We are interested only in the
ExecStop entry and that’s where you have to put the script from the previous step.
Finally, you have to enable the service and we’re done:
So, this solution is
systemd specific. If you still use the old
OpenRC, you have to use your distro specific’s way to run scripts on shutdown.