Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. set -e
  4.  
  5. NAME=foo
  6. FILE=/.$NAME.fs
  7. FSIZE=1
  8. DIR=/mnt/$NAME
  9. KEYDIR=/root
  10. ###
  11.  
  12. cryptmount=$(which cryptmount)
  13. if [ -z "$cryptmount" ]; then echo "sorry, no cryptmount installed"; exit; fi
  14.  
  15. btrfs=$(which btrfs)
  16. if [ -z "$btrfs" ]; then echo "sorry, no btrfs-tools installed"; exit; fi
  17.  
  18. echo "generating $FILE (takes while) ..."
  19. dd if=/dev/zero of=$FILE bs=1G count=$FSIZE
  20.  
  21. cp -f /etc/cryptmount/cmtab /etc/cryptmount/cmtab.$(date -I).bak
  22. cat >> /etc/cryptmount/cmtab <<EOF
  23. # created by $(basename $0)
  24. $NAME {
  25. dev=$FILE
  26. dir=$DIR
  27. fstype=btrfs
  28. mountoptions=noatime
  29. cipher=aes
  30. keyformat=builtin
  31. keyfile=$KEYDIR/$NAME.key
  32. flags=user,nofsck
  33. }
  34. EOF
  35.  
  36. echo "generating key: $NAME .."
  37. $cryptmount --generate-key 32 $NAME
  38. $cryptmount --prepare $NAME
  39.  
  40. echo "making btrfs on: $NAME ..."
  41. mkfs.btrfs /dev/mapper/$NAME
  42. mkdir -p $DIR
  43. mount -t btrfs -o noatime /dev/mapper/$NAME $DIR
  44.  
  45. echo "creating btrfs subvolumes on: $DIR: "
  46. $btrfs subvolume create $DIR/rsnapshot
  47. $btrfs subvolume create $DIR/rsnapshot/hourly.0
  48. $btrfs subvolume create $DIR/rsnapshot/hourly.1
  49. $btrfs subvolume create $DIR/rsnapshot/hourly.2
  50. $btrfs subvolume create $DIR/rsnapshot/hourly.3
  51. $btrfs subvolume create $DIR/rsnapshot/hourly.4
  52. $btrfs subvolume create $DIR/rsnapshot/weekly.0
  53. $btrfs subvolume create $DIR/rsnapshot/weekly.1
  54. $btrfs fi df $DIR
  55. $btrfs subvolume list $DIR
  56. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement