terça-feira, 15 de julho de 2014

Suspend/Resume Problem on Linux - Dell Inspiron 15R SE

It seems that there is a bug on Linux Mint 16 (more precisely on Cinnamon) * ( and other distro's) that prevents resume-from-suspend/hibernate from working correctly, suspend and hibernate works fine, but when you power it on again, the system freezes, stop working and no signal of response when using keyboard and/or mouse.

On some tests, i switched to a text-only terminal (ctrl+alt+f1) and did suspend the computer from there:

        $ sudo pm-suspend

After few seconds, turned on the computer.

Surprisingly it was working fine,  i switched back to Cinnamon (ctrl+alt+f8) and it was indeed working fine. So, i searched internet how sleep/hibernation/resume works, and found out that if you write a script on  /etc/pm/sleep.d, that script would be ran as it's meant to be. 
Let me explain a basic script, first, remember that script will be called with a parameter that will be hibernate,sleep,thaw or resume, depending on user's action.

A script there must be something like:

  #!/bin/sh

  case $1 in
    suspend)
    # do something before suspending
    ;;
    suspend_hybrid)
    # do something before suspending (hybrid)
    ;;
    hibernate)
    # do something before hibernate
    ;;
    thaw)
    # do something after thaw (resume from hibernate)
    ;;
    resume)
    # do something after resuming (resume from suspend)
    ;;
  esac

So, if as we know, we can join suspend, suspend_hybrid and hibernate, as our problem occurs on each of those three cases, as someting like

  case $1 in
    suspend|suspend_hybrid|hibernate)

And the same with thaw and resume

  case $1 in
    thaw|resume)
Finally, we know that when going to virtual terminal 1 before suspending, and going back to virtual terminal 8 fix up our bug, so let's use the chvt (for help, man chvt) to do that task on each case, so, on suspend/hibernate stuff, chvt 1, on resume/thaw stuff, chvt 8.
  The final script is the following:

#!/bin/sh

case $1 in

  suspend|suspend_hybrid|hibernate)
  /bin/chvt 1
  ;;

  thaw|resume)
  /bin/chvt 8
  ;;

esac

That fix up the bug. Save that file something like /etc/pm/sleep.d/2_fixvirtualterminal and set it as executable (chmod +x /etc/pm/sleep.d/2_fixvirtualterminal).

That's all

And if you wish to download the script, i've put it here: https://docs.google.com/file/d/0BxouXXdo-U-kdlF6b3ZEVDVIQWc/edit

Note: I've tested this successfully on Ubuntu, so this doesn't seems to be a Mint-only issue.

Nenhum comentário:

Postar um comentário