Skip to content

Instantly share code, notes, and snippets.

@inlanger
Created October 1, 2013 13:25
Show Gist options
  • Save inlanger/6778396 to your computer and use it in GitHub Desktop.
Save inlanger/6778396 to your computer and use it in GitHub Desktop.
Create 1024mb swap partition
#!/bin/bash
### BEGIN INIT INFO
# Provides: swap
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 1 0 6
# Short-Description: add fake swap.
### END INIT INFO
SWAP="${1:-512}"
NEW="$[SWAP*1024]"; TEMP="${NEW//?/ }"; OLD="${TEMP:1}0"
umount /proc/meminfo 2> /dev/null
sed "/^Swap\(Total\|Free\):/s,$OLD,$NEW," /proc/meminfo > /etc/fake_meminfo
mount --bind /etc/fake_meminfo /proc/meminfo
free -m
swapon -s
dd if=/dev/zero of=/swapfile bs=1024 count=1024k
mkswap /swapfile
swapon /swapfile
echo "/swapfile none swap sw 0 0" > /etc/fstab
sudo chown root:root /swapfile
sudo chmod 0600 /swapfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment