data/scripts/ramfsRoot.sh aktualisiert

This commit is contained in:
2025-03-31 15:49:26 +02:00
parent 5156f07940
commit 78bb57f2ae

44
data/scripts/ramfsRoot.sh Normal file
View File

@@ -0,0 +1,44 @@
#!/bin/bash
set -e
fail() {
echo -e "$1" >&2
exit 1
}
# Prüfen, ob genügend RAM frei ist (in KB)
RAM_FREE=$(grep MemAvailable /proc/meminfo | awk '{print $2}')
if [ "$RAM_FREE" -lt 3000000 ]; then # 3GB als Mindestgrenze
fail "Nicht genügend freier RAM!"
fi
# RAMFS als neues Root mounten
echo "Erstelle RAM-basiertes Root-Dateisystem..."
mount -t ramfs -o mode=0755 ramfs /mnt || fail "Fehler beim Mounten von ramfs"
# Sicherstellen, dass notwendige Verzeichnisse existieren
mkdir -p /mnt/{proc,sys,dev,run,tmp}
# Komplettes Root-Dateisystem nach RAMFS kopieren
echo "Kopiere System nach RAM..."
cp -ax / /mnt || fail "Fehler beim Kopieren nach RAMFS"
# Mountpunkte ins neue Root verschieben
mount --move /proc /mnt/proc
mount --move /sys /mnt/sys
mount --move /dev /mnt/dev
mount --move /run /mnt/run
# Wechsle zum neuen Root-FS
cd /mnt
pivot_root . oldroot || fail "pivot_root fehlgeschlagen"
# Altes Root unmounten
umount -l /oldroot/proc || true
umount -l /oldroot/sys || true
umount -l /oldroot/dev || true
umount -l /oldroot/run || true
umount -l /oldroot || true
# Startet das System normal weiter
exec /sbin/init