Advertisement
Guest User

btrfs-swapon

a guest
Nov 10th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.62 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # Copyright (C) Sebastian Philipp
  4. #
  5.  
  6. set -e
  7.  
  8. swapsize="$1"
  9. swapname="$2"
  10.  
  11.  
  12. if [ -z "$swapsize" -o -z "$swapname" ]
  13. then
  14.     cat <<EOF
  15. Usage: $0 <size> <file>
  16.  
  17. size:      the size of the file, like "8G"
  18. file:      path to the new swap file. This file should not exists.
  19. EOF
  20.     exit 1
  21. fi
  22.  
  23. if [ -e $swapname ]
  24. then
  25.     echo "error: File already exists. $swapname"
  26.     exit 1
  27. fi
  28.  
  29. swapfile=$(losetup -f) #free loop device
  30.  
  31. # set NOCOW
  32. touch $swapname
  33. chattr +C $swapname
  34. head -c $swapsize /dev/zero >> $swapname
  35.  
  36. losetup $swapfile $swapname #mount file to loop
  37. mkswap  $swapfile
  38. swapon  $swapfile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement