# [SOLVED] Problems with suspend and hibernate.

## moult

Let's start with suspend. I've got the suspend/sleep/hibernate stuff in the kernel enabled (no, I am not using tuxonice), I've got hibernate-script installed and supposedly setup with naught but the bare minimum. I can suspend via hibernate-ram or via KDE's battery plasmoid -> sleep, and it will turn off the screen and my power light will turn from green to orange. This seems to be expected. However any interaction except for mouse movement (eg: pressing a key) will cause it to wake up again instantaneously. I don't think this is normal behavior - I would've expected it to only come back when the power button is pressed. It seems like a rather half-hearted suspend, more like a turn-off-screen. Any ideas?

For hibernate the problem seems a little bit more severe. Doing hibernate from the KDE battery plasmoid) will cause the screen to turn off as expected but then the power button light will turn orange (instead of green) and start blinking. No amount of fn keys or button pressing will cause it to come back on. It doesn't show any messages, and doesn't turn off but stays in this weird state of nothing (hibernate should turn off right?). I can use the sysrq key + REISUB to reboot though.

Doing `hibernate` from console will cause the screen to blacken to a tty, then s2swup will complain about not having enough space when trying to write the file. It'll then just sit there like a duck until I force shutdown. I assume it's trying to write to my swap partition. My swap partition is not big enough and I don't think I want to risk modifying partitions. I guess I might need to make a swapfile - how would I go about doing this and setting it up with swsup? I don't think resume=/dev/sda2 is sufficient if I use a swapfile. Is it compulsory to use tuxonice?

----------

## mikegpitt

I'm not 100% sure what is going on with your suspends and hibernates, but I can show you how to set up a swapfile and hibernate to it.  It could be that this will solve your problem.

First create the swapfile:

```
dd if=/dev/zero of=/path/to/swapfile bs=1M count=512

mkswap /path/to/swapfile

swapon /path/to/swapfile

```

And add this line to your /etc/fstab

```
/path/to/swapfile               none            swap            sw              0 0
```

Now we need to add the resume and offset parameters to your grub.conf.  This command will give you your resume offset:

```
filefrag -v /path/to/swapfile | grep "First block:"
```

Let's assume for this example that your resume offset is 66050 and the the swapfile is stored on /dev/sda3.  You will need to add this to your kernel parameters in your grub.conf:

```
resume=/dev/sda3 resume_offset=66050
```

----------

## dmpogo

Do not log into KDE, and run hibernate-ram script by hand from console. What do you get ?

----------

## moult

If I run `hibernate` from console before getting into X, swsup completes without giving the "not enough space" error and turns off like it should. However when I turn it back on, it gives an error about unable to load /dev/sda2 (my swap). Doing cat /proc/swaps confirms this as /dev/sda2 is _not_ listed. Rebooting it again loads things as though it's a fresh boot and not recovering from a hibernate. This obviously isn't normal behavior.

I followed your instructions to set up a swap file, but it still gives the not enough space error - the swap file I made I changed it to 1GB - that should be plenty of space right? When it says not enough space, it still says that the amount of space it _does_ detect is 512MB (which is the size of my /dev/sda2, not my swapfile) which suggests that it isn't aware that it is able to write to that swapfile. I have added the line to /etc/fstab and cat /proc/swaps lists it successfully - any ideas?

----------

## mikegpitt

 *Moult wrote:*   

> If I run `hibernate` from console before getting into X, swsup completes without giving the "not enough space" error and turns off like it should. However when I turn it back on, it gives an error about unable to load /dev/sda2 (my swap). Doing cat /proc/swaps confirms this as /dev/sda2 is _not_ listed. Rebooting it again loads things as though it's a fresh boot and not recovering from a hibernate. This obviously isn't normal behavior.
> 
> I followed your instructions to set up a swap file, but it still gives the not enough space error - the swap file I made I changed it to 1GB - that should be plenty of space right? When it says not enough space, it still says that the amount of space it _does_ detect is 512MB (which is the size of my /dev/sda2, not my swapfile) which suggests that it isn't aware that it is able to write to that swapfile. I have added the line to /etc/fstab and cat /proc/swaps lists it successfully - any ideas?

 Can you post your /etc/fstab, your grub.conf, and the output of the filefrag command I listed above?

----------

## dmpogo

I wanted to check suspend to ram in the first place from console, before debugging hibernate

----------

## Hu

The behavior of suspend-to-ram is dependent on your hardware and BIOS.  Some do a good job, but others will produce fairly poor results, as you have seen.  Check your BIOS settings.  Some BIOSes allow you to configure what actions will awaken the system.

A proper hibernate will bring the system to a sufficiently low power state that the kernel is not running and magic sysrq would not work.  Usually, this means turning off power entirely.

Non-TuxOnIce kernels have suspended and hibernated fairly reliably for me.  However, I always use a single swap partition of sufficient size to cover the required image.

----------

## moult

Interestingly enough:

`hibernate-ram` when in X causes the screen to blacken and power light to turn from green to orange. Pressing any button or key will cause it to wake up again and resume the X session.

`hibernate-ram` when out of X will cause the screen to blacken and power light to turn from green to orange. Pressing any button or key will cause the fan to whir as though it's about to wake up, and the power light will go back to green - however the screen will never resume no matter what is pressed (ctrl-alt-f1, etc). The only thing I can do at this stage is sysrq-REISUB to reboot.

As for `hibernate`, both in and out of X produces the same. Except out of X it doesn't complain about not enough space. When booting up again (from both a hibernate in and out of X) it will complain:

```
swapon /dev/sda2 invalid argument
```

... proceeding which it'll continue to boot as normal and not load any image. A side effect of this is that /dev/sda2 is no longer swaponned, so doing cat /proc/swaps after this boot will show only the /home/drive/swap as a swapfile.

Here's the rest of the info.

my /etc/fstab

```
epicbox ~ # cat /etc/fstab

# /etc/fstab: static file system information.                                   

#                                                                               

# noatime turns off atimes for increased performance (atimes normally aren't    

# needed; notail increases performance of ReiserFS (at the expense of storage

# efficiency).  It's safe to drop the noatime options if you want and to

# switch between notail / tail freely.

#

# The root filesystem should have a pass number of either 0 or 1.

# All other filesystems should have a pass number of 0 or greater than 1.

#

# See the manpage fstab(5) for more information.

#

# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>

# NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.

/dev/sda1               /boot           ext2            noauto,noatime  1 2

/dev/sda3               /               ext3            noatime         0 1

/dev/sda2               none            swap            sw              0 0

/home/drive/swap        none            swap            sw              0 0

/dev/cdrom              /mnt/cdrom      auto            noauto,ro,user  0 0

/dev/sdc1               /mnt/usb        auto            noauto,rw,user  0 0

#/dev/fd0               /mnt/floppy     auto            noauto,user             0 0

# glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for

# POSIX shared memory (shm_open, shm_unlink).

# (tmpfs is a dynamically expandable/shrinkable ramdisk, and will

#  use almost no memory if not populated with files)

shm                     /dev/shm        tmpfs           nodev,nosuid,noexec     0 0
```

my grub.conf

```
epicbox ~ # cat /boot/grub/grub.conf 

# This is a sample grub.conf for use with Genkernel, per the Gentoo handbook

# http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&chap=10#doc_chap2

# If you are not using Genkernel and you need help creating this file, you       

# should consult the handbook. Alternatively, consult the grub.conf.sample that  

# is included with the Grub documentation.                                       

default 0

timeout 3

#splashimage=(hd0,0)/boot/grub/splash.xpm.gz

title Gentoo Linux 2.6.31-r5

root (hd0,0)                

kernel /boot/kernel-2.6.31-gentoo-r5 root=/dev/sda3 resume=/dev/sda3 resume_offset=35673435

title Memtest86Plus

root (hd0,0)       

kernel /boot/memtest86plus/memtest.bin

title Gentoo Linux 2.6.31-r3

root (hd0,0)                

kernel /boot/kernel-2.6.31-gentoo-r3 root=/dev/sda3 resume=swap:/dev/sda2

title Gentoo Linux 2.6.31

root (hd0,0)             

kernel /boot/kernel-2.6.31-gentoo root=/dev/sda3 resume=swap:/dev/sda2

title Gentoo Linux 2.6.30-r5

root (hd0,0)                

kernel /boot/kernel-2.6.30-gentoo-r5 root=/dev/sda3

title Gentoo Linux 2.6.30-r4

root (hd0,0)                

kernel /boot/kernel-2.6.30-gentoo-r4 root=/dev/sda3

title Gentoo Linux 2.6.30-r1

root (hd0,0)

kernel /boot/kernel-2.6.30-gentoo-r1 root=/dev/sda3

title Gentoo Linux 2.6.29-r5

root (hd0,0)

kernel /boot/kernel-2.6.29-gentoo-r5 root=/dev/sda3

title Gentoo Linux 2.6.29-r4

root (hd0,0)

kernel /boot/kernel-2.6.29-gentoo-r4 root=/dev/sda3

title Gentoo Linux 2.6.29-r3

root (hd0,0)

kernel /boot/kernel-2.6.29-gentoo-r3 root=/dev/sda3

title Gentoo Linux 2.6.29-r1

root (hd0,0)

kernel /boot/kernel-2.6.29-gentoo-r1 root=/dev/sda3

#title Gentoo Linux 2.6.24-r5

#root (hd0,0)

#kernel /boot/kernel-genkernel-x86-2.6.24-gentoo-r5 root=/dev/ram0 real_root=/dev/sda3

#initrd /boot/initramfs-genkernel-x86-2.6.24-gentoo-r5

# vim:ft=conf:
```

the filefrag command:

```
epicbox ~ # filefrag -v /home/drive/swap | grep "First block:"

First block: 35673435
```

/proc/swaps

```
epicbox ~ # cat /proc/swaps

Filename                                Type            Size    Used    Priority

/dev/sda2                               partition       506036  0       -1

/home/drive/swap                        file            1048568 0       -2
```

I thought that by changing the priority it might decide to use the swapfile instead of the partition. So I swapoff/swaponned to switch the priorities around but it still tries to use /dev/sda2.

----------

## mikegpitt

I had a feeling that you were running two swaps.  Try to take the /dev/sda2 swap out of your /etc/fstab, reboot, and see if you can suspend.  As for the invalid swap format error, do you have hibernate-cleanup in your boot runlevel?

Your hibernate-ram seems quite broken... this could be due to buggy kernel drivers, or more likely a buggy bios, as Hu suggested above.

----------

## moult

Thanks! Removing the /dev/sda2 from fstab fixed it - and yes, I did already have hibernate-cleanup.

Hibernate works awesomely now. The only hitch is that with hibernate-to-ram it will unsuspend even if I press any random key. There is no option for this in the BIOS settings. Seeing as the lid will be closed anyway I don't find it to be a problem  :Smile: 

Consider it solved!

Thanks again for all your help.

----------

