Hibernation - Swap Partition vs Swap File

Hi, Having a bit of trouble with putting a tumbleweed server into hibernation. When I run systemctl hibernation I get a message about swap space -

chris@localhost:~> systemctl hibernate 
Call to Hibernate failed: Not enough swap space for hibernation
chris@localhost:~> 

I built the server without a swap partition as I wanted to ‘experiment’ with zram. That part was easy as I have 2GB swap in /dev/zram0

chris@localhost:~> ls /dev/zram0
/dev/zram0
chris@localhost:~> free -m
               total        used        free      shared  buff/cache   available
Mem:            1958         344        1484           5         276        1614
Swap:           1958           0        1958
chris@localhost:~> 

I also setup the resume keyword in the grub config -

GRUB_CMDLINE_LINUX_DEFAULT="splash=verbose quiet security=apparmor resume=/dev/zram0 mitigations=auto"

But if I rebuild the server with a swap partition systemctl hibernate runs as expected.

Some sources claim swap files can not be used for hibernation, some say it’s ok.

Am I wasting efforts using zram or have I missed something in my setup?

Thanks…

The catch is, hibernation and zram-as-swap are conceptually incompatible with each other - hibernation requires the system’s memory/state to be written to a swap file/partition in non-volatile memory, so that the system can actually power down. On the other hand, using zram as your swap means that your swap is stored in volatile memory, and thus stops existing once the system powers down.

The file vs. partition thing matters less than the fact that wherever your swap is stored needs to be

  1. Contiguous - you can’t split hibernation data across multiple files/partitions
  2. Big enough to hold your system state - not necessarily equal to your amount of RAM, but that’s the intuitive benchmark
  3. Actually written to disk, so it can be read from when starting back up (“resuming” from hibernation)

Zram might have its uses/value, but AFAIK you’ll have to pick between whatever advantages you’re getting from Zram swap, vs. the ability to use your swap to hibernate.

But I thought zram is written to disk?

No, the idea of using zram is to avoid writing to the disk / instead make RAM usage more efficient. The intro paragraph and section 1 here do a pretty good job of explaining how it works:

https://wiki.archlinux.org/title/Zram

Ah, I misunderstood. OK I’m giving up the zram route. Looking at using a swapfile created under / as per howtogeek article,

Thanks.

No problem - I honestly didn’t really understand zram until reading about it recently (ironically, after switching away from Fedora where it was the default), it’s kind of an unintuitive concept!

God damn it! Encountered more issues with swap files, this time under BTRFS.

It’s simpler just to stick with swap partitions and avoid the grief :rage:

1 Like

Why do you need swap? I don’t run it micros doesn’t use it either. If your running containers then you want it off too….

Hi @malcolmlewis

Briefly, I now have a HP Elitedesk mini PC. I’m doing various ‘experiments’ on it but ultimately it will act as a low power media/NFS server with USB attached storage.

I want to hibernate the PC during the day to save power but bring it back online at night without having to re-mount the USB storage. Yes I could automount the storage via /etc/fstab but I’m plugging/swapping USBs around at the moment.

I went down the zram path because I liked the idea (and also learn about it) of growing the swap if I throw more RAM into the PC and hibernate.

I also want to run some podman containers via Cockpit so your comment about running containers without swap is curious. What’s the issue there please?

Regards…

@kitman Have a read here… https://github.com/kubernetes/kubernetes/issues/53533

I run mini pc’s (4 core 8 and 16GB of ram) here with RKE2 and K3s on MicroOS, they don’t get turned off, they update automatically (since I run Tumbleweed I get a preview of whats coming, so happy to auto update).

To be honest, systems don’t take that long to shutdown and boot up these days either…

But that’s all up to you, I would suggest MicroOS for self maintenance, designed for container workloads etc, but no swap…

Life was easier when I had DOS 3.1 back in the day :wink:

1 Like

@kitman Perhaps peruse the system BIOS and see if there is an option to power off the device and power back on on a schedule?

@kitman you might want to also look at k3s for containers, I can do everything on my local machine for deployment using helm charts. To investigate it’s use I suggest installing Rancher-Desktop to develop on, there are free courses at the SUSE Rancher Academy as well… https://www.rancher.academy/

There’s an option to daily “power on” at set times. But I found it easier just to edit the logind.conf file and set
HandlePowerKey=hibernate - 1 press in the morning hibernates, 1 press in the evening puts it back online.

I looked at k3s some time ago and thought it’s not for me. Plus I prefer podman over docker (why? I don’t know). Podman and VMs under Cockpit is really nice.

But my new learning curve after the silly season will be MicroOS. :christmas_tree:

Thanks.

@kitman podman and distrobox on MicroOS…