From bb67de3f4acd087480f697b2d41d82e11d795981 Mon Sep 17 00:00:00 2001 From: Andre Ramnitz Date: Sat, 3 Jan 2026 03:29:01 +0100 Subject: [PATCH] scripts: ramtest.sh uses luks to verify ram integrity --- dot-local/bin/ramtest.sh | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 dot-local/bin/ramtest.sh diff --git a/dot-local/bin/ramtest.sh b/dot-local/bin/ramtest.sh new file mode 100755 index 00000000..1f76f4f9 --- /dev/null +++ b/dot-local/bin/ramtest.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +# Dieses script soll ramfehler mittels luks finden +# Benutzung: ./ramtest.sh +# found at https://www.gonicus.de + +if + which dd > /dev/null && which cryptsetup > /dev/null && which pwgen > /dev/null +then + echo "dd, luks und pwgen vorhanden. Fahre fort." +else + echo "dd, luks und/oder pwgen nicht installiert." + exit 1 +fi + +if [[ -n $1 ]] && [[ $1 =~ ^[0-9]+$ ]] +then + COUNT=$1 + echo "Anzahl der Durchläufe ist $COUNT" +else + echo "keine Anzahl übergeben oder keine Zahl" + exit 1 +fi + +TMPDIR=$(mktemp -d) +echo "Lege temporäres Verzeichnis $TMPDIR an" + +PW=$(pwgen 64 -1) +PWFILE="$TMPDIR/pw" + +echo $PW > $PWFILE + +echo "Lege temporäres Image der Größe 1000MB an" +dd if=/dev/urandom of=$TMPDIR/ramtest.img bs=1M count=1000 2>/dev/null + +echo "formatiere image mit luks" +cryptsetup luksFormat $TMPDIR/ramtest.img < $PWFILE +> $TMPDIR/log +for i in $(seq 1 $COUNT) + do + echo "Durchlauf Nummer $i von $COUNT" + cryptsetup luksOpen --test-passphrase $TMPDIR/ramtest.img < $PWFILE 2>/dev/null + RES=$? + if [[ $RES -eq 0 ]] + then + echo "0" >> $TMPDIR/log + else + echo "1" >> $TMPDIR/log + fi + unset RES + done + +echo -e "\n\ +Resultat: \n\ +Anzahl Durchläufe: $COUNT \n\ +Erfolgreiche Durchläufe: $(grep ^0$ $TMPDIR/log | wc -l) \n\ +Nicht erfolgreiche Durchläufe: $(grep ^1$ $TMPDIR/log | wc -l) \n" + +echo "Entferne temporäres Verzeichnis $TMPDIR" +rm -Rf $TMPDIR +exit 0 -- 2.52.0