Suspend

From Attie's Wiki
(Difference between revisions)
Jump to: navigation, search
m
m
 
Line 16: Line 16:
 
trap 'rm -f $TMP_FILE' 0 1 15
 
trap 'rm -f $TMP_FILE' 0 1 15
  
# switch to virtual terminal 1 to avoid graphics
+
# remember the current virtual terminal
 +
OVC=`fgconsole`
 +
 
 +
# switch to another virtual terminal to avoid graphics
 
# corruption in X
 
# corruption in X
chvt 1
+
if [ "$OVC" == "1" ]; then
 +
  chvt 2
 +
else
 +
  chvt 1
 +
fi
  
 
# write all unwritten data (just in case)
 
# write all unwritten data (just in case)
Line 35: Line 42:
  
 
# switch back to virtual terminal 7 (running X)
 
# switch back to virtual terminal 7 (running X)
chvt 7
+
chvt $OVC
  
 
# remove temporary file
 
# remove temporary file
 
rm -f $TMP_FILE
 
rm -f $TMP_FILE
 
</source>
 
</source>

Latest revision as of 16:51, 25 January 2011

[edit] 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