6 # This script invalidates any stale swsusp and Software Suspend 2 images. It
7 # searches all swap partitions on your machine, as well as Suspend2's
8 # filewriter files (by way of the hibernate script telling it where to find
11 # It should be called on boot, after mounting filesystems, but before enabling
12 # swap or clearing out /var/run. Copy this into /etc/init.d/ (or the appropriate
13 # place on your system), then add a symlink at the appropriate point on boot.
14 # On a Debian system, you would do this:
15 # update-rc.d hibernate-cleanup.sh start 31 S .
17 # On other SysV-based systems, you would do something like:
18 # ln -s ../init.d/hibernate-cleanup.sh /etc/rcS.d/S31hibernate-cleanup.sh
20 HIBERNATE_FILEWRITER_TRAIL
="/var/run/suspend2_filewriter_image_exists"
26 swapoff
$where 2>/dev
/null
&& wason
=yes
27 mkswap
$where > /dev
/null || stat_append
" (failed: $?)"
28 [ -n "$wason" ] && swapon
$where
32 local where what
type rest p c
33 while read where what
type rest
; do
34 test "$type" = "swap" ||
continue
35 case "$(dd if=$where bs=1 count=6 skip=4086 2>/dev/null)" in
36 S1SUSP|S2SUSP|ULSUSP|pmdisk|
[zZ
]*)
44 check_filewriter_sig
() {
46 [ -f "$HIBERNATE_FILEWRITER_TRAIL" ] ||
return 0
47 read target
< $HIBERNATE_FILEWRITER_TRAIL
48 [ -f "$target" ] ||
return
49 case "`dd \"if=$target\" bs=8 count=1 2>/dev/null`" in
51 /bin
/echo -ne "Suspend2\n\0\0" |
dd "of=$target" bs
=11 count
=1 conv
=notrunc
2>/dev
/null
52 stat_append
-n "$target, "
53 rm -f $HIBERNATE_FILEWRITER_TRAIL
59 stat_busy
"Invalidating stale software suspend images... "
67 echo "Usage: $0 {start|stop}"