Failed to start Service enabling compressing RAM with zRam

After the latest updates it is no longer possible to make zram service work.

Vento:/home/xxxxxx # systemctl status zramswap.service
× zramswap.service - Service enabling compressing RAM with zRam
Loaded: loaded (/usr/lib/systemd/system/zramswap.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2022-06-22 17:58:00 CEST; 38s ago
Process: 3615 ExecStart=/usr/sbin/zramswapon (code=exited, status=255/EXCEPTION)
Main PID: 3615 (code=exited, status=255/EXCEPTION)

jun 22 17:58:00 Vento zramswapon[3639]: swapon: impossível abrir /dev/zram1: Ficheiro ou pasta inexistente
jun 22 17:58:00 Vento zramswapon[3640]: swapon: impossível abrir /dev/zram2: Ficheiro ou pasta inexistente
jun 22 17:58:00 Vento zramswapon[3641]: swapon: impossível abrir /dev/zram3: Ficheiro ou pasta inexistente
jun 22 17:58:00 Vento zramswapon[3642]: swapon: impossível abrir /dev/zram4: Ficheiro ou pasta inexistente
jun 22 17:58:00 Vento zramswapon[3643]: swapon: impossível abrir /dev/zram5: Ficheiro ou pasta inexistente
jun 22 17:58:00 Vento zramswapon[3644]: swapon: impossível abrir /dev/zram6: Ficheiro ou pasta inexistente
jun 22 17:58:00 Vento zramswapon[3645]: swapon: impossível abrir /dev/zram7: Ficheiro ou pasta inexistente
jun 22 17:58:00 Vento systemd[1]: zramswap.service: Main process exited, code=exited, status=255/EXCEPTION
jun 22 17:58:00 Vento systemd[1]: zramswap.service: Failed with result ‘exit-code’.
jun 22 17:58:00 Vento systemd[1]: Failed to start Service enabling compressing RAM with zRam.

[FONT=arial]Any Idea how to fix it?
[/FONT]
Tanks

Found this on the web in an Opensuse Reddit entry: Cannot start/enable systemd-zramswap.service

In the thread:

I have found two workarounds:




  - Running command manually works: sudo zramswapon 
  - In service file /usr/lib/systemd/system/zramswap.service, there is automatic added code: 




# added automatically, for details please see
# https://en.opensuse.org/openSUSE:Security_Features#Systemd_hardening_effort
ProtectSystem=full
ProtectHome=true
PrivateDevices=true
ProtectHostname=true
ProtectClock=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectKernelLogs=true
ProtectControlGroups=true
RestrictRealtime=true
# end of automatic additions.
Remove all that. Call sudo systemctl daemon-reload and sudo systemctl enable zramswap.service and now it works.




The bugs referenced in that thread are against the zram service in Tumbleweed, but at the bottom ofBugzilla – Bug 1193402, it’s noted that the problem exists in 15.4, too.

Hi
I suspect the systemd hardening effort… as it was dropped in Tumbleweed;

See https://build.opensuse.org/package/view_file/filesystems/systemd-zram-service/systemd-zram-service.changes?expand=1

In the interim as root user;


cp /usr/lib/systemd/system/zramswap.service /etc/systemd/system/zramswap.service

Edit out the following section in the /etc/systemd/system/zramswap.service




# added automatically, for details please see
# https://en.opensuse.org/openSUSE:Security_Features#Systemd_hardening_effort
ProtectSystem=full
ProtectHome=true
PrivateDevices=true
ProtectHostname=true
ProtectClock=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectKernelLogs=true
ProtectControlGroups=true
RestrictRealtime=true
# end of automatic additions 

Once edited;


systemctl daemon-reload
systemctl start zramswap.service

Test...

free
              total        used        free      shared  buff/cache   available
Mem:       16192796      217204    15505260        9520      470332    15691784
Swap:       7183720           0     7183720

systemctl start zramswap.service 

free
              total        used        free      shared  buff/cache   available
Mem:       16192796      292000    15429944        9540      470852    15616944
Swap:      23376504           0    23376504

Maintenance request created: https://build.opensuse.org/request/show/984580