Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- # Copyright (C) Sebastian Philipp
- #
- set -e
- swapsize="$1"
- swapname="$2"
- if [ -z "$swapsize" -o -z "$swapname" ]
- then
- cat <<EOF
- Usage: $0 <size> <file>
- size: the size of the file, like "8G"
- file: path to the new swap file. This file should not exists.
- EOF
- exit 1
- fi
- if [ -e $swapname ]
- then
- echo "error: File already exists. $swapname"
- exit 1
- fi
- swapfile=$(losetup -f) #free loop device
- # set NOCOW
- touch $swapname
- chattr +C $swapname
- head -c $swapsize /dev/zero >> $swapname
- losetup $swapfile $swapname #mount file to loop
- mkswap $swapfile
- swapon $swapfile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement