[ltp] How can i suspend to ram?

Richard Neill linux-thinkpad@linux-thinkpad.org
Sat, 05 May 2007 07:25:15 +0100


venture Lee wrote:
> hi all
> i need suspend my gentoo to ram, my kernel version is 2.6.20
> how can i write the sleep script ?
>

I'm somewhat tempted to say "don't". There ought to be a wiki page about 
how it works (or look at s2ram). I'd advise against writing it yourself, 
unless you want to spend a long time debugging (and rebooting). At any 
rate, you need to care about:

make ACPI trigger a suspend script from Fn-F4.
save files
lock screen (and any virtual terminals)
save sound, network state
If necessary, kill any app/mixer that uses sound. [exception: ALSA,
  usually]. Else, you'll find it has a lock on the sound card, so the
  module can't be unloaded, so it can't later be re-loaded. If firefox
  has a tab with a flash-plugin, you have to close this.
eject (in software) any PCMCIA cards
eject any mounted filesystem on removable media eg USB key that might
   not be there when you resume.
chvt 1
save video bios state (probably).
sync
[optionally, save to disk, so that you can restore in case of subsequent 
battery failure, or crash.]
tell the kernel to suspend - using ACPI (or perhaps APM).
   [wait]
resume. Hope it works.
re-start video bios if necessary.
remount filesystems.
cardctl insert for PCMCIA cards (if necessary).
Restart network.
Restore sound and mixer levels.
Unblank screen (to screensaver, not black)
Prompt for screensaver password.


HTH,

Richard


P.S. I did something like the above for Mandriva 11.0 - their script 
would always hang the machine. I'd strongly advise not re-inventing this 
particular wheel, iff you can find a working example.
   http://www.richardneill.org/a22p-mdk11-0.php#suspend


P.P.S. There is a lot to be said for suspend-to-disk instead. Do 
consider it as an alternative. It's not very much slower, and tends to 
be more reliable.