LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 06-20-2009, 03:12 PM   #1
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Lightbulb Suspend to ram/standby/(disk): Here's my flexible, adjustable 'suspend2' script.


What was initially a one-liner piece of code grew into this handy (imho) script which suspends your machine, using any/one of the methods currently supported by your machine; it detects what methods your machine currently has enabled, removes kernel modules you specify, offers time-delay and time-of-day suspend convenience, for those of use who like to forget to turn our machines off at night or want the machine to stay on long enough to finish a task, and then shut down. It can run from a crontab or via desktop icon if you like.

The comments in it are intended to be helpful, in case you need to adjust something for your machine/OS like paths to tools, troublesome kernel modules, etc., but ultimately it *should* be rather generic in its operation. READ THE COMMENTS. Feedback welcome.

NOTE: As you will read, suspend to disk has not been tested by me. If you do want to try it, make sure you have your bootloader configured with a suspend partition (swap space) first; this script assumes you have that prepared.

I hope you find this useful.

Works with Slackware64-current (as of v1.15 it still works with Slackware64 13.1 -current)

Code:
#!/bin/sh
# Release version: 1.15/Oct 20/2010
# /usr/bin/s2 -- offers some flexibility when locking/suspending your desktop.
# Does not use any LRMI or PCI-register weirdness. This script is intended
# for machines with non-crappy BIOSes and working ACPI implementations.

# Copyright (C) <2009,2010> <Sasha Alexandr> <crawlingwithsnakes at hush dot com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Testing done on: Slackware 11.0 - kernel 2.6.30
# Testing done on: Slack64-current  kernel=2.6.30.5
# Testing done on: Slack64-13.0     kernel=2.6.32.2
# Testing done on: Slack64-13.1+ (-current) kernel=2.6.35
# Testing hardware: MSI P6N-SLI-FI (MS-7350)
# Intel E2160 Core2 CPU
# nVidia chipset MCP51/430i BIOS 2.7
# Ethernet: Realtek 8211BL using forcedeth driver.
# Video: 2x eVGA eGeForce 7300/7200 PCI-E cards.
# Video: nVidia binary versions 185.18.31 through 256.35 (x86_64)
# DE: KDE 3.5.4 & xscreensaver for locking session.
# DE: XFCE in Slack64-current & xscreensaver for locking session
# DE: 2010: No more KDE - using small window manager now.
#--proposed changes (to do):---------------------------------
#--test 'suspend to disk' support (I don't use it yet)
#------------------------------------------------------------
#--<changelog:>     -----------------------------------------
# v1.01  - adjust 'Usage:' text; tidy some code.
#        - support _list_ of NICs; add logging yes/no option.
#        - divert net-restart output to $console.
# v1.02  - clean up some junk that was outputting to console.
#        - clarify comments & Usage:
#        - adjustable args for net & session-lock.
#        - add a bit more sanity checking.
# v1.03  - fix more ugly junk coming on screen after wake-up.
# v1.04  - kill undead forked process when cancel suspend.
#        - remove one function; put that code elsewhere.
# v1.05  - shorten help-page console output linewrap.
#        - clean code a bit.
# v1.10  - adjust/test for Slack64-current.
#        - clean code more.
#        - rename to /usr/bin/s2
# v1.11  - fixed POSIX compliance for shells other than Bash.
#        - fix console output so it doesn't scroll a mile down screen.
# v1.12  - check if user is root as required; or quit.
# v1.13  - fix 'help is displayed twice' when no args given.
# v1.14  - added code to detect which tty the script is called from
#          and return there upon resume. Thanks GazL & tredegar.
#        - tiny code adjustments.
# v1.15  - Fixed some logic errors for the "in????=??" delay settings areas
#        - which had escaped me previously.
#        - now disowning forked s2's so no crap on console upon resume.
#        - Observation: the code is getting convoluted. Needs a rework.
#--</changelog>
#-------------------------------------------------------------
#--<known bugs:>
# IF X is not running, using this script from a VT may result in no video
# after resuming. The machine is NOT hung - X can still be started normally
# (blindly) but the VT's seem to remain unusable. I may need to add some
# vbetool functionality to turn the video back on - or 'they' can fix that.
#--
# Upon resume, shell prompt is not quite returned to user. You gotta
# hit enter or whatever. Not sure why this is. If you fix it, let me know :-)
#--</known bugs>
#------------------------------------------------------------

setup () {
#-------------------------------adjustable stuff-------------
# unplug/reinsert any kernel modules you've determined
# cause problems suspending/resuming on your machine.
# If you use the hangcheck-timer, it MUST be a module and
# it MUST be removed before suspend, reinserted after resume.
# If hangcheck-timer is built static into the kernel, suspend
# will only work once; subsequent suspends will resume
# immediately all by themselves.
unplug_list="ohci_hcd forcedeth hangcheck-timer"
insert_list="ohci_hcd forcedeth" # if empty, unplug list is used
want_to_log_the_process='y' # change to y to log the suspend
# separate multiple NICs below with spaces like 'eth0 eth1'
# NICs using DHCP:
NIC='eth0' # stop this/these before suspending to ram/disk
#------------------------------non-adjustable stuff-----------
suspend2_log=/var/log/suspend2.log
log_pidfile=/var/run/suspend2_logpid
fork_pidfile=/var/run/suspend2_forkpid
pm_debug_exist=/sys/power/pm_test
version='1.15'
#--------------------------------adjustable stuff-------------
# Common paths to stuff - verify/adjust for your system:
kernel_log=/var/log/kernel
modprobe=/sbin/modprobe
hwclock=/sbin/hwclock
tail=/usr/bin/tail
ifconfig=/sbin/ifconfig
net_init_script=/etc/rc.d/rc.inet1
net_init_script_arg='restart'
session_locker=/usr/X11R6/bin/xscreensaver-command
session_locker_arg='-lock'
console=/dev/tty1
#-----pm debug (adjustable if you want to test stuff)---------
 debug_pm_does_exist () {
  # To test/debug your system's suspend abilities, read the kernel
  # documentation about enabling/using CONFIG_PM_DEBUG
  # note: only one line must be uncommented at any time.
  #
  echo none > /sys/power/pm_test # really suspend (default)
  #echo freezer > /sys/power/pm_test # least invasive test
  #echo devices > /sys/power/pm_test # test device susp/resume
  #echo platform > /sys/power/pm_test # only w/suspend to disk
  #echo processors > /sys/power/pm_test # test CPU susp/resume
  #echo core > /sys/power/pm_test # most invasive test
 }
[ -f $pm_debug_exist ] && debug_pm_does_exist
#---------------------------------------------end pm debug-----

} # end setup

# Do not edit below here unless you know what you're doing.
#--------------------------------------------------------------

usage () {
 unset list
  printf "\n s2: a suspend script by Sasha. Version $version (Orig. Dec 2009)\n"

  [ "$1" = 'error' ] && printf " Error: bad, missing, or extra parameter.\n"
  for i in standby mem disk; do
     [ "$(echo $methods | grep -o $i)" ] && eval $i='1' || unset i
  done;
cat << USAGE
 Usage:

 To suspend immediately, just specify the type of suspend you want, and
 optionally the 'lock' option, which locks your desktop session before
 suspending. If you want the machine to automatically suspend at a later time
 then use the additional options. All options are:

 -x | cancel    to abort any pending suspends.
 -l | lock      locks the desktop session before suspending.
 -m | mem       indicates you want 'suspend to ram'
 -d | disk      indicates you want 'suspend to disk'
 -s | standby   indicates you want 'suspend to standby'
  ? | status    shows any current pending suspend operation.
 inmins=mm      will cause a suspend after mm minutes.
 insecs=ss      causes a suspend after ss seconds.
 inhrs=hh       will suspend after hh hours.
 time=HHMM      allows a HHMM format of time-of-day to suspend at.
                NOTE: due to the nature of the "date" system command
                some adjustment is done depending on the time entered.
                If you get unsatisfactory results with the time=HHMM option
                give me an example and description of what happened and I will
                look into it.

 When a suspend instance has been created, you will see on the screen, an
 informational line, showing the actual command used to perform the operation,
 such as:

 Running s2 process: (18203) /bin/sh /usr/bin/s2 fork mem 7200 unlocked 7

 Above, the (18203) is the process ID of the running instance. The remainder of
 the line can be copied as-is, and used to silently start an s2 instance from
 cron or other means.

 As of this writing (version 1.1x), suspend to disk has not been tested by me
 at all. It should work fine - it's reputed to be less troublesome than suspend
 to ram. Standby and suspend to ram both work on my system.
 If you find a bug, i.e. something really dumb/obvious that I missed, point it
 out and I'll fix it.

 If you're so inclined, you can run this from a crontab or an icon/kicker
 button with a command something like: kdesu /path/to/script <args>

 Below shows what suspend methods are currently available on your machine
 and the rest of the possible arguments that s2 accepts:

USAGE

 printf " Usage: $(basename $0) $( [ "$standby" ] && list="standby";
                                       [ "$mem" ] && list="$list mem";
                                      [ "$disk" ] && list="$list disk";
 echo "$list" | sed 's/^[ ]//;s/ /|/g' ) [lock] [inmins=mm | insecs=ss | inhours=hh | time=HHMM]\n"
 printf " Usage: $(basename $0) [cancel] [status] [help]\n\n"
}

logging () {
[ "$want_to_log_the_process" = 'n' ] && return
case $1 in
  start) $tail -f $kernel_log > $suspend2_log &
	 echo $! > $log_pidfile ;;
  stop) if [ -f $log_pidfile ]; then
	deadlog=$(cat $log_pidfile)
	kill $deadlog > /dev/null 2>&1 &
	wait
	fi
	;;
esac;
}

get_jobs () {
 unset fpid running_jobs
 if [ -f $fork_pidfile ]; then
   fpid=$(cat $fork_pidfile); running_jobs=$(ps -p $fpid -o command= )
 fi;
}

message () {
 [ "$1" = 'S' ] && printf "\n$(date) ($(basename $0): Going into $action-sleep now.)\n" > $console
 [ "$1" = 'R' ] && printf "\n$(date) ($(basename $0): Waking up now.)\n" > $console
}

get_current_vt () {
 # Figure out what v/tty we're on when script is called
 # so we can return there upon resume:
 DISPL="$(who am i | grep -oE ':[0-9]+\.' | tr -d .)"
 curr_tty="$(tty | awk '/tty/{gsub ("[a-z/]","");print}')"
 if [ ! "$curr_tty" ]; then
   curr_tty="$(ps -ef | grep /usr/bin/X | \
                        grep -v 'xinit\|grep' | \
                        grep " $DISPL" | \
                        awk '/tty/{print $6}' | tr -d [a-z])"
 fi
 # if we still haven't got a $curr_tty then (until I get a better idea) set it to tty7
 [ ! "$curr_tty" ] && curr_tty='7'
 original_vt=$curr_tty
 #echo "$original_vt" #DEBUG
 #exit #DEBUG ONLY
}

get_current_vt_better () {
 # Thanks to LQ member 'GazL' for this nice efficient replacement for the
 # above function, which gets the current v/tty to return to upon resume:
read user tty month day time display << EOD
$(LANG=C who -m)
EOD

if [ "$display" = "" ] ; then
   where="$tty"
else
   where="${display%.*}"; where="${where#*:}"
   read X_pid < "/tmp/.X${where}-lock"
   where=$(ps h -p "${X_pid}" -o tty)
fi
[ ! "$where" ] && original_vt='7' || original_vt=${where//[a-z]}
 #echo "$original_vt" #DEBUG
 #exit #DEBUG ONLY
}

do_standby () {
 sleep $seconds; sync; sleep 1
 # 'standby' doesn't need any module-unplugging or NIC shutdown.
 chvt 1; message S
 [ "$lock" = 'lock' ] && $session_locker $session_locker_arg >/dev/null 2>&1
 logging start
 echo standby > /sys/power/state

# resuming now:

 $hwclock --hctosys # adjust OS clock
 message R
 logging stop
 chvt $original_vt
 rm -f $log_pidfile $fork_pidfile
} # end of 'do_standby'


do_suspend () {
 sleep $seconds; sync; sleep 1
 chvt 1; message S; sleep 2 # (legacy?) change to non-X console to prevent corrupt video
 [ "$lock" = 'lock' ] && $session_locker $session_locker_arg >/dev/null 2>&1
 logging start
 # take down NIC(s) (optional - we restart whole network later anyway)
 interface_list="$(echo $interfaces | sed 's/[ ]/\n/g')"
 for NICs in $(printf "$NIC"); do
   $ifconfig $NICs down
 done;
 # unplug modules known to give problems:
 for mod in $unplug_list; do
   [ "$(lsmod | grep $mod)" ] && $modprobe -r $mod 2>/dev/null
 done;
 echo $action > /sys/power/state

 # Resuming now;

 $hwclock --hctosys # adjust OS clock
 message R
 # reinsert removed modules
 [ ! "$insert_list" ] && insert_list="$unplug_list"
 for mod in $insert_list; do
   $modprobe $mod 2>/dev/null
 done;
 sleep 1 # let things settle
 # Kill any running dhcpcd & restart networking as during a cold boot:
 [ "$(ps ax | grep dhcpcd)" ] && killall -q dhcpcd
 $net_init_script $net_init_script_arg > $console
 logging stop
 chvt $original_vt
 rm -f $log_pidfile $fork_pidfile
} # end of 'do_suspend'

# end of function declarations & setup stuff;
# script entry point:

# check UID
[ $(id -u) != 0 ] && echo "s2 error: you must be UID=0 to run $0" && exit 1

# setup our variables and all that stuff:
setup

if [ "$1" = 'fork' ]; then
 # we're the forked, already-configured instance:
 seconds=$3; lock=$4; original_vt=$5
 case $2 in
   standby)
	do_standby >/dev/null 2>&1 & disown
	echo $! > $fork_pidfile
	exit 0
	;;
   *)
	action=$2
	do_suspend >/dev/null 2>&1 & disown
	echo $! > $fork_pidfile
	exit 0
	;;
 esac;

else # We haven't been set up yet, so deal with cmdline args:

 unset action units; seconds=$((0)); lock='unlocked'
 methods=$(cat /sys/power/state)

if [ $# -eq 0 ]; then
   usage error
   exit 1
fi

 for param in $*; do
  case $param in
    lock|-l) lock='lock' ;;
 standby|-s) [ ! "$action" -a "$(echo $methods | grep -o standby)" ] && action='standby' || usage error ;;
     mem|-m) [ ! "$action" -a "$(echo $methods | grep -o mem)" ] && action='mem' || usage error ;;
    disk|-d) [ ! "$action" -a "$(echo $methods | grep -o disk)" ] && action='disk' || usage error ;;
  status|'?') get_jobs
	   printf "\nRunning s2 process: $( [ "$running_jobs" ] && printf "($fpid) $running_jobs" || printf "None." )\n"
	   exit 0 ;;
  cancel|-x)
	logging stop; get_jobs
	if [ "$fpid" ]; then
	   bloody_die=$(ps ax | grep $(pgrep -P $fpid) | gawk '{/^.[:digit:]+[ ]$/;print $1}')
	   kill $fpid 2>/dev/null &
	   wait
           kill $bloody_die 2>/dev/null &
	   wait
           rm -f $fork_pidfile $log_pidfile
	fi;
	printf "\nAny pending s2 has been canceled.\n"
	exit 0
	;;
 inmins=*) if [ ! "$units" ]; then
               units='mins'; seconds=$(($(echo $param | gawk -F= '{/^inmins=[:digit:]+$/;print $2}')*60))
           else
               usage error; exit 1; fi; ;;
 insecs=*) if [ ! "$units" ]; then
               units='secs'; seconds=$(($(echo $param | gawk -F= '{/^insecs=[:digit:]+$/;print $2}')))
           else
               usage error; exit 1; fi; ;;
inhours=*) if [ ! "$units" ]; then
               units='hrs';  seconds=$(($(echo $param | gawk -F= '{/^inhours=[:digit:]+$/;print $2}')*3600))
           else
               usage error; exit 1; fi; ;;
   time=*)
	   if [ ! "$units" ]; then
                units='time'
	        timegiven="$(echo $param | gawk -F= '{/^time=[:digit:][:digit:][:digit:][:digit:]$/;print $2}')"
	        [ ! "$timegiven" ] && usage error && exit 1
	        unixtimethen=$(($(date -d "$timegiven" +%s)))
	        [ $unixtimethen -lt $(($(date +%s))) ] && unixtimethen=$((unixtimethen+86400))
	        seconds=$((unixtimethen-$(date +%s)))
           else
                usage error; exit 1; fi; ;;

  help|-h|-h*|h*) usage; exit 0 ;;
        *) usage error ; exit 1 ;;
  esac;
 done;


 get_jobs

 if [ "$running_jobs" ]; then
   printf "\nThere's already a suspend2 instance running. Cancel that one first.\n" && exit 1
 fi;

 if [ "$action" -a "$seconds" ]; then

   # If you have trouble with this function 'get_current_vt_better', please let me know,
   # and meanwhile, try the original function 'get_current_vt' instead;
   # Uncomment only one of the 2 lines below:
  # get_current_vt
   get_current_vt_better

   $0 fork $action $seconds $lock $original_vt
   $0 status
   exit 0
 else
   usage error; exit 1
 fi;
fi;

# EOF

Last edited by GrapefruiTgirl; 10-20-2010 at 06:58 AM. Reason: see changelog section, latest release version = 1.15 on Oct-20-2010
 
Old 06-21-2009, 08:44 AM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
Haven't seen you around here in awhile GrapefruiTgirl.

Neat script. You might want to edit your post to get rid of your e-mail address in the header (I've already sold it to 10 spammers )..
 
Old 06-21-2009, 09:23 AM   #3
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Original Poster
Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Thanks Weibulguy,

I thought I had botched the email address, but now it IS botched. I want a cut of the profits from the sales
Chances are, by the time anyone emails about this, that email account will be defunct anyways :/ lol, those crazy free accounts, you know how that goes. But I don't like putting my ISP email account on stuff, for the very reason you mention.

I was away from online for a period, doing some work on my hardware during which I had the machines all taken apart, and before that I was devoting a lot of time to my pets & animals here (lol, do you really want to know?)

I go through phases where I stay off the computer for a while, then get back into it like it's the last day to get everything done that I want to do.

Thanks for looking,

Sasha
 
Old 06-21-2009, 10:56 AM   #4
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
Quote:
Originally Posted by GrapefruiTgirl View Post
I want a cut of the profits from the sales
Here's 20% of the profits ... .

Quote:
Originally Posted by GrapefruiTgirl View Post
(lol, do you really want to know?)
Sure.
 
Old 06-21-2009, 11:21 AM   #5
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Original Poster
Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Well, my main pet is a boa constrictor imperator. I breed rats both as pets, and to feed to the snake. I usually have between 6 and a few dozen rats.

We also have rabbits, which my roommate wanted (she wanted one, but the one we got was pregnant, and we now have about 8 of them), but the rabbits have not been the cuddly friendly pets she had envisioned, so much of the time devoted to the rabbits involves rabbit-proofing the house, particularly safeguarding anything involving wires (to keep the wires in one piece and the wired hardware working).

Sasha
 
Old 06-21-2009, 12:38 PM   #6
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
Quote:
Originally Posted by GrapefruiTgirl View Post
Well, my main pet is a boa constrictor imperator.
Ick. The e-mail address makes sense though.

Quote:
Originally Posted by GrapefruiTgirl View Post
I breed rats...
Double ick.

Quote:
Originally Posted by GrapefruiTgirl View Post
...the rabbits have not been the cuddly friendly pets she had envisioned...
They may be good in a stew or on a skewer.
 
Old 06-21-2009, 12:44 PM   #7
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Original Poster
Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Quote:
Originally Posted by weibullguy View Post
They (the rabbits) may be good in a stew or on a skewer.
Don't tempt me! Believe me, the thought does come across our minds more often than is healthy for the rabbits, particularly after I spend several hours repairing/soldering/patching all the wiring behind my computer workstation (this discussion has been had elsewhere, in a thread where I was asking how to reset a USB port from over-current caused by rabbits eating the wire.)

NOTE: the workstation is now rabbit-proof.

Sasha
 
Old 10-11-2009, 12:19 PM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Hello Sasha

You must have done a lot of research to create that script; thanks for sharing it.

I tried running suspend2 with arguments disk insecs=1. It successfully stopped Slackware 13.0 and there was a lot of disk activity before the power went off. So far, so good, but when I booted by power-up Slackware showed no signs of looking for a resume image in the swap space.

It would be too much to ask you to to help me figure out what has to be done to get suspend-to-disk working (and resume would be handy!) but it would be very helpful if you could post some of the most useful links you found on this topic.

BTW I have a friend who keeps wild rabbits as house pets. It all started when she found one with Myxomatosis and nursed it back to health then realised it was too domesticated and scarred by the disease (and too cute, methinks!) to release back into the wild. Husband was not enamoured. They've separated now (friend and husband, that is) but history does not relate how much rabbit-about-the-house was the cause.

Best

Charles
 
Old 10-12-2009, 01:09 PM   #9
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Original Poster
Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Hi catkin,

Apparently s2disk is supposed to be easier and more reliable than s2ram; and as far as the script goes, AFAIK there should be no changes required to implement it; the only prerequesite to s2disk working would be to have a (dedicated??) swap space for the machine to suspend TO, as well as in your LILO or GRUB configuration, you specify that swap space. The only reason(s) I didn't actually test s2disk myself, is (A) I don't use it, and (B) it reportedly works nearly perfect on the vast majority of machines, right 'out of the box' with no hacking or fiddling. If you didn't do the underlined part, I suggest doing that and re-testing. It sounds like your machine did indeed suspend to your swap space, but it just didn't know where to resume from.

I would be happy to work with you in seeing that s2disk works, I don't mind, and it would be good to ultimately know that the script doesn't need anything else (or if it does!) to make s2disk work. I can set up a swap space of my own and practice with you if need be; just let me know.

I admit that I have been online less for the past week than I usually am; I am in the process of migrating my boa constrictor into a larger house, and this is keeping me busy. Part of the process of moving her involves modifying the house she currently lives in, so I have had to sort of follow a procedure, while working on the project, as well as re-engineering the heating system.. Feel free to email me to get my attention and/or direct me to this thread if I can help in any way.

As for links, I am afraid I don't really have a particular assortment of links to suspend sites; I started by Googling of course, and one that I do recall being somewhat helpful was SuSE's s2ram page, which IIRC contains some details about various aspects of suspending, as well as links to their s2ram tool (a binary) which can accept various arguments (hacks) to make various machines suspend to RAM successfully. But for the most part, all the sites I found pretty much said the same things, and ultimately, the kernel Documentation was most helpful (see next para):

Much of the useful information I used while making the script, besides just testing on my own machine, was obtained from the kernel source /Documentation/power text files. Everything useful that I needed to read/know, is in there and if you either don't have the documentation, I'd be happy to copy it and either post it or email it.

---

As for the rabbits, that's a most interesting story! I have read that it is not wise, but not really that bad, to keep wild rabbits as pets, as they are definitely much alike the domestic ones, and ALL of them are skittish and easily spooked; the main difference is that the domesticated ones have an extra chromosome, which makes them unable to mate with wild rabbits; they're incompatible-- which is hard to believe if one has experienced rabbits mating, because they do it often, and every 30 days, there are more rabbits, and more rabbits, and more rabbits, if one doesn't have them neutered.

Not sure if I mentioned above, but my roommate wanted the rabbit, not me :| but as is our situation, if one doesn't have a LOT of time to dedicate to them, with house training, litter training, etc., then they are a hellish pet. They're cute & bouncy when young, but when they become adults, they are more distructive than most pets I have experienced. We started with one rabbit (pregnant when we got her, but we didn't know) and eventually, we have now seen better than 30 rabbits from that one!!! We let them all go, and now have only two; one of which we kept because she's a really fluffy angora, and the other because he seemed to have a defect at birth, so we kept him as we felt he may not stand as good a chance of being OK outside. But, the rabbits have eaten all the drywall && wallpaper off our walls up to about 14 inches from the floor, and the door-frames are gone too; exposed wiring has all been repaired/replaced many times, and they've torn up the flooring in the hallway and bathroom where they now live. Booo.

Anyhow let me know if I can help you with suspend to disk, and also, if setting up your bootloader with the swap space helps the situation.

Best regards,
Sasha
 
Old 10-12-2009, 01:19 PM   #10
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Original Poster
Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
P.S. -- To anyone concerend:

The "don't lock" option works fine, however, if enough time passes while the machine is suspended, and you have your screensaver configured to lock the machine after a certain amount if time, it will awake and be locked anyway. This is not a bug; it's just the way things work.

To avoid this, do not set your screensaver to automatically lock. Now, if you do not specify "lock" with the script, it will awake unlocked, and "lock" will also still work.

Sasha
 
Old 10-12-2009, 02:16 PM   #11
manwithaplan
Member
 
Registered: Nov 2008
Location: ~/
Distribution: Arch || Sidux
Posts: 393

Rep: Reputation: 45
I was looking for something like this .. thanks ... I just need to adjust some of it to work on a Gentoo box.
 
Old 10-12-2009, 02:23 PM   #12
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Hello Sasha

Thanks for taking time out from boa works.

That was it! I added a new GRUB menu.lst stanza with resume=/dev/sda7 on the kernel line and tried again. Blow me over wiv a fevver -- it worked! Not perfectly but in essence suggesting some fine tuning is required. /dev/sda7 is just plain ordinary swap, not in any way dedicated to suspend/resume but the system has enough memory that it does not swap. I guess a system that does swap would need enough free space in swap when suspending to accommodate all the memory.

Specific differences between the pre-suspend state and the resume state were:
  • In root's mrxvt terminal (the one that I issued the suspend2.sh disk insecs=1 command from), there were a couple of messages:
    Running suspend2 process: (4311) /bin/sh /home/c/d/bin/try/suspend2.sh fork disk 1 unlocked
    root:~# /usr/bin/tail: cannot open `/var/log/kernel.log' for reading: No such file or directory
    /usr/bin/tail: no files remaining
    FATAL: Error inserting ehci_hcd (/lib/modules/2.6.29.6-smp/kernel/drivers/usb/host/ehci-hcd.ko): Invalid argument
  • Fans running at full speed. Prior to suspend, lmsensors' fancontrol script was running and controlling the fans according to speed.
Being cautious, I had nothing running except root's mrxvt terminal when running suspend2.sh so a lot more testing is required but this is a great start (way better than attempting suspend on ubuntu 8.04) and it makes sense to fix the issues in this minimal situation before attempting suspend with the usual plethora of apps running.

Do you have any suggestions? I have no idea why tail was trying to open /var/log/kernel.log but the message is correct; there is no /var/log/kernel.log.

FWIW, I'm running Slackware 13.0 32-bit on a Gigabyte GA-MA770-DS3 Rev 1.0 motherboard with a GeForce 7300 SE/7200 GS (G72) (sometimes reported as a GeForce 7200 GS GV-NX72G512E2 Rev 2.3) GPU.

----

Back to the serious business of rabbits-as-pets, it sounds like you are very liberal-minded with yours, allowing them free run of the place. My friend kept hers in a cage all day and let it out in the evening when she could keep an eye on it. It was quite cheeky, playing hide-and-seek and sneaking up behind people sitting on sofas then playing with/in their hair. It had a tendency to dig around the place, pulling up edges of carpets etc. but nothing like the destructive instincts of yours. It was a little nervous, despite a lot of handling and socialising, easily startled by sudden movements but seemed very happy with its lot, including being caged for the day; oft-times it would stay in its cage after the door was opened, taking its own time before hopping out and playing around the house.

Best

Charles
 
Old 10-12-2009, 10:35 PM   #13
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Original Poster
Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Quote:
Originally Posted by catkin View Post
Hello Sasha

Thanks for taking time out from boa works.
No worries -- I just fed her earlier tonight, and she's starting a shed cycle so I have a few days off now for the most part.

Quote:

That was it! I added a new GRUB menu.lst stanza with resume=/dev/sda7 on the kernel line and tried again. Blow me over wiv a fevver -- it worked! Not perfectly but in essence suggesting some fine tuning is required. /dev/sda7 is just plain ordinary swap, not in any way dedicated to suspend/resume but the system has enough memory that it does not swap. I guess a system that does swap would need enough free space in swap when suspending to accommodate all the memory.
Great!! Glad that worked out for you! You are correct as far as I know -- if a system did use its swap space, then chances are good that if it suspended to that same space, something would definitely go awry during susp/resume, so best to use IMO a dedicated swap space of adequate size to hold all of the RAM of the machine-- so if you have 4 Gib of RAM installed, I would use a 4096Kib swap space to suspend to.

Here's some input about the console messages:
Quote:
[*]In root's mrxvt terminal (the one that I issued the suspend2.sh disk insecs=1 command from), there were a couple of messages:
Running suspend2 process: (4311) /bin/sh /home/c/d/bin/try/suspend2.sh fork disk 1 unlocked
The above is normal; just an INFO type message about the running suspend process. You could comment it out if you don't like it.
Quote:
root:~# /usr/bin/tail: cannot open `/var/log/kernel.log' for reading: No such file or directory
/usr/bin/tail: no files remaining
The above is because your kernel log file has a different name than mine, because I tend to rename/change all my log files to <something>.log rather than just <something> which was particularly relevant on my Slack11 system where I mostly developed the script. The log file names are defined in the script-- just change the name of yours to the default (probably just "kernel").

Quote:
FATAL: Error inserting ehci_hcd (/lib/modules/2.6.29.6-smp/kernel/drivers/usb/host/ehci-hcd.ko): Invalid argument
The above is because you don't have that kernel module compiled as a module. Modules that gave me trouble on my machine are the ones listed by default in the script in the variables $unplug_list and $insert_list. This can vary by machine, but USB module(s) are commonly culprits in failed resumes/suspends. Initially, during my debugging using the debug methods described in the script and in pm_debug.txt from the kernel Docs, I was unplugging BOTH usb modules because USB was awaking my machine as soon as it went to sleep; but later I determined that only ONE of the 3 or 4 possible USB kernel modules was giving me the trouble, so when I rebuilt my kernel, I statically compiled that module that's giving you the error. It's likely that your machine too has that module built statically. Therefore, since the module is still listed in the $unplug_list, the script is trying to unplug/insert a module that does not exist. Simply tailor the $unplug_list to your needs. NOTE: If you try s2ram and find the machine awakes immediately, you may need to make one or more of your USB modules as modules, and unplug/insert them when suspending to ram.
Quote:
[*]Fans running at full speed. Prior to suspend, lmsensors' fancontrol script was running and controlling the fans according to speed.[/LIST]Being cautious, I had nothing running except root's mrxvt terminal when running suspend2.sh so a lot more testing is required but this is a great start (way better than attempting suspend on ubuntu 8.04) and it makes sense to fix the issues in this minimal situation before attempting suspend with the usual plethora of apps running.
Hmm.. The above, about the sensors/fans thing, I don't have a suggestion at this time, except to perhaps kill/re-execute the fancontrol program after resume.
I am going to venture a guess that since the fancontrol thing likely uses BIOS calls/info to read/write to the PWM system that controls fan speeds, then **possibly** a BIOS call would be required to either save the state of the fans, and/or restore them later. I don't think this can be done from bash, which is perhaps one of the reasons SuSE has created the s2ram binary in C, although to my recollection, there are no fan-control hacks in their s2ram tool; they have mainly video corruption prevention hacks.
EDIT: I just realized after some time, that you said "script" when you referred to the fancontrol tool you use; therefore I think I'm wrong about the BIOS stuff, and perhaps instead your script uses the /sys interface and/or /proc file system to deal with the PWM control for the fans. If this is the case, do let me know; in fact, a link to the fan-control script would be great, so I can have a look at it.[/EDIT]

As for testing with a plethora of apps running, I can attest to having no troubles whatsoever when I suspend to RAM with a load of junk running, so I **presume** suspending to disk should be no different. Do let me know.

And, if you find that killing/re-starting your fancontrol program before/after suspend+resume fixes the problem, then perhaps I should add a stub (supporting code) for where users can add such scripts to the suspend process, if other machines have the same problem with fancontrol or other things? Again, let me know.
Quote:
FWIW, I'm running Slackware 13.0 32-bit on a Gigabyte GA-MA770-DS3 Rev 1.0 motherboard with a GeForce 7300 SE/7200 GS (G72) (sometimes reported as a GeForce 7200 GS GV-NX72G512E2 Rev 2.3) GPU.
Cool, I'm running two of the same card -- one is a 7300GS, and the other is a "7200GS/7300SE" I suspect because it failed some or another QA test during manufacture-- but works great for me. Both my cards appear physically identical, though I purchased them almost a year apart.
----
Final note: about USb modules: if you have any mounted USb file systems or devices like USB sticks or whatever, then obviously they will need to be unmounted/remounted before/after suspending/resuming.

I will add functionality for this in the next revision of the script, but meanwhile, for anyone having USB things mounted and who either need them unmounted/remounted and/or need to remove their usb modules in case of problems from them, please do this manually for the moment.

Of course, any suggestions, bugs, proposed code snippets for inclusion, are welcome.

-------------
Quote:
Back to the serious business of rabbits-as-pets, it sounds like you are very liberal-minded with yours, allowing them free run of the place. My friend kept hers in a cage all day and let it out in the evening when she could keep an eye on it. It was quite cheeky, playing hide-and-seek and sneaking up behind people sitting on sofas then playing with/in their hair. It had a tendency to dig around the place, pulling up edges of carpets etc. but nothing like the destructive instincts of yours. It was a little nervous, despite a lot of handling and socialising, easily startled by sudden movements but seemed very happy with its lot, including being caged for the day; oft-times it would stay in its cage after the door was opened, taking its own time before hopping out and playing around the house.
Yes, the bunnies require a lot of interaction and constant attention to be "good" pets, and to become socialized well.. Ours *did* have the run of the house, but now they have just the hallway and bathroom, which is plenty of room for them, though they've also eaten off the bottom of the cabinet doors in the bathroom. They hate being picked up, and even trying to pick them up and handle them regularly from birth did not help; they still fight like mad when picked up, and act terrified; but they aren't scared of us or very skittish with us, and they love to get under-foot as though trying to trip us up and kill us :/ lol. Sometimes the male one has kisses for us, but not usually. The female is really anti-social; this is normal: the males are usually more friendly. Our male one likes scratches on the ears, nose-rubs, etc., but the female just dislikes physical contact.
Sounds like your friend has the right idea, and the time and devotion needed for bunnies. It's the right idea to let them come and go from their cage on their own. They really resent being manually 'urged' into their cage, but are quite happy to go in on their own. And they resent even more when people reach into their cage for any reason, while they are in there-- they see it as a BIG invasion of privacy.

I'll stick to my boa, and my ratties

Cheers, Charles,

Sasha

Last edited by GrapefruiTgirl; 10-12-2009 at 11:52 PM.
 
Old 10-12-2009, 11:38 PM   #14
rkski
Member
 
Registered: Jan 2009
Location: Canada
Distribution: CentOS 6.3, Fedora 17
Posts: 247

Rep: Reputation: 51
Hi
When I first installed CentOS to my laptop I was disappointed that it wouldn't come back to life after suspending (from KDE) -- only black screen.

I did a little searching and added the following alias which works great on my Lenovo T61:

Code:
alias standby='echo mem > /sys/power/state'
I have no need really for hibernate, but I definitely need suspend-to-ram to conserve the battery when needed.
 
Old 10-12-2009, 11:56 PM   #15
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Original Poster
Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Quote:
Originally Posted by rkski View Post
Hi
When I first installed CentOS to my laptop I was disappointed that it wouldn't come back to life after suspending (from KDE) -- only black screen.

I did a little searching and added the following alias which works great on my Lenovo T61:

Code:
alias standby='echo mem > /sys/power/state'
I have no need really for hibernate, but I definitely need suspend-to-ram to conserve the battery when needed.
Hi rkski,

The alias you're using is the same method that my script uses, for suspend2ram.

However that said, there is also on some systems a "standby" state, which I think is somewhere between s2ram and s2disk, and which apparently doesn't work on your system if I'm reading between the lines correctly from your post.
On my desktop machine, if I put it into "standby" it appears to shut off, but it won't resume by keyboard; I have to actually press the power button to make it return to life.
I'm not exactly sure what it's really doing in the standby state
When I use "mem" as I usually do and as you do, I can use my keyboard (spacebar) to resume the machine.

Thanks for the info

Regards,
Sasha
 
  


Reply

Tags
bash, hibernate, script, standby, suspend



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
3 Questions by a Mandriva Noob: Suspend to RAM/Disk, Compiz-Fusion, Screensavers OpEn_SoUrCe_RoCkS Mandriva 8 04-03-2008 05:26 PM
Suspend to disk/ram problem tea of evil Linux - Laptop and Netbook 2 03-05-2008 04:49 AM
Plz explain Suspend to Disk and Suspend to Ram pkhera_2001 Linux - Newbie 2 02-18-2008 07:23 AM
difference between "suspend to standby" and "suspend to ram" nappaji Linux - Hardware 1 08-23-2006 08:17 PM
Suspend To Disk And Wake On Lan, Can you somehow combine Suspend2 and Soft off? Lake-end Linux - Hardware 1 04-19-2006 04:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 01:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration