-
-
Save tsertkov/573d077012ae76443cbf to your computer and use it in GitHub Desktop.
cloud-config file for enabling swap on CoreOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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