2

I recently acquired a laptop with a ssd and in order not to weigh too much on the ssd (which I was told had a limited number of write cycles), I decided to write a systemd unit file for setting up a swap and a filesystem (to use later with asd) respectively on devices zram0 and zram1. I'm not really familiar with systemd and udev so I may have made a stupid error but I couldn't find it... here are my files : etc/udev/rules.d/10-zram.rules :

 KERNEL=="zram0",SYMLINK+="zramswap" ,ATTR{disksize}="1G" ,ENV{SYSEMD_WANTS}+="zram-swap@%k.service"

 KERNEL=="zram1",SYMLINK+="zramfs",ATTR{disksize}="250m", ENV{SYSTEMD_WANTS}+="zram-fs@%k.service"

/etc/systemd/system/zram-swap@.service

[Unit]
Description="Daemon that sets xfs on %i device"

BindsTo=dev-%i.swap

After=dev-%i.device
Requires=dev-%i.device

Before=dev-%i.swap
Wants=dev-%i.swap

[Service]
Type=oneshot
ExecStart="/usr/bin/mkswap /dev/%i"

zram-fs@.service is pretty much the same except it uses /usr/bin/mkfs.xfs (because I read xfs was fast to create)

and finally, the end of my fstab :

/dev/zram0      swap        swap    defaults    0 0
/dev/zram1      /media/asd  xfs     defaults    0 0

The problem is thar my system won't launch normally with this setup... when I try to swapon and mount these two devices, it tells me the swap and fs don't exist, and looking in journalctl -xb , there is an error while trying to mount and swapon these two devices for the same reason. But when I look in /sys, the devices sizes are the one I set up in the udev rules so I guess my rules are read and work, the problem seems to be my service files which aren't run and/or don't work...

1

I found what were my problems... the main one is that zram is not by default handeled by systemd. As a consequence, there was no dev-zram0.device unit, so my services failed because of the unsatisfied dependencies. The solution was to add

TAG+="systemd"

to my udev rules

There was another little error which was the line ExecStart in the daemon needed no double quotes " and that made it fail...

Thanks anyway if anyone tried to answer !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.