Skip to content

Instantly share code, notes, and snippets.

@arpat
Created November 17, 2016 14:32
Show Gist options
  • Save arpat/5f8dd71e1b7c4335d3ed54b250cf13f0 to your computer and use it in GitHub Desktop.
Save arpat/5f8dd71e1b7c4335d3ed54b250cf13f0 to your computer and use it in GitHub Desktop.
Make a swapfile on Linux of 1GB
#!/bin/bash
## blame: [email protected]
## Make a 1G swapfile in CWD
SwapFile="~~SWAPFILE.$(date +%H%m%s%N | sha1sum | cut -c1-12)"
# fallocate -l 1G $SwapFile \ ## caused issue for f2fs
dd if=/dev/zero of="$SwapFile" bs=1024 count=1048576 \
&& chmod 600 $SwapFile \
&& mkswap $SwapFile \
&& swapon $SwapFile
echo "MAKE SURE to switch swap off before making $SwapFile inaccessible with"
echo " swapoff $PWD/$SwapFile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment