1

I need to get my Pi4 running Raspbian to sleep or hibernate. The when I type the commands systemctl suspend or systemctl hibernated I get the error 'not supported'. Is it possible to enable this functionality? Or is there another way to do this?

My goal is to get the Pi4 to boot as fast as possible. Current, it takes 30 seconds.

My Pi4 has is the 2gig version.

Please help. Thanks!

Sarphati
  • 11
  • 3
  • 1
    not supported is pretty clear ... if your goal is to boot fast, look at cmdline.txt and config.txt options that can improve boot speed a bit – Jaromanda X Apr 16 '20 at 11:18
  • Does this answer your question? [How to hibernate/suspend rapberry pi?](https://raspberrypi.stackexchange.com/questions/104221/how-to-hibernate-suspend-rapberry-pi) – itiic Apr 16 '20 at 11:20
  • 30 seconds for an RPi4 to boot sounds like an awfully long time. Are you spinning up a lot of services at boot time? – Seamus Apr 19 '20 at 00:45

1 Answers1

6

Raspbian kernel is built without CONFIG_HIBERNATION which is needed to provide the necessary interfaces for systemctl. You will have to build a custom kernel to enable those interfaces. You will also need a swap partition which is at least as big as your RAM size (2GB) for the hibernation to actually work, and you need to make sure the kernel command line is updated before power-off so that the kernel knows it must resume from swap instead of a regular boot. I don't think systemctl is aware of /boot/config.txt.

Another issue making hibernation less practical is the Pi power management after shutdown. You'll need to configure the Pi bootloader with POWER_OFF_ON_HALT to actually get the power consumption down, and once you do that, you need to either toggle the GLOBAL_EN node (HI-LO-HI), or unplug and re-plug the power to boot again.

Note that @goldilocks have tried enabling hibernation on a Pi, and it didn't work. See his comment below.

Suspending to RAM and standby (or power-on suspend) additionally require hardware support (ACPI/APM or the like) which AFAIK is missing on Raspberries, so even if you get the command accepted by systemctl, there will be no reduction in power consumption.

The simplest thing you can do is to leave the Pi running: it doesn't consume that much power in the first place, and there will be no boot time at all when you need it.

Dmitry Grigoryev
  • 26,688
  • 4
  • 44
  • 133
  • Thanks Dmitry. That explains a lot. I have a Witty Pi hat for my Pi4. This hat can control shutdown and startup and can be triggered via an external source. Have it set up to turn on where there is an external power source and to shut down gracefully when the external power source is turned off. I want it to hibernate instead of shutting off. I will start by looking into building my own kernal (sounds very daunting) and including CONFIG_HIBERNATION. I also need to create the swap partition of 2GB. How to resume from swap is the question. Thanks! – Sarphati Apr 16 '20 at 13:40
  • @Sarphati add `resume=/dev/your_swap_partition` to `config.txt` – Dmitry Grigoryev Apr 16 '20 at 17:57
  • 1
    Interesting answer - I've long been curious re the absence of any hibernate or sleep mode for RPi - even though such a mode appears to be required by regulations that were inspired by the [*One Watt Initiative*](https://en.wikipedia.org/wiki/One_Watt_Initiative). I've done some reading, and it now *seems* to me that the [kernel has all of the necessary plumbing](https://man.archlinux.org/man/systemd-sleep.8) to do this (e.g. `systemd-logind`), but the RPi side of this interface does not. – Seamus Jul 15 '21 at 05:31
  • More documentation on this subject is available here:https://www.kernel.org/doc/html/v5.4/power/interface.html – Seamus Jul 15 '21 at 22:24
  • @Seamus This one watt initiative sounds interesting, but I'm skeptical about its practical effects. A Pi can consume as much as it likes because it is out of scope (not mains-powered). And even equipment which is in scope will not be forbidden for sale, it will simply not get certified. What do you think customers will buy: a $100 OEM charger with a boring FCC/CE mark, or a $30 Baseus charger with a shiny GaN label and a fake CE mark (the "China Export" one)? – Dmitry Grigoryev Jul 16 '21 at 07:33
  • @Seamus Actually, the way it is written, it sounds like the one-watt requirement only applies to devices which claim to have a standby mode. As such I don't see the obligation to have such a mode at all. – Dmitry Grigoryev Jul 16 '21 at 09:27
  • 1
    *"You will have to build a custom kernel to enable those interfaces."* I have tried this, it does not work, unfortunately (and I've been doing that with linux since before the Pi existed). I was firmly of the opinion that the way hibernate works does not require any hardware support -- it's just saving the memory state to the storage and then loading it again at boot. Normally, power can be completely removed from a system that has been put into hibernate (it can just end with a normal shutdown, right?). But for whatever reason it fails on the Pi (I don't remember what actually happens). – goldilocks Jul 16 '21 at 13:49
  • 1
    @Seamus *"the kernel has all of the necessary plumbing to do this (e.g. systemd-logind)"* 1) Systemd is not part of the kernel and logind is not required to perform suspend or hibernate (you don't need any init system at all; see documentation for `/sys/power/state`). 2) WRT to hibernate, the stock pi kernel certainly does **not** have the necessary bits built in, last I checked. You can confirm this via `sudo modprobe configs; gunzip -c /proc/config.gz | HIBERNAT`, no E on the end to catch -ION and -E; the result is interesting but negative). – goldilocks Jul 16 '21 at 14:03
  • @goldilocks Do you remember if you had the issue while entering hibernation or upon resuming from it? – Dmitry Grigoryev Jul 16 '21 at 14:26
  • Pretty sure it was resuming, but I cannot remember at all whether it just ignored the `resume=` or crapped out in some sense. Probably done with a 3B+. – goldilocks Jul 16 '21 at 15:17
  • @goldilocks: Thanks for this massive clarification! :) When I first read your comment that `systemd` was not part of the kernel, I thought, "Poor guy hasn't had his morning coffee yet." But of course you are correct! And fascinated by your experiments with adding a `hibernate` function. What would it take to get you to resurrect &/OR document this?? – Seamus Jul 16 '21 at 17:53
  • @DmitryGrigoryev: `... but I'm skeptical...`. I'm very much in touch with that emotion :) In this case though, I'm not clear why you classify the Pi as `not mains-powered`... how could it be anything but that?! Certainly not battery-powered. Surely they can't make an exception because someone puts a wall-wart between the device and the mains source - seems that would give all mfrs an easy work-around to the regulations. – Seamus Jul 16 '21 at 18:01
  • *"What would it take to get you to resurrect &/OR document this??"* -> I'm not sure there's much of a point. If you've built and used a custom kernel before, this is just a matter of setting a few options. I've noticed hibernate is often left out of "ordinary" distro kernels too, I think it is considered a little bit dangerous because if it boots and loads a mem image that is out of step with the filesystem, that system is potentially garbaged (this would be a user screw-up, I've never had it happen, but it would not be that hard to arrange via a series of simple mistakes). – goldilocks Jul 17 '21 at 14:27
  • ...If you've never built a kernel before, I don't see the point in going through that *again* here. Finally, of course, it just doesn't work (and reflecting a bit now on my point about the potential for problems, the potential is that much worse in a context where fs corruption seems to be much more common than most, ie., it probably is not a good idea for most users and so having that bar there is likely for the best). – goldilocks Jul 17 '21 at 14:27
  • @goldilocks: `But for whatever reason it fails on the Pi (I don't remember what actually happens).` Could it have been the issue with swap files for hibernation in `systemd` v 239 [mentioned here?](https://ihatesystemd.com/bad/#content) – Seamus Jul 17 '21 at 19:51
  • 1
    I don't use swap files. I put a partition at the end of the card. Also, I would almost certainly have used `/sys/power/state`, although there is a thin chance I might have used `systemd hibernate`. If I get time in the next few days I may do this again just to nail the problem down better. – goldilocks Jul 17 '21 at 20:04
  • @Seamus As far as I understand, the Pi and the wall wart are two separate products, I know I bought my Pi without any power supply. As such, you are allowed to power it from any 5V source, e.g. people are using the Pi in their cars. So I'm almost sure the mains-powered regulations don't apply to a Pi. (IANAL of course) – Dmitry Grigoryev Jul 19 '21 at 09:10
  • @DmitryGrigoryev: I'm no lawyer either, but understand the difference between the **spirit** of the law, and the **letter** of the law. To me, it seems the *One Watt **Initiative*** is the *spirit*, and that spirit strikes me as reasonable: **don't waste energy**. I don't feel it's unreasonable to expect the appliances we buy to respect that initiative - when it's possible and practical to do so. The only real point of my comment is this: *It is possible and practical for the RPi to implement the "hibernate" function in Linux.* One might ask, "Why has it not been done?" – Seamus Jul 19 '21 at 17:41
  • @Seamus, "Why has it not been done?" - because if you do everything that is possible and practical, you become too expensive and go out of business. I had this exact conversation at work last year: the first customer didn't ask for a sleep mode, so it was not implemented. When the second customer asked for it, there were only two options: get a $2 relay to shut down our product, or redesign and retest the hardware for $100'000. They only wanted 2000 pieces / year, so of course they went for a relay. – Dmitry Grigoryev Jul 20 '21 at 09:09
  • @DmitryGrigoryev: `become too expensive and go out of business`... Given the number of computing devices sold today, and the feature sets offered today vs 10, 15, 20 years ago, I struggle to see the precedent you claim. [RPi sales](https://en.wikipedia.org/wiki/Raspberry_Pi#Sales) are closing in on 1 million units per month. My math suggests that's 0.10-0.15 per unit cost at 100,000. But the markets are quite good at sorting such things, so we shall see. – Seamus Jul 20 '21 at 23:11