Skip to content

Instantly share code, notes, and snippets.

@so0k
Forked from romaninsh/swapon.service
Last active August 4, 2016 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save so0k/6cedf6a57be8d1cf91dc to your computer and use it in GitHub Desktop.
Save so0k/6cedf6a57be8d1cf91dc to your computer and use it in GitHub Desktop.
Set up swap on CoreOS
[Unit]
Description=Turn on swap
[Service]
Type=oneshot
Environment="SWAPFILE=/4GiB.swap"
RemainAfterExit=true
ExecStartPre=/usr/bin/touch ${SWAPFILE}
ExecStartPre=/usr/bin/chattr -C ${SWAPFILE}
ExecStartPre=/usr/bin/fallocate -l 4096m ${SWAPFILE}
ExecStartPre=/usr/bin/chmod 600 ${SWAPFILE}
ExecStartPre=/usr/sbin/mkswap ${SWAPFILE}
ExecStartPre=/usr/sbin/losetup -f ${SWAPFILE}
ExecStart=/usr/bin/sh -c "/sbin/swapon $(/usr/sbin/losetup -j ${SWAPFILE} | /usr/bin/cut -d : -f 1)"
ExecStop=/usr/bin/sh -c "/sbin/swapoff $(/usr/sbin/losetup -j ${SWAPFILE} | /usr/bin/cut -d : -f 1)"
ExecStopPost=/usr/bin/sh -c "/usr/sbin/losetup -d $(/usr/sbin/losetup -j ${SWAPFILE} | /usr/bin/cut -d : -f 1)"
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment