Skip to content

Instantly share code, notes, and snippets.

@tsertkov
Forked from kacinskas/CoreOS swap
Last active May 28, 2021 05:18
Show Gist options
  • Select an option

  • Save tsertkov/573d077012ae76443cbf to your computer and use it in GitHub Desktop.

Select an option

Save tsertkov/573d077012ae76443cbf to your computer and use it in GitHub Desktop.
cloud-config file for enabling swap on CoreOS
# swith to sudo
sudo -i
# create swap
touch /2GiB.swap
chattr +C /2GiB.swap
fallocate -l 2048m /2GiB.swap
chmod 600 /2GiB.swap
mkswap /2GiB.swap
# create service unit to start swap [/etc/systemd/system/swap.service]
[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=local.target
# add service and start
systemctl enable /etc/systemd/system/swap.service
systemctl start swap
# reboot
reboot
# Options
cat /proc/sys/vm/swappiness
sysctl vm.swappiness=10
https://github.com/coreos/docs/issues/52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment