Skip to content

Instantly share code, notes, and snippets.

@hqingyi
Created July 6, 2015 09:25
Show Gist options
  • Save hqingyi/ab6c5baef3e56cc5af80 to your computer and use it in GitHub Desktop.
Save hqingyi/ab6c5baef3e56cc5af80 to your computer and use it in GitHub Desktop.
make file swap.
#!/bin/bash
# N and BYTES may be followed by the following multiplicative suffixes:
# c =1, w =2, b =512, kB =1000, K =1024, MB =1000*1000, M =1024*1024
help(){
echo "useage: `basename $0` -o full_path -b block_size(default 1K) -c block_count(default 2M)"
}
while getopts 'o:b:c:' OPT; do
case $OPT in
o)
of="$OPTARG";;
b)
bs="$OPTARG";;
c)
count="$OPTARG";;
esac
done
if [ -z "$of" ]; then
help
exit 1;
fi
if [ -z "$bs" ]; then
bs="1K"
fi
if [ -z "$count" ]; then
count="2M"
fi
echo "create swap file on: $of with bs:$bs count:$count"
dd if=/dev/zero of=$of bs=$bs count=$count
/sbin/mkswap $of
/sbin/swapon $of
echo "writing swapfile:$of to /etc/fatab."
echo "$of swap swap defaults 0 0" >> /etc/fstab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment