Wed Oct 26 20:59:32 EST 2005

Thinkpad T30 - Hotswap, and Software Suspend


One of the things that I've gotten used to in Windows is the nice Hibernate feature. I like to just close my laptop and have it suspend to disk then quickly resume. I'll do this several times a day during my work. I figured, if Windows can do it, then Linux should be able to do it better right? :D

Well, it wasn't exactly easy but it built on what I learned messing with ACPI as I talk about in my last post. First of all, there really isn't any specific documentation for Slackware when it comes to suspend to disk that I could find. But, I found some info on Gentoo, Debian, and Fedora which was useful. Now it turns out that in the 2.6.13 kernel (and possible older ones I don't know) that there is already a suspend to disk feature right under power management in your menuconfig. I gave that a shot and lets just say it doesn't play well with my Thinkpad. Basically I can suspend it but it never comes back. It tries to resume but then locks.

Some more research pointed me to a project called Software Suspend 2 for Linux that actually works. Basically it consists of a kernel patch for the vanilla 2.6.13 kernel and a hibernate script. Both the patch and the support scripts are super easy to install. The documentation and the FAQ are really nice on their site. Once you compile the kernel with suspend2 enabled you can either suspend to a file or to swap space. To resume you just add an option to your lilo.conf or your grub menu.lst file to tell the kernel where you expect a suspend file or partition. Then all you have to do it type hibernate and it will suspend to disk. They even have a tip on how to setup sudo so you can hibernate without being root which lets you use it in something like Klaptop to hibernate the system when the batter gets critically low.

This is all well and good but I want to set this up so that it will hibernate when i close the lid of the laptop regardless of if I'm in KDE or at the console. Oh, and make sure not to use the hibernate function of Klaptop with suspend2. It corrupted my drive so bad I had to reinstall. I'm thinking it may have been something I did wrong in the hibernate.conf file but since I'm not planning on using klaptop to take care of the lid I didn't look into it.

Anyway, I figured acpid would be the way to go to catch the lid button event and have it run hibernate for me. Watching /var/log/acpid gave me a event called "button/lid LID 00000080 00000001" but I found out the hard way that it actually counts up such that the last bit of it changes. Pressing the button counts as an event as well as releasing it. So I couldn't just check for the entire thing. Also, I needed to make it only suspend on every other event. Otherwise it would suspend on the lid button press and would then suspend again right after the resume when it would get the lid button release. The suspend2 FAQ had the answer. Here is what worked for me:
event=button[/]lid LID.*[13579bdf]$
action=/usr/local/sbin/hibernate
I just stuck that in a file in the /etc/acpid/events directory along with my other events and issued a /etc/rc.d/rc.acpid restart and now the laptop suspends to disk perfectly every time I close the lid. As a point of interest I initially made the event expression to be event=button[/]lid LID.*[02468ace]$ which had the odd effect of only suspending the system when opened the lid.

One word of advice, if you try to set this up manually like I did rather than relying on your distro to set it up for you then do it on a test system. It seems that once you get it tweaked and working it works fine, but one mess up while learning it can irreversibly corrupt your file system. On, and one other thing of to note, read the section of the How to Avoid Data Loss section of the HOWTO if you mount a Windows partition to avoid killing your fat vfat or msdos partitions.

The other thing I did that was much easier than figuring out all this ACPI and suspend to disk stuff was figure out how to hot swap my drive bay so I can switch between my floppy and my CD-ROM without having to reboot. The utility to use is called Khotswap that sits in your system tray in KDE. The author also has a Gnome applet for it and it has a command line only version of itself just called hotswap and an X generic one called xhotswap.

So, at this point I'm well on my way to getting the foundation of the laptop done in Slackware enough to start thinking of setting up the rest to use for day to day work. I know, I could have used another distro and had much of this stuff work right out of the box. I hear Ubuntu is very good at this. But if I did that where would the challenge be and what would I learn in the process?

Posted by Brian | Permalink | Categories: Computers and Technology, Work | |