I still haven't completely solved the problem of my PC sometimes failing to resume from sleep, and when it happens it acts as if it had crashed and then just starts up normally. This means I wan't to check the disks to make sure the file system is all OK. This can be done on Slackware by creating a file /etc/forcefsck and then rebooting. The same can be done with other distributions, but the file location may be /forcefsck.
Doing this means creating the file and then rebooting again though. The system only fails to resume about 5% of the time, but that's still enough to make it annoying to have to do the fsck. So I decided to create a sleep script which will create the forcefsck file when sleeping, and then remove it again after the system has resumed OK. This means that if the system crashes then it will run the normal startup scripts which will see the forcefsck file and check the disks.
Using elogind on Slackware the script lives at /lib64/elogind/system-sleep/fsck-on-crash.sh and looks like this.

#!/bin/bash

WHEN="$1"
WHAT="$2"

if [[ "xpre" = "x$WHEN" ]]; then
    /usr/bin/logger -t "$WHAT" -s "$WHEN: Creating forcefsck"
    touch /etc/forcefsck
elif [[ "xpost" = "x$WHEN" ]]; then
    # sleep a bit to make sure the system really does wake ok
    # also sleep for long enough that this doesn't get run when waking to hibernate
    ( sleep 60 && /usr/bin/logger -t "$WHAT" -s "$WHEN: Removing forcefsck (wake was successful)" && rm -f /etc/forcefsck ) &
fi

exit 0

It will need the executable bit setting on it with chmod +x.

The script location is distro specific. For systemd it would be something like /lib/systemd/system-sleep but could also be in /lib64 or /usr/lib

Previous Post Next Post