Created
October 24, 2018 03:13
-
-
Save sveitser/e84c47d46852aa88ba18f97dfb657538 to your computer and use it in GitHub Desktop.
Untested, probably doesn't work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# DANGEROUS! | |
# | |
# Benchmark drive with bonnie using ext4: vanilla, LUKS, LVM, LUKS + LVM | |
import os | |
import time | |
import sys | |
from sh import ( | |
chown, | |
cryptsetup, | |
dmsetup, | |
lvcreate, | |
lvremove, | |
mkdir, | |
mkfs, | |
mount, | |
pvcreate, | |
pvremove, | |
umount, | |
vgcreate, | |
Command, | |
) | |
DISK = "/dev/sde" | |
RUNS = 1 | |
RESULTS_DIR = "samsung-evo840" | |
######################################################## | |
# No need to edit anything below for normal usage. # | |
######################################################## | |
PART = f"{DISK}1" | |
CRYPT_VOLUME_NAME = "crypt-benchmark" | |
CRYPT_VOLUME = f"/dev/mapper/{CRYPT_VOLUME_NAME}" | |
USER = "lulu" | |
MOUNTPOINT = "/mnt" | |
BONNIEDIR = f"{MOUNTPOINT}/bonnie" | |
PASSWORD = "MUCHSECURE" | |
VOLUME_NAME = "benchmark" | |
VOLUME_GROUP = "vg" | |
VG_PATH = f"/dev/{VOLUME_GROUP}/{VOLUME_NAME}" | |
START = 1 | |
RUNS = 3 | |
bonnie = Command("bonnie++") | |
def run_bonnie(name): | |
rundir = os.path.join(RESULTS_DIR, name) | |
mkdir("-p", rundir) | |
for it in range(START, START + RUNS): | |
result = bonnie("-d", BONNIEDIR, "-n", "1", "-u", USER) | |
fname = os.path.join(rundir, "f{it}.txt") | |
with open(fname) as f: | |
print(result, file=f) | |
chown("-R", USER, rundir) | |
def test_unencrypted(): | |
print("Testing ext4 unencrypted.") | |
format_disk(PART) | |
mount_volume(PART) | |
run_bonnie("ext4") | |
def test_luks(): | |
print("Testing LUKS.") | |
setup_luks() | |
format_disk(CRYPT_VOLUME) | |
mount_volume(CRYPT_VOLUME) | |
run_bonnie("luks") | |
def test_lvm(): | |
print("Testing LVM.") | |
setup_lvm(PART) | |
format_disk(VG_PATH) | |
mount_volume(VG_PATH) | |
run_bonnie("lvm") | |
def test_luks_lvm(): | |
print("Testing LUKS LVM.") | |
setup_luks() | |
setup_lvm(CRYPT_VOLUME) | |
format_disk(VG_PATH) | |
mount_volume(VG_PATH) | |
run_bonnie("luks_lvm") | |
def setup_luks(): | |
print("Setting up LUKS.") | |
cryptsetup("luksFormat", PART, _in=PASSWORD) | |
# echo $PASSWORD | cryptsetup luksFormat PART | |
print("Opening crypt volume.") | |
# echo $PASSWORD | cryptsetup luksOpen PART" "$CRYPT_VOLUME_NAME | |
cryptsetup("luksOpen", PART, CRYPT_VOLUME_NAME, _in=PASSWORD) | |
def setup_lvm(volume_path): | |
print("Setting up LVM.") | |
pvcreate("-y", volume_path) | |
vgcreate(VOLUME_GROUP, volume_path) | |
lvcreate("-l", "100%FREE", "-n", VOLUME_NAME, VOLUME_GROUP) | |
def format_disk(path): | |
mkfs.ext4(path) | |
def mount_volume(volume_path): | |
mount(volume_path, MOUNTPOINT) | |
mkdir("-p", BONNIEDIR) | |
chown(USER, BONNIEDIR) | |
def clean(): | |
print("Unmounting file systems.") | |
umount(MOUNTPOINT) | |
print("Removing logical volumes.") | |
lvremove("-y", VOLUME_GROUP, VOLUME_NAME) | |
print("Removing logical volume group.") | |
lvremove("-y", VOLUME_GROUP) | |
print("Removing physical volume group.") | |
pvremove("-y", "-ff", CRYPT_VOLUME) | |
pvremove("-y", "-ff", PART) | |
time.sleep(1) | |
print("Removing device.") | |
dmsetup("remove", CRYPT_VOLUME) | |
def run(): | |
if os.getuid() != 0: | |
print("Needs root. :(", file=sys.stderr) | |
sys.exit(1) | |
clean() | |
test_unencrypted() | |
clean() | |
test_luks() | |
clean() | |
test_lvm() | |
clean() | |
test_luks_lvm() | |
if __name__ == "__main__": | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment