Adding a swap partition for hiberating

  • Hello,

    I would like to enable hibernation (aka suspend to disk) support to my LibreELEC powered Raspberry Pi 3B (in fact it's Lakka but it doesn't matter). I added CONFIG_HIBERNATING=y to the linux.arm.conf file. When I want to compile LibreELEC, it asks me for a hibernation swap partition, which is required (and must be enabled before hibernating).

    When I looked at LibreELEC, I saw that we could create a swap file, but not a swap partition, which is understandable. But in order to hibernation to work, I need a swap partition. So here is my question : how can I add a swap partition to my SD card (or an external drive it doesn't matter), and is it possible to automate this process in the compilation process (because you know, creating a swap by hand each time I burn the image to the SD card is not optimal) ?

    Thanks for your help :)

  • Quote

    Lakka is reasonably similar to LE, but not entirely.

    The core system part is the same, isn't it ?

    Quote

    However, the swap mounting process will use a pre-existing swap partition if present in preference to a swap file.

    So I need to create the partition and put it in the swap.conf ? Or will it be created by the swap service ?

    The partition needs to be created in the IMG file, before the first filesystem expansion, right ? So I must create it somehow during the system compilation, let's say in /dev/sdb3, and put /dev/sdb3 in the swap.conf file ?

    Edited once, last by natinusala (October 14, 2017 at 6:06 PM).

  • Lakaa is Lakka. I've never booted it so I cannot state whether it works exactly the same. In LE: create a swap partiion after installing and then create /storage/.config/swap.conf with the right content and it will be used "as a swap partition" .. no idea whether it also works as a hybernation partition; we don't support that function so you need to experiment. Content of swap.conf can be figured out looking at the URL that I posted.

  • Quote

    no idea whether it also works as a hybernation partition; we don't support that function so you need to experiment. Content of swap.conf can be figured out looking at the URL that I posted.

    Well I'm going to try and see if it works !

    Quote

    In LE: create a swap partiion after installing

    How can I do this ? I have to resize the storage partition too, can this be done with Gparted on the host computer ?

    Quote

    Does an RPi3 even support hibernation? How do you come out of hibernation?

    I saw that it was supported using pm-hibernate. To come out of hibernation you can just unplug the power and put it back in (which will be done using a ATXRaspi in my case). I also saw that if the RPi is powered, you can join two specific GPIOS together to wake it up, this is used to make cheap power buttons for instance

    Edited once, last by natinusala (October 14, 2017 at 6:58 PM).

  • Quote

    I think the issue here is whether the host is correctly saved. If it is then, you shouldn’t have an issue. However my thoughts are why bother!

    The goal is to make a portable game console, and I would like to have the ATXRaspi power button perform an hibernation instead of a shutdown.

    This way, I can play my game, and when I want to stop I press the power button, which will send a hibernation signal to the RPi, thus pausing the game. Then, the ATXRaspi will cut the power to save battery life (this is why it's interesting). When I press power again, the Rpi will be powered and will resume its activity, showing up the game exactly as I left it !

    edit : Okay so I enabled everything, activated the swap... and when I do systemctl hibernate, it doesn't do anything but freezing the SSH server... meh, it doesn't look so supported after all. Is there a way to achieve what I would want without hibernation ?

    Edited 2 times, last by natinusala (October 14, 2017 at 9:12 PM).

  • The RPi3 will take at least 2.5 minutes (quite possibly longer) to write up to 1GB RAM to a hibernation file/partition (writing at up to 7MB/s on SD card, and most SD cards will be slower than this), so maybe it's working but it's just not a practical solution because it just takes forever to save the hibernation state.

    Saving a small amount of state on shutdown and restoring same on power up would get you most of what you want without waiting while 1GB of RAM is dribbled out to SD card, but you'd need to speak to the Lakka developers about this as I'm not sure what applications they use or what the apps are capable of.

  • Wow that's actually very slow !

    Implementing a smaller state is very possible, and I already thought about it. I basically have to store the core (emulator) used along with the running game, make a save state and then shut down the RPi. On next boot I'll check if such a state is existing and reload the core, game and the save state. I know how RetroArch works, I think I can implement this myself... I'll give it a try !

    edit : I can even do simpler by using the autosave/autoload feature and a modified version of the RetroArch service and ATXRaspi script

    Edited once, last by natinusala (October 15, 2017 at 4:00 PM).

  • Having looked into it, it would seem that hibernate is not possible on the ARM. Which is the same conclusion you must have come to.

    You could just leave the RPi on :) I don't know the value exactly but it cannot be more than £7 py. Add a TV tuner card and you have a free PVR as well

  • It's for a portable project, with a battery, leaving it on is not an option ^^

    The Linux kernel configuration for the system has the ARCH_HIBERNATION_SUPPORTED flag set to true, so I thought that it was OK, but apparently it's not

  • I don't know what standby mode refers to, but I don't think it will work since the power needs to be cut in order to my power button to work.

    When I press the power button the ATXRaspi will send a shutdown command to the RPi which will shutdown (duh). Then, the ATXRaspi will detect that a GPIO is low and will cut the power. When I press it again it will power it back up and wait for a specific GPIO to turn high to stop the fancy LED blinking.

    So standby mode or any other suspend to RAM method will not work if I'm willing to use the ATXRaspi.