3

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/[email protected]

[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"

[email protected] 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...

tbrugere
  • 966
  • 6
  • 16
  • In answer to [another question](https://unix.stackexchange.com/questions/17254/how-to-set-up-properly-zram-and-swap/17280#17280) I described how to do it with udev rules alone. – Maciej Piechotka Nov 08 '17 at 03:11

1 Answers1

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 !

tbrugere
  • 966
  • 6
  • 16