# tuxonice and suspend to file

## fau

Hello,

I ran into some problems trying to set up hibernating to file on my laptop. I have 2.6.30 tuxonice-sources kernel with default tuxonice configuration. When I enter "FilewriterLocation /suspend_file 2048" tuxonice creates the file and I can use it to suspend during that session. However after reboot it doesn't recognize it and prints following error:

```

Starting suspend at wto, 27 kwi 2010, 20:12:08 CEST

hibernate: [01] Executing CheckLastResume ... 

hibernate: [01] Executing CheckRunlevel ... 

hibernate: [01] Executing LockFileGet ... 

hibernate: [01] Executing NewKernelFileCheck ... 

hibernate: [10] Executing EnsureTuxOnIceCapable ... 

hibernate: [11] Executing TuxOnIceSetupFilewriter ... 

hibernate: Filewriter image (/suspend_file) is unrecognised.

hibernate: I'm not even going to attempt to use this file to hibernate to.

hibernate: Please erase the contents of the existing file if you believe it

hibernate: to be safe, otherwise, please specify a new file.

hibernate: TuxOnIceSetupFilewriter refuses to let us continue.

hibernate: Aborting.

hibernate: [11] Executing TuxOnIceCleanupFilewriter ... 

hibernate: [01] Executing NoteLastResume ... 

hibernate: [01] Executing LockFilePut ... 

hibernate: [00] Executing RemoveTuxOnIceProcCruft ... 

Resumed at wto, 27 kwi 2010, 20:12:08 CEST

```

Just let me know and i'll post any additional info.

----------

## MotivatedTea

Your setup is incomplete. You need to follow all of the instructions here:

http://en.gentoo-wiki.com/wiki/TuxOnIce#Alternative:_Using_a_Dedicated_File

In particular, you need to determine the hibernation file's offset and include that in the resume parameter.

----------

## Paczesiowa

it's a known bug in tuxonice (2 years?), kernel part uses different signature than hibernate script (you can check first 10 bytes of that file, it's supposed to be 'tuxonice' and it usually is garbage). it was supposed to be fixed with newer hibernate-script, but nobody knows when it will come out.

----------

## fau

When I manually add "TuxOnIce" to my suspend file I get "no storage avaible" error. I guess that this time kernel doesn't recognise his header so it breaks. Is there any way to suspend to file using tuxonice then?

----------

## Paczesiowa

how do you add that? "echo tuxonice > suspend_file"? that puts ONLY that word in the file, so it's too small. you have to create as as big as it must be (e.g. using hibernate script) and then overwrite first word, I don't know how to do that from bash, but it's easy to do in C, iirc I have that code on my laptop so if you want I could get it for you.

----------

## MotivatedTea

You can put the header in the file like this:

```
# echo -n "TuxOnIce" > header.tmp

# dd if=header.tmp of=suspend_file conv=notrunc

# rm header.tmp
```

You could also use something like app-editors/hexedit to edit the file directly.

I thought the hibernate script was supposed to do that for you, though? I have used hibernation files before, but I switched to using swap files a while ago.

----------

## fau

@MotivatedTea:

It works, but I don't know why hibernate-cleanup doesn't do it - suspend file's header is broken after every reboot.

This is my hibernate-cleanup script:

```

HIBERNATE_FILEWRITER_TRAIL="/var/run/TuxOnIce_filewriter_image_exists"

clear_swap() {

        local where wason

        where=$1

        wason=

        swapoff $where 2>/dev/null && wason=yes

        mkswap $where > /dev/null || msg_status " (failed: $?)"

        [ -n "$wason" ] && swapon $where

}

check_swap_sig() {

        local where what type rest p c

        while read  where what type rest ; do

                test "$type" = "swap" || continue

                case "$(dd if=$where bs=1 count=6 skip=4086 2>/dev/null)" in

                        S1SUSP|S2SUSP|ULSUSP|pmdisk|[zZ]*)

                                msg_status "$where"

                                clear_swap $where

                                msg_status ", "

                esac

        done < /etc/fstab

}

check_filewriter_sig() {

        local target

        [ -f "$HIBERNATE_FILEWRITER_TRAIL" ] || return 0

        read target < $HIBERNATE_FILEWRITER_TRAIL

        [ -f "$target" ] || return

        case "`dd \"if=$target\" bs=8 count=1 2>/dev/null`" in

                HaveImag)

                        /bin/echo -ne "TuxOnIce\n\0\0" | dd "of=$target" bs=11 count=1 conv=notrunc 2>/dev/null

                        msg_status -n "$target, "

                        rm -f $HIBERNATE_FILEWRITER_TRAIL

        esac

}

do_start() {

        check_swap_sig

        check_filewriter_sig

}

do_stop() {

        :

}

do_reload() {

        :

}

```

----------

## MotivatedTea

That's the same as mine, but I'm using swapfiles now, not hibernation  files. However, it looks like the hibernate-cleanup script won't do anything unless "/var/run/TuxOnIce_filewriter_image_exists" exists:

```
[ -f "$HIBERNATE_FILEWRITER_TRAIL" ] || return 0 
```

I don't know what is supposed to create that file. I can't seem to find any other references to it. Does that file exist on your computer? If it's not getting created, then that explains why hibernate-cleanup isn't doing anything. It looks like it's supposed to hold the location if your swapfile.

If that file exists, the check_filewriter_sig reads it and stores its contents in $target. It then checks to see if $target starts with "HaveImag". If it does, it overwrites the start of $target with "TuxOnIce". Finally, it deletes /var/run/TuxOnIce_filewriter_image_exists. So it looks like your problem would be solved if /var/run/TuxOnIce_filewriter_image_exists were created properly. I don't know where that's supposed to happen, though. I'd try to reproduce the problem, but I don't have a computer running Gentoo that I can switch to hibernation files on at the moment.

----------

## fau

I've removed error stream's redirection from script and now it prints: 

```
dd: opening `#/dev/SWAP' no such file or directory'

```

----------

## MotivatedTea

That's coming from check_swap_sig, and you're not using the swap writer. That error message just indicates that it didn't find a hibernation image in what it thought might be a swap file (but wasn't). As I said before, if you're using a hibernation file, then the hibernate-cleanup script isn't going to do anything unless the file "/var/run/TuxOnIce_filewriter_image_exists" exists. Have you checked to see if it does?

----------

## fau

Ach I forgot - it doesn't exist.

----------

## MotivatedTea

I'm not sure what it is that is supposed to create that file, but that explains why the hibernate-cleanup script isn't doing anything. At this point, you could try to figure out where that's supposed to be coming from (maybe file a bug report when you do), or you could hack it so that it works. You could modify the hibernate-cleanup script, but you might have to re-do the modifications when the scripts get updated. Or, since you have the right command to run, you could put it in "/etc/conf.d/local.start" for now until the problem gets solved.

Or, you could switch to using a swapfile. (You can use swap files, not just partitions.) Tuxonice allows you to specify scripts that get run during the hibernation process and on resuming. What I played around with in the past was making a swapfile, but not setting it to mount automatically in /etc/fstab. I would only mount it just before hibernation, and then unmount it just after. That means it has pretty much the same effect as a hibernation file.

----------

## fau

OK, I'll do one of these. Thank you for helping me  :Smile: 

----------

