# HOWTO: Getting APM suspend to work

## thechosen0ne

Despite my best searching, the documentation out there for setting up APM suspend seems to be pretty minimal. I realize that ACPI is the new standard, but the code and drivers out there still seem to be in the developing stages. Here goes. I used an IBM Thinkpad 600x for this, but it should be pretty generic as long as your computer's bios  supports APM.

1. Compile APM into your kernel

Make sure your /usr/src/linux symlink points to your kernel source folder

```

#cd /usr/src/linux

#make menuconfig

Power management options (ACPI, APM)  ---> 

  [*] Power Management support   

ACPI (Advanced Configuration and Power Interface) Support  --->

  [ ] ACPI Support

APM (Advanced Power Management) BIOS Support  --->

<*> APM (Advanced Power Management) BIOS support

  [ ]   Ignore USER SUSPEND

  [*]   Enable PM at boot time

  [*]   Make CPU Idle calls when idle

  [ ]   Enable console blanking using APM

  [ ]   RTC stores time in GMT

  [ ]   Allow interrupts during APM BIOS calls

  [ ]   Use real mode APM BIOS call to power off

```

Then save and exit.

You may have to change one or more of the APM options to make things work correctly, but this should give you the best default power management using APM. If you have problems suspending later on, try a different kernel configuration to see if it works.

Next, compile and copy your new kernel into /boot (done with 2.6 kernel, check handbook for 2.4 commands)

```

#make bzImage modules modules_install 

#mount /boot

#cp arch/i386/boot/bzImage /boot/kernel-2.x.y

#cp System.map /boot/System.map-2.x.y

#rm /boot/System.map

#ln -s /boot/System.map-2.x.y /boot/System.map

```

now before you unmount /boot, run

```

#nano -w /boot/grub/grub.conf

```

and add the parameter apm=on acpi=off to your kernel parameters

The code is the same for lilo, just a different file. Once you are done with this part, you can unmount /boot and reboot with your new apm-ready kernel!

2. Emerge and Test ampd

ampd is a daemon that handles apm requests, basically, the thing that allows you to tell the computer to suspend. Emerging is pretty straightforward, run 

```
#emerge apmd
```

Now you want to start apmd and use rc-update to make it run at boot

```
#/etc/init.d/apmd start

#rc-update add apmd default
```

Configuration shouldn't take much as long as you have apm support in your kernel. To test that apm works, you should be able to do the following:

To see information about AC status and battery info

```
#apm
```

To standby (on my system just turns the monitor off)

```
#apm -S
```

To suspend (the real goal of this howto)

```
#apm -s
```

If these commands don't work, go back to Step 1 and check out the kernel options. Some computers have weird BIOS's that linux has ways around using the different options. Otherwise, continue on.

3. Configure apmd Events

You may notice after suspending that your network card or sound stops functioning. Fortunately, apmd has a way around this, using scripts placed in /etc/apm/event.d/ . They are executed every time the system suspends/resumes. Here are the scripts in my event.d directory, you can add your own if you have other things you would like run on suspend/resume:

/etc/apm/event.d/alsa

```

#!/bin/sh

#<br />

case "$1" in

resume)

        /etc/init.d/alsasound start

        ;;

suspend)

        /etc/init.d/alsasound stop

        ;;

esac

```

/etc/apm/event.d/usb

```

#!/bin/sh

case "$1" in

        suspend)

                /etc/init.d/hotplug stop

                ;;

        resume)

                /etc/init.d/hotplug start

                ;;

esac

```

/etc/apm/event.d/pcmcia

```

#!/bin/sh

case "$1" in

        suspend)

                /sbin/cardctl eject

                ;;

        resume)

                /sbin/cardctl insert

                ;;

esac

```

The pcmcia script will cause any pcmcia cards to be reloaded (network cards, etc). It is like pulling the card out of the slot and reinserting it.

Make sure that for each script you make it executable using 

```
chmod +x scriptname
```

Now when you run apm -s you should have sound, usb, pcmcia working when you resume. You can check the output of #dmesg and it should have some info about things that have been restarted. That's it! Please let me know if I forgot anything!

EDIT: I'm going to start experimenting with ACPI, because I think support is finally starting to come around for my Thinkpad 600X... we'll see. I'll post a similar howto if I get it working.

RE-EDIT: I seem to have found a howto, check it out. I certainly will https://forums.gentoo.org/viewtopic.php?t=147898Last edited by thechosen0ne on Thu Jun 03, 2004 6:07 am; edited 3 times in total

----------

## MaxDamage

I'm recompiling the kernel right now. When I reboot I will tell you the results. I thought suspending under Linux wasn't possible  :Razz: 

My desktop PC is an Athlon XP 2000, 512MB RAM PC-333, and Gigabyte GA-7VAX board with KT400a chipset, integrated via82xx soundcard and integrated realtek ethernet card.

EDIT: Yes, both suspend and standby work. Nice guide  :Wink: 

----------

## FonderiaDigitale

You can simply differentiate scripts by their own name

/etc/apm/SERVICE_NAME

```

#!/bin/sh

case "$1" in

        suspend)

                /etc/init.d/$0 stop

                ;;

        resume)

                /etc/init.d/$0 start

                ;;

esac

```

and symlink /etc/apm/SERVICE_NAME to eg. /etc/apm/event.d/usb

this except, obviously, pcmcia.

BTW, thanks for this guide  :Smile: 

----------

## Gatak

How does this work with ACPI? There used to be a conflict between APM and ACPI in 2.4 kernels. Is is still in 2.6?

----------

## Phk

 *thechosen0ne wrote:*   

> Despite my best searching, the documentation out there for setting up APM suspend seems to be pretty minimal.
> 
> [...]
> 
> That's it! Please let me know if I forgot anything!

 

Excellent Post, chosenOne! Speakin for me (and many more probably):

THANKX  :Wink: 

----------

## Phk

However........ even doing this i still have a problem:

My "apmd" give a "Oops" crash.... With lots and lots of error-messages.... 

Anyone knows about this ?

----------

## agaffney

I seem to have a problem with this on my Thinkpad 770. I'm running gentoo-dev-sources-2.6.4. My PCMCIA NIC is a D-Link DWL-AB650 802.11b card. I'm currently using Linuxant driverloader with it due to weird problems with madwifi-drivers.

When I suspend ('apm -s' or Fn-F4) and bring it back up, the NIC comes back up (blinking lights) but it doesn't have an IP. If I manually run '/etc/init.d/net.eth0 restart' it takes a few minutes to come back up, but it does work again.

Can I automate this with these scripts (I know the answer is yes, but I'm asking anyway)? Why does it take so long to come back up?

----------

## agaffney

After a little playing around, if I run 'iwconfig eth0 essid "myessid"' and then '/etc/init.d/net.eth0 zap; /etc/init.d/net.eth0 start' right after resuming, it comes up very quickly. It seems to have a hard time associating with the AP. It sees it and is on the correct channel, but it doesn't set the ESSID correctly. Anyone know why?

----------

## stahlsau

hi,

nice howto. I´m using ACPI, but the idea about killing alsasound before going asleep helps for that as well  :Wink: )

thx!  :Smile: 

----------

## Phk

Sorry to bother you all with this again, but:

After doing everything, and turning on APM, ACPI off, and adding APMD to rc-update, i get a strange "Segmentation Fault", or "OOoops" crash whenever i try to load "apmd".... 

What's the problem here? This computer is a laptop, and if suspends perfectly under microshit's os..

Do i need to re-emerge anything?

thanks for the attention []

----------

## thrasher6670

I have added this to gentoo-wiki.com 

http://gentoo-wiki.com/HOWTO_APM_Suspend

If anyone sees any changes that need to be made, feel freed to add them, It is a wiki afterall

great HOWTO BTW

----------

## Phk

That's a nice WIKI, that's for your contribution...

BUT!! There's one topic no one ever answered me:

I had the whole system emerged, with APM=OFF and ACPI=ON.

Now, when i do the WIKI steps, i get a "segfault" each time i run apmd or i try to suspend....

WHAT or DO i have to re-compile?  :Sad: 

----------

## polymorf

Hrm. I went through these steps and they arn't working for me. 

I'm running a dell L400. I've compiled support for APM in because in dmesg states that my bios is old and doesn't support ACPI.

then i emerged apmd and it seems to be running fine, but when i run apm -S nothing happens. Even better when i run apm -s, the system seems like its going to suspend - the screen blanks but after a second or so it comes back with:

apm: Input/output error

Anyone seen this before?

thanks!

poly

----------

## stahlsau

nope, works here.

Only thing is, sometimes after coming back it opens 317 instances of mozilla, and my aterm scrolls like hell  :Wink:  Dunno what causes this, but i had to laugh so much when it opens 317 mozillas that i didn´t have the chance to get annoyed *lol*

----------

## phuber

I'm having a few troubles getting all this to work. Basically suspend and resume work but the suspend doesn't seem to get called...

My Scripts:

```

#!/bin/bash

#/etc/apm/event.d/ac-power

case "$1" in

        change)

                if [ `cat /proc/apm | cut -d"x" -f3 | cut -d" " -f1` -eq "00" ];

                then

                        sync

                        laptop-mode start

                else

                        laptop-mode stop

                fi

        ;;

esac

```

```

#!/bin/bash

#/etc/apm/event.d/on-off

logger "script called with: 0:$0 1:$1 2:$2 3:$3 4:$4 5:$5"

case "$1" in

        suspend)

                logger "Shutting down hotplug, vpn, eth0, ath0 - syncing discs"

                /etc/init.d/hotplug stop

                sudo phuber vpnclient disconnect

                /etc/init.d/net.eth0 stop

                /etc/init.d/net.ath0 stop

                sync

                sleep 1

        ;;

        resume)

                logger "Starting hotplug, eth0, ath0"

                /etc/init.d/hotplug start

                /etc/init.d/net.eth0 start

                /etc/init.d/net.ath0 start

        ;;

esac

```

When I issue "apm --suspend" on the console I get:

```

Jun 30 20:14:38 deadbeef logger: script called with: 0:/etc/apm/event.d/on-off 1:suspend 2:user 3: 4: 5:

Jun 30 20:14:38 deadbeef logger: Shutting down hotplug, vpn, eth0, ath0 - syncing discs

Jun 30 20:15:27 deadbeef logger: script called with: 0:/etc/apm/event.d/on-off 1:resume 2:suspend 3: 4: 5:

Jun 30 20:15:27 deadbeef logger: Starting hotplug, eth0, ath0

```

When I just close the lid I get:

```

Jun 30 20:16:19 deadbeef logger: script called with: 0:/etc/apm/event.d/on-off 1:resume 2:suspend 3: 4: 5:

Jun 30 20:16:19 deadbeef logger: Starting hotplug, eth0, ath0

```

The apmd version is 3.0.2-r3

Does anyone know why this happens how I can get it working correctly? Thanks!

----------

## Caalvin

hi, first of all, thanks a lot for the hints....

but there is one problem left for me.

a few weeks ago, it possible to set my notebook to suspend by closing the lid, but now it freezed when close the lid. Is there anyone, who has an idea what i have to do...

the notebook is an DELL latitude csx (P3-500)

ciao 

torsten

----------

## BTR

What if you want certain services to remain on?  Whenever I come out of suspension, eth0 is up fine, but I want it to [i]remain[/i] on while my system's suspended, so I can go away and still access my computer remotely (I have a desktop).  As is it seems like the network device goes down while my system's suspended, and that is NOT the behavior I want.

----------

## boltronics

BTR, sounds like you want standby mode instead of suspend mode. See the first post for screen blanking (apm -S). In suspend mode, I believe the CPU goes to sleep and can't be used (hence goes your networking and everything else).

----------

## crafteh

How can I get my keyboard to work after I resume from suspend?

----------

## tam

My Thinkpad T23only suspend if I (auto)load yenta_socket as module and unload this module before suspend:

/etc/apm/event.d/pcmcia

```
#!/bin/sh

case "$1" in

        suspend)

                /sbin/modprobe -r yenta_socket

                /sbin/cardctl eject

                ;;

        resume)

                /sbin/modprobe yenta_socket

                /sbin/cardctl insert

                ;;

esac
```

Too bad, I can't use my wireless LAN card after suspend anyhow.

----------

## biatch0

Here's a question... I've got a Dell Latitude L400, Gentoo is running perfectly with the exception of APM; the only one small problem I have is suspend/wakeup. During short suspend periods of maybe up to one hour, the laptop wakes up perfectly to whatever it was doing before... however, occasionally it refuses to wake up giving me just a blank screen (the screen DID turn on) and nothing more (hammering caps lock would not turn on the blinky little light   :Rolling Eyes:  ).

Weird thing is that I can't see anything of interest showing up in the logs after a cold reboot (nothing else works). This is a cry for help BTW   :Embarassed: 

----------

## Ben2040

Hi

I have a real old Dell Latitude (100Mhz), running Debian, and I did nothing to set up apm or suspending - It just works! I can type apm t check battery, or run a WindowMaker Dockapp for it, and I can press "Fn+Suspend" t osuspend, which turns of the PCMCIA and everything correctly. With or without X running I can then open the lid/press a button to resume and the net comes back up and everything is peachy  :Smile: 

Does Debian include this style of event scripts?

Ben

----------

## badgers

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I followed this with the 2.6.9 love kernel

when I do apm -s the system spins down(the fan on the cpu keeps running) but I can hear the hard drive spin down

then 2 seconds later it starts back up again without me touching anything.

WTF

when you have the choice of the suspend partion, what should I tell it?

/dev/hda3 is what I have

----------

## Swift

got it working on my t42, only problem left, the script in event.d doesn't seem to be executed (and yes, it is chmod +x)

anyone knows a possible reason?

/e:

solved with:

```
[*]   Allow interrupts during APM BIOS calls 
```

----------

## Caalvin

works fine on my Dell Latitude csx.

----------

## eduardo451

I know this page is older than dirt, but thought you'd like to know it's still helping people.  I recently updated my kernel, and switched from pcmcia-cs to pcmciautils, and my computer would lock up coming out of suspend.  I discovered that lockups did not occur when physically removing my wireless card before suspending, and the pcmcia eject script fixed the issue for me.  It's now behaving as it used to.  Thanks!  For those who now encounter this issue, it seems /sbin/pcardctl has replaced /sbin/cardctl.

EDIT

Hmmm. . . It works well for me when only briefly in standby, but I just tried bringing it back up after being down for a few hours, and not only did my wireless not come back up, neither would my monitor.  And so it goes.

EDIT

SUCCESS!!!  It turns out I didn't need any of the pccardctl stuff.  What I did need was to remove my ndiswrapper module before suspending.  Not sure why this is suddenly necessary, but it works.  I went the route of using separate suspend and resume scripts, as described in the wiki based on this thread.  In the suspend script I have it stop my wireless and rmmod ndiswrapper, and the resume script restarts my wireless.  That's it.

----------

## tekknokrat

as i have problems with acpi and an old toshiba satellite pro 4600 i will try fixing things with apm.

new location of howto moved to http://gentoo-wiki.com/HOWTO_Getting_APM_Suspend_to_Work

----------

