Suspend
From Attie's Wiki
(Difference between revisions)
m (Created page with '== How to suspend under linux == <source lang="bash"> #!/bin/sh # discover video card's ID ID=`lspci | grep VGA | awk '{ print $1 }' | sed -e 's@0000:@@' -e 's@:@/@'` # securel…') |
m |
||
(One intermediate revision by one user not shown) | |||
Line 2: | Line 2: | ||
<source lang="bash"> | <source lang="bash"> | ||
#!/bin/sh | #!/bin/sh | ||
+ | |||
+ | # ensure that we are root | ||
+ | if [ `whoami` != "root" ]; then | ||
+ | sudo $0 | ||
+ | exit 0 | ||
+ | fi | ||
# discover video card's ID | # discover video card's ID | ||
Line 10: | Line 16: | ||
trap 'rm -f $TMP_FILE' 0 1 15 | trap 'rm -f $TMP_FILE' 0 1 15 | ||
− | # switch to virtual terminal | + | # 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 29: | Line 42: | ||
# switch back to virtual terminal 7 (running X) | # switch back to virtual terminal 7 (running X) | ||
− | chvt | + | 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