Skip to content

Instantly share code, notes, and snippets.

@dillera
Forked from philips/gist:7310435
Created November 5, 2013 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dillera/7319664 to your computer and use it in GitHub Desktop.
Save dillera/7319664 to your computer and use it in GitHub Desktop.

Setup a swap file in the stateful partition

Run these commands as root to create a 512 megabyte swap.

fallocate -l 512m /media/state/512MiB.swap
chmod 600 /media/state/512MiB.swap
mkswap /media/state/512MiB.swap

Create a unit to initialize it on boot

Create a unit file at /media/state/units/swapon.service with these contents:

[Unit]
Description=Turn on swap

[Service]
Type=oneshot
ExecStart=/sbin/swapon /media/state/512MiB.swap

[Install]
WantedBy=local.target

Enable the unit and start using swap

systemctl enable --runtime /media/state/units/swapon.service
systemctl start swapon

On your next reboot the swap will be turned on automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment