#! /bin/sh # Suspend-to-RAM (ACPI S3 state) # see /usr/src/linux/Documentation/power/video.txt and # http://www.linux.com/article.pl?sid=06/05/24/1716222 # http://www.linux.com/article.pl?sid=07/02/02/2117209 su - phd -c "xscreensaver-command -exit" # discover video card's ID ID=`lspci | grep VGA | awk '{ print $1 }' | sed -e 's@0000:@@' -e 's@:@/@'` # securely create a temporary file STATE_DIR=`mktemp -d /var/tmp/acpi_state.XXXXXX` trap 'rm -rf $STATE_DIR' 0 1 15 # switch to virtual terminal 1 to avoid graphics corruption in X curcons=`fgconsole` chvt 2 clear # synchronize system clock with hardware hwclock --directisa --localtime --systohc # dump current data from the video card to the # temporary file cat /dev/vcsa > $STATE_DIR/vcsa cat /proc/bus/pci/$ID > $STATE_DIR/video_state # write all unwritten data (just in case) sync # suspend /etc/init.d/laptop-mode stop echo -n mem > /sys/power/state statedir=/root/s3 vbetool post vbetool vbestate restore <$statedir/vbe # restore video card data from the temporary file # on resume cat $STATE_DIR/video_state > /proc/bus/pci/$ID cat $STATE_DIR/vcsa >/dev/vcsa # synchronize hardware clock with system hwclock --directisa --localtime --hctosys # restore states of the other subsystems /etc/init.d/laptop-mode start cyr # cyryllic fonts on the console # switch back to the original virtual terminal chvt $[curcons%6+1] chvt $curcons cd "$HOME" su - phd -c "xscreensaver &" clear # remove temporary file exec rm -rf $STATE_DIR