Guest User

Untitled

a guest
Oct 21st, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # DANGEROUS!
  4. #
  5. # Benchmark drive with bonnie using ext4: vanilla, LUKS, LVM, LUKS + LVM
  6. #
  7. set -euxo pipefail
  8.  
  9. DISK="/dev/sda"
  10. RUNS=3
  11. RESULTS_DIR="results"
  12.  
  13. ########################################################
  14. # No need to edit anything below for normal usage. #
  15. ########################################################
  16.  
  17. PART="${DISK}1"
  18. CRYPT_VOLUME_NAME="crypt-benchmark"
  19. CRYPT_VOLUME="/dev/mapper/$CRYPT_VOLUME_NAME"
  20. USER="lulu"
  21. MOUNTPOINT="/mnt"
  22. BONNIEDIR="$MOUNTPOINT/bonnie"
  23. PASSWORD="MUCHSECURE"
  24. VOLUME_NAME="benchmark"
  25. VOLUME_GROUP="vg"
  26. VG_PATH="/dev/$VOLUME_GROUP/$VOLUME_NAME"
  27.  
  28. run-bonnie() {
  29. local rundir="$RESULTS_DIR/$1"
  30. mkdir -p "$rundir"
  31. for iter in $(seq 0 $RUNS); do
  32. local fname="$rundir/${iter}.txt"
  33. bonnie++ -d "$BONNIEDIR" -n 1 -u $USER | tee "$fname"
  34. chown $USER "$fname"
  35. done
  36. }
  37.  
  38. test-unencrypted() {
  39. echo "Testing ext4 unencrypted."
  40. format "$PART"
  41. mount-volume "$PART"
  42. run-bonnie ext4
  43. }
  44.  
  45. test-luks(){
  46. echo "Testing LUKS."
  47. setup-luks
  48. format "$CRYPT_VOLUME"
  49. mount-volume "$CRYPT_VOLUME"
  50. run-bonnie luks
  51. }
  52.  
  53. test-lvm(){
  54. echo "Testing LVM."
  55. setup-lvm "$PART"
  56. format "$VG_PATH"
  57. mount-volume "$VG_PATH"
  58. run-bonnie lvm
  59. }
  60.  
  61. test-luks-lvm(){
  62. echo "Testing LUKS LVM."
  63. setup-luks
  64. setup-lvm "$CRYPT_VOLUME"
  65. format "$VG_PATH"
  66. mount-volume "$VG_PATH"
  67. run-bonnie luks-lvm
  68. }
  69.  
  70. setup-luks(){
  71. echo "Setting up LUKS."
  72. echo $PASSWORD | cryptsetup luksFormat "$PART"
  73. echo "Opening crypt volume."
  74. echo $PASSWORD | cryptsetup luksOpen "$PART" "$CRYPT_VOLUME_NAME"
  75. }
  76.  
  77. setup-lvm(){
  78. echo "Setting up LVM."
  79. pvcreate -y "$1"
  80. vgcreate $VOLUME_GROUP "$1"
  81. lvcreate -l '100%FREE' -n "$VOLUME_NAME" "$VOLUME_GROUP"
  82. }
  83.  
  84. format(){
  85. mkfs.ext4 "$1"
  86. }
  87.  
  88. mount-volume(){
  89. mount "$1" "$MOUNTPOINT"
  90. mkdir -p "$BONNIEDIR"
  91. chown $USER "$BONNIEDIR"
  92. }
  93.  
  94. clean() {
  95. echo "Unmounting file systems."
  96. umount "$MOUNTPOINT" || true
  97. echo "Removing logical volumes."
  98. lvremove -y "$VOLUME_GROUP" "$VOLUME_NAME" || true
  99. echo "Removing logical volume group."
  100. lvremove -y "$VOLUME_GROUP" || true
  101. echo "Removing physical volume group."
  102. pvremove -y -f -f $CRYPT_VOLUME || true
  103. pvremove -y -f -f $PART || true
  104. sleep 1
  105. echo "Removing device."
  106. dmsetup remove $CRYPT_VOLUME || true
  107. }
  108.  
  109. partition(){
  110. echo "Creating partition table."
  111. (echo o # new table
  112. echo Y # yes
  113. echo n # new part
  114. echo # number 1
  115. echo # start
  116. echo # end
  117. echo # linux
  118. echo w # write
  119. echo Y # yes
  120. ) | gdisk $DISK
  121. }
  122.  
  123. partition
  124.  
  125. clean
  126. test-unencrypted
  127.  
  128. clean
  129. test-luks
  130.  
  131. clean
  132. test-lvm
  133.  
  134. clean
  135. test-luks-lvm
Add Comment
Please, Sign In to add comment