Suspend

From Attie's Wiki
Revision as of 15:51, 25 January 2011 by Attie (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

How to suspend under linux

#!/bin/sh
 
# ensure that we are root
if [ `whoami` != "root" ]; then
  sudo $0
  exit 0
fi
 
# discover video card's ID
ID=`lspci | 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
 
# remember the current virtual terminal
OVC=`fgconsole`
 
# switch to another virtual terminal to avoid graphics
# corruption in X
if [ "$OVC" == "1" ]; then
  chvt 2
else
  chvt 1
fi
 
# 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 7 (running X)
chvt $OVC
 
# remove temporary file
rm -f $TMP_FILE
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox