Skip to content

Instantly share code, notes, and snippets.

@sveitser
Created October 21, 2018 15:12
Show Gist options
  • Save sveitser/4f7f7b2f4e00d14c551f98fd65f08aed to your computer and use it in GitHub Desktop.
Save sveitser/4f7f7b2f4e00d14c551f98fd65f08aed to your computer and use it in GitHub Desktop.
Bonnie, ext4, lvm, luks benchmark.
#!/bin/bash
#
# DANGEROUS!
#
# Benchmark drive with bonnie using ext4: vanilla, LUKS, LVM, LUKS + LVM
#
set -euxo pipefail
DISK="/dev/sda"
RUNS=3
RESULTS_DIR="results"
########################################################
# No need to edit anything below for normal usage. #
########################################################
PART="${DISK}1"
CRYPT_VOLUME_NAME="crypt-benchmark"
CRYPT_VOLUME="/dev/mapper/$CRYPT_VOLUME_NAME"
USER="lulu"
MOUNTPOINT="/mnt"
BONNIEDIR="$MOUNTPOINT/bonnie"
PASSWORD="MUCHSECURE"
VOLUME_NAME="benchmark"
VOLUME_GROUP="vg"
VG_PATH="/dev/$VOLUME_GROUP/$VOLUME_NAME"
run-bonnie() {
local rundir="$RESULTS_DIR/$1"
mkdir -p "$rundir"
for iter in $(seq 0 $RUNS); do
local fname="$rundir/${iter}.txt"
bonnie++ -d "$BONNIEDIR" -n 1 -u $USER | tee "$fname"
chown $USER "$fname"
done
}
test-unencrypted() {
echo "Testing ext4 unencrypted."
format "$PART"
mount-volume "$PART"
run-bonnie ext4
}
test-luks(){
echo "Testing LUKS."
setup-luks
format "$CRYPT_VOLUME"
mount-volume "$CRYPT_VOLUME"
run-bonnie luks
}
test-lvm(){
echo "Testing LVM."
setup-lvm "$PART"
format "$VG_PATH"
mount-volume "$VG_PATH"
run-bonnie lvm
}
test-luks-lvm(){
echo "Testing LUKS LVM."
setup-luks
setup-lvm "$CRYPT_VOLUME"
format "$VG_PATH"
mount-volume "$VG_PATH"
run-bonnie luks-lvm
}
setup-luks(){
echo "Setting up LUKS."
echo $PASSWORD | cryptsetup luksFormat "$PART"
echo "Opening crypt volume."
echo $PASSWORD | cryptsetup luksOpen "$PART" "$CRYPT_VOLUME_NAME"
}
setup-lvm(){
echo "Setting up LVM."
pvcreate -y "$1"
vgcreate $VOLUME_GROUP "$1"
lvcreate -l '100%FREE' -n "$VOLUME_NAME" "$VOLUME_GROUP"
}
format(){
mkfs.ext4 "$1"
}
mount-volume(){
mount "$1" "$MOUNTPOINT"
mkdir -p "$BONNIEDIR"
chown $USER "$BONNIEDIR"
}
clean() {
echo "Unmounting file systems."
umount "$MOUNTPOINT" || true
echo "Removing logical volumes."
lvremove -y "$VOLUME_GROUP" "$VOLUME_NAME" || true
echo "Removing logical volume group."
lvremove -y "$VOLUME_GROUP" || true
echo "Removing physical volume group."
pvremove -y -f -f $CRYPT_VOLUME || true
pvremove -y -f -f $PART || true
sleep 1
echo "Removing device."
dmsetup remove $CRYPT_VOLUME || true
}
partition(){
echo "Creating partition table."
(echo o # new table
echo Y # yes
echo n # new part
echo # number 1
echo # start
echo # end
echo # linux
echo w # write
echo Y # yes
) | gdisk $DISK
}
partition
clean
test-unencrypted
clean
test-luks
clean
test-lvm
clean
test-luks-lvm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment