1

I have a systemd unit file that does swapon, but it doesn't seem to run on each boot even though it's enabled.

Here are the contents of my swapon.service:

[Unit]
Description=Turn on swap

[Service]
Type=oneshot
Environment=SWAPFILE=/swapfile-1GB
ExecStartPre=-/usr/bin/dd if=/dev/zero of=${SWAPFILE} bs=1024 count=1048576
ExecStartPre=-/sbin/mkswap ${SWAPFILE}
ExecStart=/sbin/swapon ${SWAPFILE}

[Install]
WantedBy=local.target

This should optionally create the file and make it into a swapfile optionally if it hasn't been done yet, then run swapon on it. It's enabled, but doesn't run on boot; I manually have to run sudo systemctl start swapon which does work.

How do I get it to run on boot?

2
  • How do you know it is enabled? Commented Mar 21, 2016 at 8:51
  • It's listed and marked as "enabled" when I list all the units Commented Mar 21, 2016 at 9:46

2 Answers 2

0

I fixed this by changing local.target at the end to swap.target

Sign up to request clarification or add additional context in comments.

Comments

0

FWIW, there is a swap unit that can be used to control swapfile activation:


[Swap]
What=/swapfile

(etc)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.