Skip to content

Instantly share code, notes, and snippets.

@PyYoshi
Created November 5, 2015 04:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save PyYoshi/7db8723d9bf1f0142090 to your computer and use it in GitHub Desktop.
Save PyYoshi/7db8723d9bf1f0142090 to your computer and use it in GitHub Desktop.
Mount swap 2GB on CoreOS
$ sudo -i
# touch /2GiB.swap
# chattr +C /2GiB.swap
# fallocate -l 2048m /2GiB.swap
# chmod 600 /2GiB.swap
# mkswap /2GiB.swap
# vim /etc/systemd/system/swap.service
# systemctl enable /etc/systemd/system/swap.service
# systemctl start swap
# free
[Unit]
Description=Turn on swap
[Service]
Type=oneshot
Environment="SWAPFILE=/2GiB.swap"
RemainAfterExit=true
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