Suspend script (for laptops)

Using applications, configuring, problems
Message
Author
User avatar
debernardis
Posts: 180
Joined: Sat 12 Nov 2005, 08:01
Contact:

Suspend script (for laptops)

#1 Post by debernardis »

I modified the script suggested by Lobster (here) as follows:

Code: Select all

#!/bin/sh

# this script was adapted for Puppy 2.12 by EdB, from the original in
# http://www.linux.com/article.pl?sid=06/05/24/1716222

# discover video card's ID
ID=`lspci -i /usr/share/pci-usb-pcmcia.ids | grep VGA | awk '{ print $1 }' | sed -e 's@0000:@@' -e 's@:@/@'`

# securely create a temporary file
TMP_FILE=`mktemp /var/tmp/video_state.XXXXXX`
# trap 'rm -f $TMP_FILE' 0 1 15

# switch to virtual terminal 2 to avoid graphics
# corruption in X
chvt 2

# write all unwritten data (just in case)
sync

# dump current data from the video card to the
# temporary file
cat /proc/bus/pci/$ID > $TMP_FILE

# suspend
echo -n mem > /sys/power/state

# restore video card data from the temporary file
# on resume
cat $TMP_FILE > /proc/bus/pci/$ID

# switch back to virtual terminal 3 (running X)
chvt 3

# remove temporary file
rm -f $TMP_FILE

# needed by my wlan internal card!
iwconfig wlan0 essid any
This works on my 2.12-based rudypuppy, on an hp pavilion zv6278ea.

Please test it on your laptops and let me know... I plan to include it in my next puplet

User avatar
rarsa
Posts: 3053
Joined: Sun 29 May 2005, 20:30
Location: Kitchener, Ontario, Canada
Contact:

#2 Post by rarsa »

Jutst a comment on this part:

Code: Select all

# needed by my wlan internal card! 
iwconfig wlan0 essid any
The network wizard creates the scripts /etc/wlan0wireless and /etc/wlan0mode

It may be preferrable to execute those files when waking up instead of adding custom code to your script.

I will test tomorrow :)

cheers
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to

User avatar
debernardis
Posts: 180
Joined: Sat 12 Nov 2005, 08:01
Contact:

#3 Post by debernardis »

rarsa wrote: The network wizard creates the scripts /etc/wlan0wireless and /etc/wlan0mode

It may be preferrable to execute those files when waking up instead of adding custom code to your script.
Unfortunately those files are not executable in my puppy.
Why?
I'll see now if in a plain puppy it's like that too.

EDIT: also in a plain 2.12 puppy those files are not executable.

EDIT EDIT: is this the right way to do that?

Code: Select all

 cat /etc/wlan0wireless|sh
cat /etc/wlan0mode|sh
It works indeed :roll:

Braden
Posts: 69
Joined: Fri 22 Sep 2006, 20:39
Location: Waterloo, Ontario, Canada

#4 Post by Braden »

That works, but the canonical technique is to use the source command:

Code: Select all

source /etc/wlan0wireless
source /etc/wlan0mode

User avatar
debernardis
Posts: 180
Joined: Sat 12 Nov 2005, 08:01
Contact:

#5 Post by debernardis »

Braden wrote:That works, but the canonical technique is to use the source command
Thanks, that works too, and I have learned one other thing :D

Now I have seen that this script works only with Xorg, but not Xvesa. Can you confirm?

User avatar
rarsa
Posts: 3053
Joined: Sun 29 May 2005, 20:30
Location: Kitchener, Ontario, Canada
Contact:

#6 Post by rarsa »

I execute them with

Code: Select all

sh /etc/wlan0mode
The scripts are independent of the X driver you are using. I don't see a reason why Xorg or XVesa would have anything to do with these scripts.

**EDIT** :oops: Oh, you mean the suspend script.
Last edited by rarsa on Tue 05 Dec 2006, 05:04, edited 1 time in total.
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to

Braden
Posts: 69
Joined: Fri 22 Sep 2006, 20:39
Location: Waterloo, Ontario, Canada

#7 Post by Braden »

Does Xvesa react badly to having its proc entries accessed (less likely) or modified (more likely)? Are they formatted the same?

When it doesn't work with Xvesa, does it refuse to suspend, refuse to resume? Crash? When?

User avatar
rarsa
Posts: 3053
Joined: Sun 29 May 2005, 20:30
Location: Kitchener, Ontario, Canada
Contact:

#8 Post by rarsa »

Well, It worked for me! No problems, no freezes.

Dell Latitude D610.

I made a small change to the script to make it 100% generic.

I've revised my advice and at the end of the script instead of

Code: Select all

# needed by my wlan internal card! 
iwconfig wlan0 essid any
I am advising to do

Code: Select all

# needed to restart network connections! 
source /etc/rc.d/rc.network
To start the network connections as if the computer was just booting.

Of course, that will only work if the user used the network wizard to setup the network and saved his/her configuration. But as that is the recommended way of setting a connection then I guess is the best we can do.
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to

User avatar
debernardis
Posts: 180
Joined: Sat 12 Nov 2005, 08:01
Contact:

#9 Post by debernardis »

OK, Rarsa's call to rc.network works for me, too.

Now, the problems:

1. in XORG, when I am back from the suspend script, I find that the consoles #1 and #2 (ctrl-alt-f1 and ctrl-alt-f2) do not show the normal 640x480 video mode any more. Console #1 has an abnormal video mode with expanded chars, and console #2 sports some grey and black stripes. In console #2, the "reset" command restores an expanded char mode like in console #1.
I don't know how to restore the normal 640x480, 80x25 text mode.
X in console #3 (ctrl-alt-f3) has no problems.
This is quite a problem when, i.e., you exit from X to prompt in console #1, because you won't be able to see console output except for the leftmost chars of each line.

2. in XVESA, I do confirm that the script suspends my machine but does not restore X. Interestingly, even before you even start the suspend script, XVESA seems unable to change to console with ctrl-alt-f2 and back to X with ctrl-alt-f3, because X gets corrupted, so maybe there is a bug in console switching under Xvesa.
This seems to be already known: http://www.murga-linux.com/puppy/viewto ... ole&t=5580

Brian C
Posts: 168
Joined: Thu 09 Feb 2006, 04:19

#10 Post by Brian C »

The script from your first post works almost PERFECTLY on my Dell Inspiron e1405. The only thing I've noticed is that when I come back, my screen is stretched to the full display (I only have it set for 1280x800, still working on making 1440x900 work) instead of being 1-1 pixels. Thanks so much!

User avatar
debernardis
Posts: 180
Joined: Sat 12 Nov 2005, 08:01
Contact:

#11 Post by debernardis »

Brian C wrote:The only thing I've noticed is that when I come back, my screen is stretched to the full display
I don't know if it may help you, but try to open a console terminal and give the command xrandr. You will see several video modes like those:

Code: Select all

sh-3.00# xrandr
 SZ:    Pixels          Physical       Refresh
*0   1280 x 800    ( 433mm x 271mm )  *60  
 1    640 x 350    ( 433mm x 271mm )   60  
 2    640 x 400    ( 433mm x 271mm )   60  
 3    720 x 400    ( 433mm x 271mm )   60  
 4    640 x 480    ( 433mm x 271mm )   60  
 5    800 x 600    ( 433mm x 271mm )   60  
 6   1024 x 768    ( 433mm x 271mm )   60  
 7    832 x 624    ( 433mm x 271mm )   60  
 8   1152 x 768    ( 433mm x 271mm )   60  
Current rotation - normal
Current reflection - none
Rotations possible - normal 
Reflections possible - none
Next, choose the one you like (suppose is #6, 1024x768) and give xrandr -s 6... your screen resolution should change accordingly.
Maybe this can restore your optimal resolution.

EDIT: :roll: hehehe I forgot you could do that in a gui-style by firing the Xorg video wizard and choosing the resolution changer
Last edited by debernardis on Wed 06 Dec 2006, 06:40, edited 1 time in total.

User avatar
debernardis
Posts: 180
Joined: Sat 12 Nov 2005, 08:01
Contact:

#12 Post by debernardis »

To better understand the screen problems in virtual console #2 that I get after running the suspend script, here's a photo.
I tried to reset the video mode of the text console by running a program, SVGATextMode, which according to its Authors should reset or modify the video mode of virtual consoles, but with no joy.

This problem is quite annoying and I hope that somebody helps me fixing.
Attachments
foto_schermo_320.jpg
(78.09 KiB) Downloaded 7239 times

User avatar
rarsa
Posts: 3053
Joined: Sun 29 May 2005, 20:30
Location: Kitchener, Ontario, Canada
Contact:

#13 Post by rarsa »

I didn't find that problem. I was able to restart the computer and switch virtual consoles with no problem.
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to

emike
Posts: 6
Joined: Sun 24 Dec 2006, 00:44

Suspends put doesn't Resume

#14 Post by emike »

Hey guys (and gals if appropriate),

Kudos for working on this project! I would come close to Puppy Nirvana if I could get it to Suspend and Resume like Windoze on my NC4010 Compaq Laptop. I am an admitted linux and Puppy noob so please excuse me if I ask or say something stupid.

The script powers down my laptop without a problem, but when I power back up, I get a blank screen without even a blinking cursor. Ctrl-Alt-Backspace has no effect and attempting to change consoles with the Ctrl-Alt-F1 to F4 also has no effect. I am running IceWm if that makes a difference although I went back to JVM just to see the script would work there and it did the exact same thing.

Any help at all would be most appreciated. Thanks a million from a grateful and very happy Puppy user.

User avatar
debernardis
Posts: 180
Joined: Sat 12 Nov 2005, 08:01
Contact:

#15 Post by debernardis »

It is difficult to spot the problem. One point is that in my experience the script works,in Xorg, but fails in Xvesa. Could this be the culprit? If you have enabled Xvesa, you can turn to Xorg (among other methods) by exiting to prompt and running 'xorgwizard'.
Otherwise, that might be something specific to your graphics adapter. You could google for 'suspend + the name of your adapter' on google linux ( http://www.google.com/linux ) to see if there are known issues.
In each case, please post your experiences here, so that you can contribute to the development of the suspend feature 8) 8) 8) 8)

emike
Posts: 6
Joined: Sun 24 Dec 2006, 00:44

Using Xorg, Resume fails

#16 Post by emike »

Hey debernardis!

thanks for taking the time to respond to my problem. I wanted to get right back to you with the information that I am using Xorg. I may have Xvesa enabled, but I am running IceWM with Xorg. I double-checked this by using the Xorg Video Wizard to change my screen resolution. It worked so I'm guessing that's proof positive that I'm on Xorg.

I did some surfing on Google as you suggested but unfortunately, I'm not sharp enough on my Linux lingo to make heads or tails of what's being said.

Again, I appreciate your willingness to help. I'm posting my script here just in case I copied something wrong:

#!/bin/sh

# this script was adapted for Puppy 2.12 by EdB, from the original in
# http://www.linux.com/article.pl?sid=06/05/24/1716222

# discover video card's ID
ID=`lspci -i /usr/share/pci-usb-pcmcia.ids | grep VGA | awk '{ print $1 }' | sed -e 's@0000:@@' -e 's@:@/@'`

# securely create a temporary file
TMP_FILE=`mktemp /var/tmp/video_state.XXXXXX`
# trap 'rm -f $TMP_FILE' 0 1 15

# switch to virtual terminal 2 to avoid graphics
# corruption in X
chvt 2

# write all unwritten data (just in case)
sync

# dump current data from the video card to the
# temporary file
cat /proc/bus/pci/$ID > $TMP_FILE

# suspend
echo -n mem > /sys/power/state

# restore video card data from the temporary file
# on resume
cat $TMP_FILE > /proc/bus/pci/$ID

# switch back to virtual terminal 3 (running X)
chvt 3

# remove temporary file
rm -f $TMP_FILE

# needed to restart network connections!
source /etc/rc.d/rc.network

User avatar
debernardis
Posts: 180
Joined: Sat 12 Nov 2005, 08:01
Contact:

#17 Post by debernardis »

Bad news.
From http://www.netsplit.com/text/nc4010.html : Suspend is sadly a different matter, this is still one area that Linux doesn't really support yet. I'm able to instruct the laptop to enter S3 (RAM suspend) easily enough but neither the keyboard, mouse nor network come back afterwards. I've had a little more success with S4 (disk suspend) when using swsusp2 but have decided to simply switch the laptop on and off while travelling for the time being — it boots fast enough to make this feasible.

From http://lackof.org/matt/hacking/hpnc4010/ : ACPI and APM suck. What I want is "suspend to RAM", this currently doesn't work in ACPI (I tested with latest firmware (f.2f) and 2.6.11). It does work in APM, but you can't use the power button to put it to sleep, because if you don't have the button setup with ACPI the BIOS just tells the machine to shut off. So you have to put the machine to sleep with "apm -S". ACPI has some nice features, like the stuff in /sys and button/fan/temp/etc. it would be nice if we had a complete ACPI solution. There are more details on Martin's page

It is reported as a problem in ACPI - see http://www.mail-archive.com/acpi-bugzil ... 05007.html -
I have HP compaq nc4000 laptop and it is exhibiting the same problem. suspend to
ram works but resume never reaches the linux kernel.

emike
Posts: 6
Joined: Sun 24 Dec 2006, 00:44

Suspend a No-Go for NC4010

#18 Post by emike »

Thanks a million debernardis! :D
Bad news.
From http://www.netsplit.com/text/nc4010.html : Suspend is sadly a different matter, this is still one area that Linux doesn't really support yet. I'm able to instruct the laptop to enter S3 (RAM suspend) easily enough but neither the keyboard, mouse nor network come back afterwards. I've had a little more success with S4 (disk suspend) when using swsusp2 but have decided to simply switch the laptop on and off while travelling for the time being — it boots fast enough to make this feasible.
This obviously wasn't what I was hoping for, but you certainly provided me with the reason and in lightning fast fashion. I appreciate your efforts on my behalf and the behalf of the rest of the NC4010 Puppy users. Gives me a justification for getting a new laptop now. :wink:

Thanks again,
emike

Brian C
Posts: 168
Joined: Thu 09 Feb 2006, 04:19

#19 Post by Brian C »

This script handles the opening anc closing of the laptop display pretty well. Could that be incorporated into the next release of Puppy, so that I can close my laptop lid and open it again with my graphics still working?

User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

#20 Post by HairyWill »

Doesn't work for me on a thinkpad x30 830mg graphics uses i810 xorg driver.
I've tried inserting echos to file after every instruction each of the suspend lines completes but nothing gets written after I power up after
echo -n mem > /sys/power/state
I get spinning disks one or two beeps a flashing LED and a black screen. To recover from this I have to power off.
I've compared /var/log/messages with a normal shutdown reboot cycle and the suspend script is generating anything there but I presume it wouldn't if the kernel isn't coming back.
Nice try but at less than a minute to boot I'm not too bothered. I don't think that my laptops ACPI implementation is particularly good anyway.
Happy to test further if anyone gets any good ideas.
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

Post Reply