luks.j2 954 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/sh
  2. # Templated paths
  3. MAPPER="/dev/mapper"
  4. CRYPT_NAME="{{ luks_crypt_name }}"
  5. CRYPT_PATH="${MAPPER}/${CRYPT_NAME}"
  6. VG_NAME="{{ luks_vg_name }}"
  7. DEV="{{ luks_dev }}"
  8. # Sanity checks
  9. if [ ! -b "${DEV}" ]; then
  10. echo "Unable to find a suitable device" 1>&2
  11. exit 2
  12. fi
  13. # Determine if we need to format or just open
  14. FORMAT=0
  15. if basename "${0}" | grep -qi format; then
  16. FORMAT=1
  17. fi
  18. # Initial encryption
  19. if [ $FORMAT -gt 0 ]; then
  20. cryptsetup --type luks2 \
  21. --cipher aes-xts-plain64 \
  22. --hash sha512 \
  23. --key-size 512 \
  24. --sector-size 4096 \
  25. luksFormat "${DEV}"
  26. fi
  27. # Unlock
  28. cryptsetup luksOpen "${DEV}" "${CRYPT_NAME}"
  29. # Initial filesystem - note the big inodes for gluster
  30. if [ $FORMAT -gt 0 ]; then
  31. pvcreate "${CRYPT_PATH}"
  32. if [ $? != 0 ]; then
  33. echo "Unable to create LVM PV: ${CRYPT_PATH}" 1>&2
  34. exit 3
  35. fi
  36. vgcreate "${VG_NAME}" "${CRYPT_PATH}"
  37. if [ $? != 0 ]; then
  38. echo "Unable to create LVM VG: ${VG_NAME}" 1>&2
  39. exit 3
  40. fi
  41. fi